Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sup/source improve error handling and logging.



details:   https://anonhg.NetBSD.org/src/rev/49832d80e624
branches:  trunk
changeset: 758129:49832d80e624
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Oct 20 17:05:54 2010 +0000

description:
improve error handling and logging.

diffstat:

 usr.sbin/sup/source/scmio.c      |   4 ++--
 usr.sbin/sup/source/supcmeat.c   |  12 ++++++++----
 usr.sbin/sup/source/supcmisc.c   |   5 ++++-
 usr.sbin/sup/source/supfilesrv.c |  33 ++++++++++++++++++---------------
 4 files changed, 32 insertions(+), 22 deletions(-)

diffs (176 lines):

diff -r 465208115c80 -r 49832d80e624 usr.sbin/sup/source/scmio.c
--- a/usr.sbin/sup/source/scmio.c       Wed Oct 20 16:25:01 2010 +0000
+++ b/usr.sbin/sup/source/scmio.c       Wed Oct 20 17:05:54 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scmio.c,v 1.19 2009/10/18 15:23:54 christos Exp $      */
+/*     $NetBSD: scmio.c,v 1.20 2010/10/20 17:05:54 christos Exp $      */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -542,7 +542,7 @@
        (void) readmend();
        if (goawayreason == NULL)
                return (SCMEOF);
-       logerr("SCM GOAWAY %s", goawayreason);
+       logerr("SCM GOAWAY for %s %s", remotehost(), goawayreason);
        return (SCMEOF);
 }
 
diff -r 465208115c80 -r 49832d80e624 usr.sbin/sup/source/supcmeat.c
--- a/usr.sbin/sup/source/supcmeat.c    Wed Oct 20 16:25:01 2010 +0000
+++ b/usr.sbin/sup/source/supcmeat.c    Wed Oct 20 17:05:54 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: supcmeat.c,v 1.37 2009/10/17 20:46:03 christos Exp $   */
+/*     $NetBSD: supcmeat.c,v 1.38 2010/10/20 17:05:54 christos Exp $   */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -1407,20 +1407,24 @@
        }
        (void) sprintf(fname, FILEWHEN, collname, relsufix);
        if (establishdir(fname)) {
+               int oerrno = errno;
                Tfree(&lastT);
                if (protver < 6)
                        return;
-               done(FDONEUSRERROR, "Couldn't timestamp");
+               done(FDONEUSRERROR, "Couldn't create directory `%s' (%s)",
+                       fname, strerror(oerrno));
                (void) requestend();
                return;
        }
        if (!putwhen(fname, scantime)) {
+               int oerrno = errno;
                notify("SUP: Can't record current time in %s (%s)\n",
-                   fname, strerror(errno));
+                   fname, strerror(oerrno));
                Tfree(&lastT);
                if (protver < 6)
                        return;
-               done(FDONEUSRERROR, "Couldn't timestamp");
+               done(FDONEUSRERROR, "Couldn't timestamp `%s' (%s)",
+                       fname, strerror(oerrno));
                (void) requestend();
                return;
        }
diff -r 465208115c80 -r 49832d80e624 usr.sbin/sup/source/supcmisc.c
--- a/usr.sbin/sup/source/supcmisc.c    Wed Oct 20 16:25:01 2010 +0000
+++ b/usr.sbin/sup/source/supcmisc.c    Wed Oct 20 17:05:54 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: supcmisc.c,v 1.20 2009/10/16 12:41:37 christos Exp $   */
+/*     $NetBSD: supcmisc.c,v 1.21 2010/10/20 17:05:54 christos Exp $   */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -144,14 +144,17 @@
        if (strcmp(fpart, ".") == 0) {  /* dname is / or . */
                notify("SUP: Can't create directory %s for %s (Invalid name)\n",
                    dname, fname);
+               errno = EINVAL;
                return (TRUE);
        }
        x = estabd(fname, dpart);
        if (x)
                return (TRUE);
        if (makedir(dname, 0755, &sbuf) < 0) {
+               int oerrno = errno;
                notify("SUP: Can't create directory %s for %s (%s)\n", dname,
                    fname, strerror(errno));
+               errno = oerrno;
                return TRUE;
        }
        vnotify("SUP Created directory %s for %s\n", dname, fname);
