]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/cwfs/main.c
cwfs: fix race between cmd_exec("users") and serve processes, cleanup portfns.h
[plan9front.git] / sys / src / cmd / cwfs / main.c
index 9d12066d0ac97ee49336811bd5798b5496b8289b..3d37a5467006da8685f3e570ce41c5773d0f5135 100644 (file)
@@ -3,12 +3,11 @@
 #include "io.h"
 #include "9p1.h"
 
-extern int oldcachefmt;
-
 Map *devmap;
 
-int sfd, rfd;
 Biobuf bin;
+int chatty = 0;
+int sfd = -1;
 
 void
 machinit(void)
@@ -59,7 +58,7 @@ panic(char *fmt, ...)
        n = vseprint(buf, buf + sizeof buf, fmt, arg) - buf;
        va_end(arg);
        buf[n] = '\0';
-       print("panic: %s\n", buf);
+       fprint(2, "panic: %s\n", buf);
        exit();
 }
 
@@ -92,12 +91,12 @@ mapinit(char *mapfile)
        if (bp == nil)
                sysfatal("can't read %s", mapfile);
        devmap = nil;
-       while ((ln = Brdline(bp, '\n')) != nil) {
+       while((ln = Brdline(bp, '\n')) != nil) {
                ln[Blinelen(bp)-1] = '\0';
-               if (*ln == '\0' || *ln == '#')
+               if(*ln == '\0' || *ln == '#')
                        continue;
                nf = tokenize(ln, fields, nelem(fields));
-               if (nf != 2)
+               if(nf != 2)
                        continue;
                if(testconfig(fields[0]) != 0) {
                        print("bad `from' device %s in %s\n",
@@ -109,7 +108,7 @@ mapinit(char *mapfile)
                map->to =   strdup(fields[1]);
                map->fdev = iconfig(fields[0]);
                map->tdev = nil;
-               if (access(map->to, AEXIST) < 0) {
+               if(access(map->to, AEXIST) < 0) {
                        /*
                         * map->to isn't an existing file, so it had better be
                         * a config string for a device.
@@ -129,8 +128,6 @@ confinit(void)
 {
        conf.nmach = 1;
 
-       conf.mem = meminit();
-
        conf.nuid = 1000;
        conf.nserve = 15;               /* tunable */
        conf.nfile = 30000;
@@ -140,7 +137,6 @@ confinit(void)
        localconfinit();
 
        conf.nwpath = conf.nfile*8;
-       conf.nauth =  conf.nfile/10;
        conf.gidspace = conf.nuid*3;
 
        cons.flags = 0;
@@ -177,25 +173,25 @@ postservice(void)
        if(service[0] == 0)
                panic("no service name");
 
-       if(sfd < 0){
-               if(pipe(p) < 0)
-                       panic("can't make a pipe");
-               sfd = p[0];
-               rfd = p[1];
+       /* serve 9p for -s */
+       if(sfd >= 0){
+               srvchan(sfd, "stdio");
+               sfd = -1;
        }
 
        /* post 9p service */
-       snprint(buf, sizeof(buf), "#s/%s", service);
-       srvfd(buf, 0666, sfd);
-       close(sfd);
-       srvchan(rfd, buf);
-
        if(pipe(p) < 0)
                panic("can't make a pipe");
+       snprint(buf, sizeof(buf), "#s/%s", service);
+       srvfd(buf, 0666, p[0]);
+       close(p[0]);
+       srvchan(p[1], buf);
 
        /* post cmd service */
+       if(pipe(p) < 0)
+               panic("can't make a pipe");
        snprint(buf, sizeof(buf), "#s/%s.cmd", service);
-       srvfd(buf, 0222, p[0]);
+       srvfd(buf, 0220, p[0]);
        close(p[0]);
 
        /* use it as stdin */
@@ -292,9 +288,8 @@ main(int argc, char **argv)
        rfork(RFNOTEG);
        formatinit();
        machinit();
-       conf.confdev = "/dev/sdC0/cwfs";
-
-       rfd = sfd = -1;
+       conf.confdev = "/dev/sdC0/fscache";
+       conf.newcache = 0;
 
        ARGBEGIN{
        case 'a':                       /* announce on this net */
@@ -310,8 +305,8 @@ main(int argc, char **argv)
                strcpy(service, EARGF(usage()));
                break;
        case 's':
-               sfd = dup(0, -1);
-               rfd = dup(1, -1);
+               dup(0, -1);
+               sfd = dup(1, -1);
                close(0);
                if(open("/dev/cons", OREAD) < 0)
                        open("#c/cons", OREAD);
@@ -320,7 +315,7 @@ main(int argc, char **argv)
                        open("#c/cons", OWRITE);
                break;
        case 'C':                       /* use new, faster cache layout */
-               oldcachefmt = 0;
+               conf.newcache = 1;
                break;
        case 'c':
                conf.configfirst++;
@@ -331,6 +326,9 @@ main(int argc, char **argv)
        case 'm':                       /* name device-map file */
                conf.devmap = EARGF(usage());
                break;
+       case 'd':
+               chatty++;
+               break;
        default:
                usage();
                break;
@@ -342,9 +340,11 @@ main(int argc, char **argv)
        Binit(&bin, 0, OREAD);
        confinit();
 
-       print("\nPlan 9 %d-bit cached-worm file server with %d-deep indir blks\n",
-               sizeof(Off)*8 - 1, NIBLOCK);
-       printsizes();
+       if(chatty){
+               print("\nPlan 9 %d-bit cached-worm file server with %d-deep indir blks\n",
+                       sizeof(Off)*8 - 1, NIBLOCK);
+               printsizes();
+       }
 
        qlock(&reflock);
        qunlock(&reflock);
@@ -364,19 +364,20 @@ main(int argc, char **argv)
        wpaths = malloc(conf.nwpath * sizeof(*wpaths));
        uid = malloc(conf.nuid * sizeof(*uid));
        gidspace = malloc(conf.gidspace * sizeof(*gidspace));
-       authinit();
 
-       print("iobufinit\n");
        iobufinit();
 
        arginit();
        boottime = time(nil);
 
-       print("sysinit\n");
        sysinit();
-
        srvinit();
 
+       installcmds();
+       cmd_exec("cfs");
+       cmd_exec("users");
+       cmd_exec("version");
+
        /*
         * post filedescriptors to /srv
         */
@@ -412,6 +413,9 @@ main(int argc, char **argv)
         * processes to read the console
         */
        consserve();
+
+       /* success */
+       exits(nil);
 }
 
 /*
@@ -508,11 +512,9 @@ serve(void *)
                                        cp->protocol = fsprotocol[i];
                                        break;
                                }
-                       if(cp->protocol == nil){
+                       if(cp->protocol == nil && (chatty > 1)){
                                print("no protocol for message\n");
-                               for(i = 0; i < 12; i++)
-                                       print(" %2.2uX", mb->data[i]);
-                               print("\n");
+                               hexdump(mb->data, 12);
                        }
                } else
                        /* process the request, generate an answer and reply */
@@ -550,7 +552,7 @@ nextdump(Timet t)
 {
        Timet nddate = nextime(t+MINUTE(100), DUMPTIME, WEEKMASK);
 
-       if(!conf.nodump)
+       if(!conf.nodump && chatty)
                print("next dump at %T\n", nddate);
        return nddate;
 }
@@ -577,10 +579,6 @@ wormcopy(void *)
                }
                dt = time(nil) - t;
                if(dt < 0 || dt > MINUTE(100)) {
-                       if(dt < 0)
-                               print("time went back\n");
-                       else
-                               print("time jumped ahead\n");
                        dorecalc = 1;
                        continue;
                }