mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
post9pservice: accept mtpt (via fuse)
This commit is contained in:
parent
ce1e3a796c
commit
118dfa98b8
4 changed files with 78 additions and 38 deletions
|
@ -832,7 +832,8 @@ extern char* get9root(void);
|
|||
extern char* unsharp(char*);
|
||||
extern int sendfd(int, int);
|
||||
extern int recvfd(int);
|
||||
extern int post9pservice(int, char*);
|
||||
extern int post9pservice(int, char*, char*);
|
||||
extern int chattyfuse;
|
||||
|
||||
/* external names that we don't want to step on */
|
||||
#ifndef NOPLAN9DEFINES
|
||||
|
|
|
@ -75,18 +75,22 @@ void
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
Ram *r;
|
||||
char *defmnt;
|
||||
char *defmnt, *defsrv;
|
||||
int p[2];
|
||||
char buf[TICKREQLEN];
|
||||
|
||||
fmtinstall('F', fcallfmt);
|
||||
initfcalls();
|
||||
|
||||
defmnt = "tapefs";
|
||||
defmnt = nil;
|
||||
defsrv = nil;
|
||||
ARGBEGIN{
|
||||
case 'm':
|
||||
defmnt = ARGF();
|
||||
break;
|
||||
case 's':
|
||||
defsrv = ARGF();
|
||||
break;
|
||||
case 'p': /* password file */
|
||||
uidmap = getpass(ARGF());
|
||||
break;
|
||||
|
@ -142,8 +146,8 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
default:
|
||||
close(p[0]); /* don't deadlock if child fails */
|
||||
if(post9pservice(p[1], defmnt, nil) < 0) {
|
||||
sprint(buf, "post on `%s' failed", defmnt);
|
||||
if(post9pservice(p[1], defsrv, defmnt) < 0){
|
||||
sprint(buf, "post9pservice: %r");
|
||||
error(buf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +1,79 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
|
||||
int chattyfuse;
|
||||
|
||||
int
|
||||
post9pservice(int fd, char *name)
|
||||
post9pservice(int fd, char *name, char *mtpt)
|
||||
{
|
||||
int i;
|
||||
char *ns, *s;
|
||||
int i, pid;
|
||||
char *ns, *addr;
|
||||
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(name == nil && mtpt == nil){
|
||||
close(fd);
|
||||
werrstr("nothing to do");
|
||||
return -1;
|
||||
}
|
||||
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(name){
|
||||
if(strchr(name, '!')) /* assume is already network address */
|
||||
addr = strdup(name);
|
||||
else{
|
||||
if((ns = getns()) == nil)
|
||||
return -1;
|
||||
addr = smprint("unix!%s/%s", ns, name);
|
||||
free(ns);
|
||||
}
|
||||
if(addr == nil)
|
||||
return -1;
|
||||
switch(pid = 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", addr, (char*)0);
|
||||
fprint(2, "exec 9pserve: %r\n");
|
||||
_exits("exec");
|
||||
}
|
||||
close(fd);
|
||||
w = waitfor(pid);
|
||||
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;
|
||||
if(mtpt){
|
||||
/* reopen */
|
||||
if((fd = dial(addr, nil, nil, nil)) < 0){
|
||||
werrstr("cannot reopen for mount: %r");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
free(addr);
|
||||
}
|
||||
if(mtpt){
|
||||
switch(pid = rfork(RFFDG|RFPROC|RFNOWAIT)){
|
||||
case -1:
|
||||
return -1;
|
||||
case 0:
|
||||
dup(fd, 0);
|
||||
for(i=3; i<20; i++)
|
||||
close(i);
|
||||
if(chattyfuse)
|
||||
execlp("9pfuse", "9pfuse", "-D", "-", mtpt, (char*)0);
|
||||
else
|
||||
execlp("9pfuse", "9pfuse", "-", mtpt, (char*)0);
|
||||
fprint(2, "exec 9pfuse: %r\n");
|
||||
_exits("exec");
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,8 @@ void
|
|||
threadpostmountsrv(Srv *s, char *name, char *mtpt, int flag)
|
||||
{
|
||||
int fd[2];
|
||||
|
||||
if(mtpt)
|
||||
sysfatal("mount not supported");
|
||||
int mtfd;
|
||||
char *addr;
|
||||
|
||||
if(!s->nopipe){
|
||||
if(pipe(fd) < 0)
|
||||
|
@ -24,7 +23,10 @@ threadpostmountsrv(Srv *s, char *name, char *mtpt, int flag)
|
|||
s->infd = s->outfd = fd[1];
|
||||
s->srvfd = fd[0];
|
||||
}
|
||||
if(name && post9pservice(s->srvfd, name) < 0)
|
||||
sysfatal("post9pservice %s: %r", name);
|
||||
if(name || mtpt){
|
||||
if(post9pservice(s->srvfd, name, mtpt) < 0)
|
||||
sysfatal("post9pservice %s: %r", name);
|
||||
}else if(!s->nopipe)
|
||||
sysfatal("no one to serve");
|
||||
proccreate(launchsrv, s, 32*1024);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue