9pfuse: accept - for stdin, try to hang up cleanly

This commit is contained in:
Russ Cox 2008-04-17 16:03:49 -04:00
parent 1412580357
commit e63025d094
2 changed files with 20 additions and 3 deletions

View file

@ -3,6 +3,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/select.h>
#include <libc.h> #include <libc.h>
#include <fcall.h> #include <fcall.h>
#include <thread.h> #include <thread.h>

View file

@ -39,7 +39,6 @@
# endif # endif
#endif #endif
int debug; int debug;
char *argv0; char *argv0;
char *aname = ""; char *aname = "";
@ -77,6 +76,7 @@ usage(void)
} }
void fusereader(void*); void fusereader(void*);
void watchfd(void*);
void void
threadmain(int argc, char **argv) threadmain(int argc, char **argv)
@ -139,8 +139,12 @@ init9p(char *addr, char *spec)
{ {
int fd; int fd;
if((fd = dial(netmkaddr(addr, "tcp", "564"), nil, nil, nil)) < 0) if(strcmp(addr, "-") == 0)
sysfatal("dial %s: %r", addr); fd = 0;
else
if((fd = dial(netmkaddr(addr, "tcp", "564"), nil, nil, nil)) < 0)
sysfatal("dial %s: %r", addr);
proccreate(watchfd, (void*)(uintptr)fd, STACK);
if((fsys = fsmount(fd, spec)) == nil) if((fsys = fsmount(fd, spec)) == nil)
sysfatal("fsmount: %r"); sysfatal("fsmount: %r");
fsysroot = fsroot(fsys); fsysroot = fsroot(fsys);
@ -1208,4 +1212,16 @@ estrdup(char *p)
return pp; return pp;
} }
void
watchfd(void *v)
{
int fd = (int)(uintptr)v;
/* wait for exception (file closed) */
fd_set set;
FD_ZERO(&set);
FD_SET(fd, &set);
if(select(fd+1, NULL, NULL, &set, NULL) >= 0)
threadexitsall(nil);
return;
}