code: mafs

ref: 80e6c118c65b013bde24f8b9c95881c0e3a73d3e
dir: /tests/testpostsrv.c/

View raw version
#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);
}