Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/cmd/vnc/exporter.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include "compat.h"
4
 
5
typedef struct Exporter	Exporter;
6
struct Exporter
7
{
8
	int	fd;
9
	Chan	**roots;
10
	int	nroots;
11
};
12
 
13
int
14
mounter(char *mntpt, int how, int fd, int n)
15
{
16
	char buf[32];
17
	int i, ok, mfd;
18
 
19
	ok = 1;
20
	for(i = 0; i < n; i++){
21
		snprint(buf, sizeof buf, "%d", i);
22
		mfd = dup(fd, -1);
23
		if(mount(mfd, -1, mntpt, how, buf) == -1){
24
			close(mfd);
25
			fprint(2, "can't mount on %s: %r\n", mntpt);
26
			ok = 0;
27
			break;
28
		}
29
		close(mfd);
30
		if(how == MREPL)
31
			how = MAFTER;
32
	}
33
 
34
	close(fd);
35
 
36
	return ok;
37
}
38
 
39
static void
40
extramp(void *v)
41
{
42
	Exporter *ex;
43
 
44
	rfork(RFNAMEG);
45
	ex = v;
46
	sysexport(ex->fd, ex->roots, ex->nroots);
47
	shutdown();
48
	exits(nil);
49
}
50
 
51
int
52
exporter(Dev **dt, int *fd, int *sfd)
53
{
54
	Chan **roots;
55
	Exporter ex;
56
	int p[2], i, n, ed;
57
 
58
	for(n = 0; dt[n] != nil; n++)
59
		;
60
	if(!n){
61
		werrstr("no devices specified");
62
		return 0;
63
	}
64
 
65
	ed = errdepth(-1);
66
	if(waserror()){
67
		werrstr(up->error);
68
		return 0;
69
	}
70
 
71
	roots = smalloc(n * sizeof *roots);
72
	for(i = 0; i < n; i++){
73
		(*dt[i]->reset)();
74
		(*dt[i]->init)();
75
		roots[i] = (*dt[i]->attach)("");
76
	}
77
	poperror();
78
	errdepth(ed);
79
 
80
	if(pipe(p) < 0){
81
		werrstr("can't make pipe: %r");
82
		return 0;
83
	}
84
 
85
	*sfd = p[0];
86
	*fd = p[1];
87
 
88
	ex.fd = *sfd;
89
	ex.roots = roots;
90
	ex.nroots = n;
91
	kproc("exporter", extramp, &ex);
92
 
93
	return n;
94
}