ref: b3e875d7db45fca0cde9f4efa12872f61afc54d7
dir: /tests/testpostsrv.c/
#include <u.h> #include <libc.h> #include <fcall.h> #include <auth.h> #include <authsrv.h> #include <thread.h> #include <9p.h> void mysrvforker(void (*fn)(void*), void *arg, int flag) { switch((rfork(RFPROC|RFMEM|RFNOWAIT|flag))){ case -1: sysfatal("rfork: %r"); default: sleep(1000); print("mysrvforker: Parent pid is %d\n", getpid()); return; case 0: print("mysrvforker Child pid is %d\n", getpid()); return; fn(arg); } } Srv mysrv = { .auth = auth9p, .forker = mysrvforker, /* .attach = fsattach, .walk1 = fswalk1, .clone = fsclone, .open = fsopen, .create = fscreate, .read = fsread, .write = fswrite, .stat = fsstat, .wstat = fswstat, .remove = fsremove, .destroyfid = fsdestroyfid, */ }; char service[] = "test.postsrv"; void main(int, char**) { int sfd; print("parent pid %ud\n", getpid()); sfd = postsrv(&mysrv, service); if(sfd < 0) sysfatal("postsrv: %r"); close(sfd); print("parent exiting\n"); exits(nil); }