File: post9p.c

package info (click to toggle)
9base 2-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,116 kB
  • ctags: 3,521
  • sloc: ansic: 34,477; yacc: 1,623; makefile: 365; sh: 37; asm: 8
file content (46 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <u.h>
#include <libc.h>

int
post9pservice(int fd, char *name)
{
	int i;
	char *ns, *s;
	Waitmsg *w;

	if(strchr(name, '!'))	/* assume is already network address */
		s = strdup(name);
	else{
		if((ns = getns()) == nil)
			return -1;
		s = smprint("unix!%s/%s", ns, name);
		free(ns);
	}
	if(s == nil)
		return -1;
	switch(fork()){
	case -1:
		return -1;
	case 0:
		dup(fd, 0);
		dup(fd, 1);
		for(i=3; i<20; i++)
			close(i);
		execlp("9pserve", "9pserve", "-u", s, (char*)0);
		fprint(2, "exec 9pserve: %r\n");
		_exits("exec");
	default:
		w = wait();
		if(w == nil)
			return -1;
		close(fd);
		free(s);
		if(w->msg && w->msg[0]){
			free(w);
			werrstr("9pserve failed");
			return -1;
		}
		free(w);
		return 0;
	}
}