#include #include "test.h" #include "tests.h" typedef struct priv PRIV; struct priv { int lfd; int cfd; } ; static void run_l_c_cl_cc_run_l(void *pv) { PRIV *p; pid_t mypid; int fd; char c; p = pv; mypid = getpid(); printf("l-c-cl-cc: listener is %d\n",(int)mypid); sleep(1); printf("l-c-cl-cc: listener doing PIDCONN_LISTEN\n"); sleep(1); SET_PIDCONN(fd,PIDCONN_LISTEN,0,0); sleep(1); printf("l-c-cl-cc: listener sending PID to connecter\n"); sleep(1); mustwrite(p->lfd,&mypid,sizeof(pid_t)); sleep(1); printf("l-c-cl-cc: listener reading interlock from connecter\n"); sleep(1); mustread(p->lfd,&c,1); sleep(1); printf("l-c-cl-cc: listener closing\n"); sleep(1); close(fd); sleep(1); printf("l-c-cl-cc: listener writing interlock to connecter\n"); sleep(1); mustwrite(p->lfd,&mypid,sizeof(pid_t)); sleep(1); printf("l-c-cl-cc: listener reading interlock from connecter\n"); sleep(1); mustread(p->lfd,&c,1); sleep(1); printf("l-c-cl-cc: listener done\n"); } static void run_l_c_cl_cc_run_c(void *pv) { PRIV *p; pid_t lpid; int fd; char c; p = pv; printf("l-c-cl-cc: connecter is %d\n",(int)getpid()); sleep(1); printf("l-c-cl-cc: connecter reading PID from listener\n"); sleep(1); mustread(p->cfd,&lpid,sizeof(pid_t)); sleep(1); printf("l-c-cl-cc: connecter doing PIDCONN_CONNECT to %d\n",(int)lpid); sleep(1); SET_PIDCONN(fd,PIDCONN_CONNECT,0,lpid); sleep(1); printf("l-c-cl-cc: connecter writing interlock to listener\n"); sleep(1); mustwrite(p->cfd,"",1); sleep(1); printf("l-c-cl-cc: connecter reading interlock from listener\n"); sleep(1); mustread(p->cfd,&c,1); sleep(1); printf("l-c-cl-cc: connecter closing\n"); sleep(1); close(fd); sleep(1); printf("l-c-cl-cc: connecter writing interlock to listener\n"); sleep(1); mustwrite(p->cfd,"",1); sleep(1); printf("l-c-cl-cc: connecter done\n"); } static void run_l_c_cl_cc(void) { PRIV p; KID *kl; KID *kc; local_socketpair(&p.lfd,&p.cfd); kl = fork_kid(&run_l_c_cl_cc_run_l,&p); kc = fork_kid(&run_l_c_cl_cc_run_c,&p); close(p.lfd); close(p.cfd); reap_kid(kl); reap_kid(kc); printf("l-c-cl-cc: done\n"); } const TEST test_l_c_cl_cc = { &run_l_c_cl_cc };