]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/cpu.c
fix ref822 again: remove uniqarray(), fix case with many entries in 'n'.
[plan9front.git] / sys / src / cmd / cpu.c
index 44792fc9025bca6ae28942f66f3ea9ed50624942..98532502259875caf1fea3fe708ce6edbd47a4d7 100644 (file)
@@ -14,7 +14,7 @@
 #define        Maxfdata 8192
 #define MaxStr 128
 
-void   remoteside(int);
+void   remoteside(void);
 void   fatal(char*, ...);
 void   lclnoteproc(int);
 void   rmtnoteproc(void);
@@ -69,8 +69,6 @@ struct AuthMethod {
 };
 AuthMethod *am = authmethod;   /* default is p9 */
 
-char *p9authproto = "p9any";
-
 int setam(char*);
 
 char   *aan = "/bin/aan";
@@ -118,31 +116,6 @@ procgetname(void)
        return strdup(lp+1);
 }
 
-/*
- * based on libthread's threadsetname, but drags in less library code.
- * actually just sets the arguments displayed.
- */
-void
-procsetname(char *fmt, ...)
-{
-       int fd;
-       char *cmdname;
-       char buf[128];
-       va_list arg;
-
-       va_start(arg, fmt);
-       cmdname = vsmprint(fmt, arg);
-       va_end(arg);
-       if (cmdname == nil)
-               return;
-       snprint(buf, sizeof buf, "#p/%d/args", getpid());
-       if((fd = open(buf, OWRITE)) >= 0){
-               write(fd, cmdname, strlen(cmdname)+1);
-               close(fd);
-       }
-       free(cmdname);
-}
-
 void
 main(int argc, char **argv)
 {
@@ -154,7 +127,7 @@ main(int argc, char **argv)
        origargs = procgetname();
        /* see if we should use a larger message size */
        fd = open("/dev/draw", OREAD);
-       if(fd > 0){
+       if(fd >= 0){
                ms = iounit(fd);
                if(msgsize < ms+IOHDRSZ)
                        msgsize = ms+IOHDRSZ;
@@ -188,12 +161,8 @@ main(int argc, char **argv)
        case 'A':
                anstring = EARGF(usage());
                break;
-       case 'O':
-               p9authproto = "p9sk2";
-               remoteside(1);                          /* From listen */
-               break;
        case 'R':                               /* From listen */
-               remoteside(0);
+               remoteside();
                break;
        case 'h':
                system = EARGF(usage());
@@ -204,7 +173,7 @@ main(int argc, char **argv)
                *s++ = '!';
                *s = 0;
                while(p = ARGF())
-                       s = seprint(s, cmd+sizeof(cmd), " %s", p);
+                       s = seprint(s, cmd+sizeof(cmd), " %q", p);
                break;
        case 'k':
                keyspec = smprint("%s %s", keyspec, EARGF(usage()));
@@ -297,47 +266,9 @@ fatal(char *fmt, ...)
 
 char *negstr = "negotiating authentication method";
 
-int
-old9p(int fd)
-{
-       int p[2];
-
-       if(pipe(p) < 0)
-               fatal("pipe: %r");
-
-       switch(rfork(RFPROC|RFMEM|RFFDG|RFNAMEG|RFREND)) {
-       case -1:
-               fatal("rfork srvold9p: %r");
-       case 0:
-               if(fd != 1){
-                       dup(fd, 1);
-                       close(fd);
-               }
-               if(p[0] != 0){
-                       dup(p[0], 0);
-                       close(p[0]);
-               }
-               close(p[1]);
-               if(0){
-                       fd = open("/sys/log/cpu", OWRITE);
-                       if(fd != 2){
-                               dup(fd, 2);
-                               close(fd);
-                       }
-                       execl("/bin/srvold9p", "srvold9p", "-ds", nil);
-               } else
-                       execl("/bin/srvold9p", "srvold9p", "-s", nil);
-               fatal("exec srvold9p: %r");
-       default:
-               close(fd);
-               close(p[0]);
-       }
-       return p[1];    
-}
-
 /* Invoked with stdin and stdout connected to the network connection */
 void
-remoteside(int old)
+remoteside(void)
 {
        char user[MaxStr], buf[MaxStr], xdir[MaxStr], cmd[MaxStr];
        int i, n, fd, badchdir, gotcmd;
@@ -351,7 +282,7 @@ remoteside(int old)
        if(n < 0)
                fatal("authenticating: %r");
        filterp = nil;
-       if(!old && strcmp(cmd, "aan") == 0){
+       if(strcmp(cmd, "aan") == 0){
                filterp = aan;
                writestr(fd, "", nil, 1);
                n = readstr(fd, cmd, sizeof(cmd));
@@ -396,9 +327,6 @@ remoteside(int old)
        if(n != 2 || buf[0] != 'O' || buf[1] != 'K')
                exits("remote tree");
 
-       if(old)
-               fd = old9p(fd);
-
        /* make sure buffers are big by doing fversion explicitly; pick a huge number; other side will trim */
        strcpy(buf, VERSION9P);
        if(fversion(fd, 64*1024, buf, sizeof buf) < 0)
@@ -529,6 +457,19 @@ readln(char *buf, int n)
        return p-buf;
 }
 
+/*
+ *  chown network connection
+ */
+static void
+setnetuser(int fd, char *user)
+{
+       Dir nd;
+       nulldir(&nd);
+       nd.mode = 0660;
+       nd.uid = user;
+       dirfwstat(fd, &nd);
+}
+
 /*
  *  user level challenge/response
  */
@@ -589,6 +530,7 @@ netkeysrvauth(int fd, char *user)
        writestr(fd, "", "challenge", 1);
        if(auth_chuid(ai, 0) < 0)
                fatal("newns: %r");
+       setnetuser(fd, ai->cuid);
        auth_freeAI(ai);
        return fd;
 }
@@ -666,7 +608,7 @@ p9auth(int fd)
 {
        AuthInfo *ai;
 
-       ai = auth_proxy(fd, auth_getkey, "proto=%q role=client %s", p9authproto, keyspec);
+       ai = auth_proxy(fd, auth_getkey, "proto=p9any role=client %s", keyspec);
        if(ai == nil)
                return -1;
        fd = sslsetup(fd, ai->secret, ai->nsecret, 1);
@@ -695,11 +637,12 @@ srvp9auth(int fd, char *user)
 {
        AuthInfo *ai;
 
-       ai = auth_proxy(fd, nil, "proto=%q role=server %s", p9authproto, keyspec);
+       ai = auth_proxy(fd, nil, "proto=p9any role=server %s", keyspec);
        if(ai == nil)
                return -1;
        if(auth_chuid(ai, nil) < 0)
                fatal("newns: %r");
+       setnetuser(fd, ai->cuid);
        snprint(user, MaxStr, "%s", ai->cuid);
        fd = sslsetup(fd, ai->secret, ai->nsecret, 0);
        auth_freeAI(ai);
@@ -830,10 +773,8 @@ rmtnoteproc(void)
                _exits(0);
        case 0:
                fd = open(rmtnotefile, OREAD);
-               if(fd < 0){
-                       syslog(0, "cpu", "cpu -R: can't open %s", rmtnotefile);
+               if(fd < 0)
                        _exits(0);
-               }
        
                for(;;){
                        n = read(fd, buf, sizeof(buf)-1);
@@ -1075,14 +1016,7 @@ notefs(int fd)
        ncpunote = 0;
        for(;;){
                n = read9pmsg(fd, buf, sizeof(buf));
-               if(n < 0){
-                       if(dbg)
-                               fprint(2, "read9pmsg(%d) returns %d: %r\n", fd, n);
-                       break;
-               }
-               if(n == 0)
-                       continue;
-               if(convM2S(buf, n, &f) <= BIT16SZ)
+               if(n <= 0 || convM2S(buf, n, &f) != n)
                        break;
                if(dbg)
                        fprint(2, "notefs: ->%F\n", &f);