Remove uses of errno_to_string()
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 13 Feb 2016 19:03:57 +0000 (14:03 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sun, 14 Feb 2016 14:03:22 +0000 (09:03 -0500)
Using errno_to_string() was a hack.

In addition to removing that, this commit cleans up a few nasty things.
In namec(), we just had a static string floating around for some reason.
Good times.

More importantly, in sysfile we were doing a brain-dead strcmp on
ENODATA.  Computers should do comparisons on errno.  Errstr is for
humans.  The danger there is that if someone did:

error(ENODATA, "Actually a useful message that was not NULL")

then the strcmp on errstr would fail, since it's not the "string that
meant ENODATA).

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/net/dial.c
kern/src/net/tcp.c
kern/src/ns/chan.c
kern/src/ns/parse.c
kern/src/ns/sysfile.c

index b7da019..667f071 100644 (file)
@@ -155,7 +155,7 @@ static int csdial(DS * ds)
         *  we get one that works.
         */
        *besterr = 0;
-       strlcpy(err, errno_to_string(ECONNRESET), ERRMAX);
+       strlcpy(err, "csdial() connection reset", ERRMAX);
        sysseek(fd, 0, 0);
        while ((n = sysread(fd, buf, Maxstring - 1)) > 0) {
                buf[n] = 0;
index b4882e2..823c05f 100644 (file)
@@ -2091,7 +2091,7 @@ reset:
                        }
                        if (seg.flags & RST) {
                                if (seg.flags & ACK)
-                                       localclose(s, errno_to_string(ECONNREFUSED));
+                                       localclose(s, "connection refused");
                                goto raise;
                        }
 
@@ -2196,7 +2196,7 @@ reset:
                                                 s->raddr, s->rport, s->laddr, s->lport, tcb->rcv.nxt,
                                                 seg.seq);
                        }
-                       localclose(s, errno_to_string(ECONNREFUSED));
+                       localclose(s, "connection refused");
                        goto raise;
                }
 
@@ -2725,7 +2725,7 @@ void tcpkeepalive(void *v)
        }
        if (tcb->state != Closed) {
                if (--(tcb->kacounter) <= 0) {
-                       localclose(s, errno_to_string(ETIMEDOUT));
+                       localclose(s, "connection timed out");
                } else {
                        tcpsendka(s);
                        tcpgo(s->p->priv, &tcb->katimer);
@@ -2814,7 +2814,7 @@ void tcptimeout(void *arg)
                                maxback = MAXBACKMS;
                        tcb->backedoff += tcb->timer.start * MSPTICK;
                        if (tcb->backedoff >= maxback) {
-                               localclose(s, errno_to_string(ETIMEDOUT));
+                               localclose(s, "connection timed out");
                                break;
                        }
                        netlog(s->p->f, Logtcprxmt, "timeout rexmit 0x%lx %llu/%llu\n",
index 40802cd..c488d1a 100644 (file)
@@ -688,7 +688,6 @@ struct chan *undomount(struct chan *c, struct cname *name)
  * Either walks all the way or not at all.  No partial results in *cp.
  * *nerror is the number of names to display in an error message.
  */
-static char Edoesnotexist[] = "does not exist";
 int walk(struct chan **cp, char **names, int nnames, bool can_mount, int *nerror)
 {
        int dev, dotdot, i, n, nhave, ntry, type;
@@ -796,11 +795,11 @@ int walk(struct chan **cp, char **names, int nnames, bool can_mount, int *nerror
                                        if (wq->nqid == 0 || (wq->qid[wq->nqid - 1].type & QTDIR)) {
                                                if (nerror)
                                                        *nerror = nhave + wq->nqid + 1;
-                                               set_errstr(Edoesnotexist);
+                                               set_error(ENOENT, "walk failed");
                                        } else {
                                                if (nerror)
                                                        *nerror = nhave + wq->nqid;
-                                               set_errstr(errno_to_string(ENOTDIR));
+                                               set_error(ENOTDIR, "walk failed");
                                        }
                                        kfree(wq);
                                        if (mh != NULL)
index 2fa9880..ac5af9e 100644 (file)
@@ -144,12 +144,8 @@ struct cmdtab *lookupcmd(struct cmdbuf *cb, struct cmdtab *ctab, int nctab)
                if (strcmp(ct->cmd, "*") != 0)  /* wildcard always matches */
                        if (strcmp(ct->cmd, cb->f[0]) != 0)
                                continue;
-               if (ct->narg != 0 && ct->narg != cb->nf) {
-                       // oh how I hate plan 9 error handling sometimes (DL: sometimes?!?).
-                       printk("%s: for %s have %d want %d\n", errno_to_string(EINVAL),
-                                  cb->f[0], cb->nf, ct->narg);
-                       cmderror(cb, "bring me another fucking rock");
-               }
+               if (ct->narg != 0 && ct->narg != cb->nf)
+                       cmderror(cb, "wrong number of args");
                return ct;
        }
 
index 6bad857..33c8094 100644 (file)
@@ -605,7 +605,7 @@ long unionread(struct chan *c, void *va, long n)
                        /* normally we want to discard the error, but for our ghetto kdirent
                         * hack, we need to repeat unionread if we saw a ENODATA */
                        if (waserror()) {
-                               if (!strcmp(current_errstr(), errno_to_string(ENODATA))) {
+                               if (get_errno() == ENODATA) {
                                        runlock(&m->lock);
                                        qunlock(&c->umqlock);
                                        nexterror();