summaryrefslogtreecommitdiff
path: root/sys/src/cmd/vnc/exporter.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/vnc/exporter.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/vnc/exporter.c')
-rwxr-xr-xsys/src/cmd/vnc/exporter.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/sys/src/cmd/vnc/exporter.c b/sys/src/cmd/vnc/exporter.c
new file mode 100755
index 000000000..bf5198bc3
--- /dev/null
+++ b/sys/src/cmd/vnc/exporter.c
@@ -0,0 +1,94 @@
+#include <u.h>
+#include <libc.h>
+#include "compat.h"
+
+typedef struct Exporter Exporter;
+struct Exporter
+{
+ int fd;
+ Chan **roots;
+ int nroots;
+};
+
+int
+mounter(char *mntpt, int how, int fd, int n)
+{
+ char buf[32];
+ int i, ok, mfd;
+
+ ok = 1;
+ for(i = 0; i < n; i++){
+ snprint(buf, sizeof buf, "%d", i);
+ mfd = dup(fd, -1);
+ if(mount(mfd, -1, mntpt, how, buf) == -1){
+ close(mfd);
+ fprint(2, "can't mount on %s: %r\n", mntpt);
+ ok = 0;
+ break;
+ }
+ close(mfd);
+ if(how == MREPL)
+ how = MAFTER;
+ }
+
+ close(fd);
+
+ return ok;
+}
+
+static void
+extramp(void *v)
+{
+ Exporter *ex;
+
+ rfork(RFNAMEG);
+ ex = v;
+ sysexport(ex->fd, ex->roots, ex->nroots);
+ shutdown();
+ exits(nil);
+}
+
+int
+exporter(Dev **dt, int *fd, int *sfd)
+{
+ Chan **roots;
+ Exporter ex;
+ int p[2], i, n, ed;
+
+ for(n = 0; dt[n] != nil; n++)
+ ;
+ if(!n){
+ werrstr("no devices specified");
+ return 0;
+ }
+
+ ed = errdepth(-1);
+ if(waserror()){
+ werrstr(up->error);
+ return 0;
+ }
+
+ roots = smalloc(n * sizeof *roots);
+ for(i = 0; i < n; i++){
+ (*dt[i]->reset)();
+ (*dt[i]->init)();
+ roots[i] = (*dt[i]->attach)("");
+ }
+ poperror();
+ errdepth(ed);
+
+ if(pipe(p) < 0){
+ werrstr("can't make pipe: %r");
+ return 0;
+ }
+
+ *sfd = p[0];
+ *fd = p[1];
+
+ ex.fd = *sfd;
+ ex.roots = roots;
+ ex.nroots = n;
+ kproc("exporter", extramp, &ex);
+
+ return n;
+}