diff -r 465208115c80 -r 49832d80e624 usr.sbin/sup/source/supfilesrv.c
--- a/usr.sbin/sup/source/supfilesrv.c  Wed Oct 20 16:25:01 2010 +0000
+++ b/usr.sbin/sup/source/supfilesrv.c  Wed Oct 20 17:05:54 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: supfilesrv.c,v 1.43 2009/10/17 20:46:03 christos Exp $ */
+/*     $NetBSD: supfilesrv.c,v 1.44 2010/10/20 17:05:54 christos Exp $ */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -783,7 +783,7 @@
 {
        int x;
        char *p, *q;
-       char buf[STRINGLENGTH];
+       char buf[STRINGLENGTH], filename[MAXPATHLEN];
        FILE *f;
        struct stat sbuf;
        TREELIST *tl;
@@ -882,8 +882,8 @@
                release = estrdup(DEFRELEASE);
        if (basedir == NULL || *basedir == '\0') {
                basedir = NULL;
-               (void) sprintf(buf, FILEDIRS, DEFDIR);
-               f = fopen(buf, "r");
+               (void) sprintf(filename, FILEDIRS, DEFDIR);
+               f = fopen(filename, "r");
                if (f) {
                        while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
                                q = strchr(p, '\n');
@@ -906,9 +906,10 @@
                }
        }
        if (chdir(basedir) < 0)
-               goaway("Can't chdir to base directory %s", basedir);
-       (void) sprintf(buf, FILEPREFIX, collname);
-       f = fopen(buf, "r");
+               goaway("Can't chdir to base directory %s (%s)", basedir,
+                   strerror(errno));
+       (void) sprintf(filename, FILEPREFIX, collname);
+       f = fopen(filename, "r");
        if (f) {
                while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
                        q = strchr(p, '\n');
@@ -918,8 +919,9 @@
                                continue;
                        prefix = estrdup(p);
                        if (chdir(prefix) < 0)
-                               goaway("Can't chdir to %s from base directory %s",
-                                   prefix, basedir);
+                               goaway("%s: Can't chdir to %s from base "
+                                   "directory %s (%s)", filename, prefix,
+                                   basedir, strerror(errno));
                        break;
                }
                (void) fclose(f);
@@ -928,7 +930,8 @@
        if (prefix)
                (void) chdir(basedir);
        if (x < 0)
-               goaway("Can't stat base/prefix directory");
+               goaway("Can't stat base/prefix directory (%s)",
+                   strerror(errno));
        if (nchildren >= maxchildren) {
                setupack = FSETUPBUSY;
                (void) msgsetupack();
@@ -1468,15 +1471,15 @@
        if (donereason == NULL)
                donereason = estrdup("No reason");
        if (doneack == FDONESRVERROR || doneack == FDONEUSRERROR)
-               logerr("%s", donereason);
+               logerr("%s: %s", remotehost(), donereason);
        else if (doneack == FDONEGOAWAY)
-               logerr("GOAWAY: %s", donereason);
+               logerr("GOAWAY: %s: %s", remotehost(), donereason);
        else if (doneack != FDONESUCCESS)
-               logerr("Reason %d:  %s", doneack, donereason);
+               logerr("%s: Reason %d: %s", remotehost(), doneack, donereason);
        goawayreason = donereason;
        cdprefix((char *) NULL);
        if (collname == NULL) {
-               logerr("NULL collection in svrfinishup");
+               logerr("%s: NULL collection in svrfinishup", remotehost());
                return;
        }
        (void) sprintf(lognam, FILELOGFILE, collname);
@@ -1789,7 +1792,7 @@
        va_end(ap);
        goawayreason = estrdup(buf);
        (void) msggoaway();
-       logerr("%s", buf);
+       logerr("%s: %s", remotehost(), buf);
        longjmp(sjbuf, TRUE);
 }
 



Home | Main Index | Thread Index | Old Index