Plan 9 from Bell Labs’s /usr/web/sources/9grid/Plan9.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "xcpusrv.h"

void runit(void *ac) {
	Client *c = ac;
	/* kudos to p9p, they do a bidi pipe */
	int pid;
//	char err[128];
	char *argv[128];
	int ntoken;
	int i;

	ntoken = tokenize(c->argv, argv, 127);
	argv[ntoken] = 0;
//	debug(12, "ntokedn %d\n", ntoken);
//	for(i = 0; i < ntoken; i++)
//		debug(12, argv[i]);

	pipe(c->stdinfd);
	pipe(c->stdoutfd);
	pipe(c->stderrfd);

	kidfds[0] = c->stdinfd[1];
	kidfds[1] = c->stdoutfd[1];
	kidfds[2] = c->stderrfd[1];

	pid = fork();
//	if (pid < 0)
//		debug(12, "FORK FAIL\n");
	if (pid > 0){
		(void)close(c->stdinfd[1]);
		(void)close(c->stdoutfd[1]);
		(void)close(c->stderrfd[1]);
		return;
	}

//	debug(12, "runit: spawn %s already\n", c->tmpname);

	dup(c->stdinfd[1], 0);
	dup(c->stdoutfd[1], 1);
	dup(c->stderrfd[1], 2);
	(void)close(c->stdinfd[1]);
	(void)close(c->stdoutfd[0]);
	(void)close(c->stderrfd[0]);

	exec(c->tmpname, argv);

	dup(2, open("/dev/cons", ORDWR));
//	debug(12, "FUCK! exec failed: %r\n");
}

void tmpexec(Client *c) {
		c->tmpname = strdup("/tmp/xcpuXXXXXXXXXXX");
		mktemp(c->tmpname);
		c->tmpfd = create(c->tmpname, ORDWR, 0700);
}

int mkdebugfd(void){
	char *console = "/dev/cons";
	int debugfd;
	debugfd = open(console, ORDWR);
	if (debugfd < 0)
		threadexits(smprint("NO %s\n", console));
	return debugfd;
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.