Module Name: src
Committed By: christos
Date: Wed Oct 20 17:05:54 UTC 2010
Modified Files:
src/usr.sbin/sup/source: scmio.c supcmeat.c supcmisc.c supfilesrv.c
Log Message:
improve error handling and logging.
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/sup/source/scmio.c
cvs rdiff -u -r1.37 -r1.38 src/usr.sbin/sup/source/supcmeat.c
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/sup/source/supcmisc.c
cvs rdiff -u -r1.43 -r1.44 src/usr.sbin/sup/source/supfilesrv.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/sup/source/scmio.c
diff -u src/usr.sbin/sup/source/scmio.c:1.19 src/usr.sbin/sup/source/scmio.c:1.20
--- src/usr.sbin/sup/source/scmio.c:1.19 Sun Oct 18 11:23:54 2009
+++ src/usr.sbin/sup/source/scmio.c Wed Oct 20 13:05:54 2010
@@ -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);
}
Index: src/usr.sbin/sup/source/supcmeat.c
diff -u src/usr.sbin/sup/source/supcmeat.c:1.37 src/usr.sbin/sup/source/supcmeat.c:1.38
--- src/usr.sbin/sup/source/supcmeat.c:1.37 Sat Oct 17 16:46:03 2009
+++ src/usr.sbin/sup/source/supcmeat.c Wed Oct 20 13:05:54 2010
@@ -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;
}
Index: src/usr.sbin/sup/source/supcmisc.c
diff -u src/usr.sbin/sup/source/supcmisc.c:1.20 src/usr.sbin/sup/source/supcmisc.c:1.21
--- src/usr.sbin/sup/source/supcmisc.c:1.20 Fri Oct 16 08:41:37 2009
+++ src/usr.sbin/sup/source/supcmisc.c Wed Oct 20 13:05:54 2010
@@ -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);
Index: src/usr.sbin/sup/source/supfilesrv.c
diff -u src/usr.sbin/sup/source/supfilesrv.c:1.43 src/usr.sbin/sup/source/supfilesrv.c:1.44
--- src/usr.sbin/sup/source/supfilesrv.c:1.43 Sat Oct 17 16:46:03 2009
+++ src/usr.sbin/sup/source/supfilesrv.c Wed Oct 20 13:05:54 2010
@@ -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);
}