salvager: redd up showlog global flag
authorMichael Meffie <mmeffie@sinenomine.net>
Wed, 9 Sep 2015 17:22:26 +0000 (13:22 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 3 Dec 2015 04:53:58 +0000 (23:53 -0500)
Clean up the show log flag so it is only set by the salvager and
is reset when spawning a child process.

Change-Id: I1702cf98faca583409594d1199a8215ffe08a75e
Reviewed-on: http://gerrit.openafs.org/12001
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/vol/salvaged.c
src/vol/salvager.c
src/vol/vol-salvage.c
src/vol/vol-salvage.h

index 7e4717b..dca7792 100644 (file)
@@ -606,7 +606,6 @@ DoSalvageVolume(struct SalvageQueueNode * node, int slot)
        logFile = afs_fopen(childLog, "a");
        if (!logFile) {         /* still nothing, use stdout */
            logFile = stdout;
-           ShowLog = 0;
        }
        free(childLog);
     }
index d9b96ad..bd5119f 100644 (file)
@@ -252,7 +252,6 @@ handleit(struct cmd_syndesc *as, void *arock)
 #ifndef AFS_NT40_ENV           /* ignore options on NT */
     if ((ti = as->parms[16].items)) {  /* -syslog */
        useSyslog = 1;
-       ShowLog = 0;
     }
     if ((ti = as->parms[17].items)) {  /* -syslogfacility */
        useSyslogFacility = atoi(ti->data);
index 8ad286d..4a7b2eb 100644 (file)
@@ -281,6 +281,8 @@ char *tmpdir = NULL;
 
 
 /* Forward declarations */
+static void QuietExit(int) AFS_NORETURN;
+static void SalvageShowLog(void);
 static int IsVnodeOrphaned(struct SalvInfo *salvinfo, VnodeId vnode);
 static int AskVolumeSummary(struct SalvInfo *salvinfo,
                             VolumeId singleVolumeNumber);
@@ -608,7 +610,7 @@ SalvageFileSysParallel(struct DiskPartition64 *partP)
            } else {
                int fd;
 
-               ShowLog = 0;
+               ShowLog = 0; /* Child processes do not display. */
                for (fd = 0; fd < 16; fd++)
                    close(fd);
                open(OS_DIRSEP, 0);
@@ -663,8 +665,7 @@ SalvageFileSys(struct DiskPartition64 *partP, VolumeId singleVolumeNumber)
     if (!canfork || debug || Fork() == 0) {
        SalvageFileSys1(partP, singleVolumeNumber);
        if (canfork && !debug) {
-           ShowLog = 0;
-           Exit(0);
+           QuietExit(0);
        }
     } else
        Wait("SalvageFileSys");
@@ -1304,8 +1305,7 @@ GetInodeSummary(struct SalvInfo *salvinfo, FD_t inodeFile, VolumeId singleVolume
            goto error;
        }
        if (canfork && !debug) {
-           ShowLog = 0;
-           Exit(0);
+           QuietExit(0);
        }
     } else {
        if (Wait("Inode summary") == -1) {
@@ -2192,8 +2192,7 @@ DoSalvageVolumeGroup(struct SalvInfo *salvinfo, struct InodeSummary *isp, int nV
     IH_RELEASE(salvinfo->VGLinkH);
 
     if (canfork && !debug) {
-       ShowLog = 0;
-       Exit(0);
+       QuietExit(0);
     }
 }
 
@@ -4763,12 +4762,9 @@ Fork(void)
     return f;
 }
 
-void
-Exit(int code)
+static void
+QuietExit(int code)
 {
-    if (ShowLog)
-       showlog();
-
 #ifdef AFS_DEMAND_ATTACH_FS
     if (programType == salvageServer) {
        /* release all volume locks before closing down our SYNC channels.
@@ -4802,6 +4798,14 @@ Exit(int code)
 #endif
 }
 
+void
+Exit(int code)
+{
+    SalvageShowLog();
+    QuietExit(code);
+}
+
+
 int
 Wait(char *prog)
 {
@@ -4836,7 +4840,6 @@ CheckLogFile(char * log_path)
 
 #ifndef AFS_NT40_ENV
     if (useSyslog) {
-       ShowLog = 0;
        return;
     }
 #endif
@@ -4850,7 +4853,6 @@ CheckLogFile(char * log_path)
 
        if (!logFile) {         /* still nothing, use stdout */
            logFile = stdout;
-           ShowLog = 0;
        }
 #ifndef AFS_NAMEI_ENV
        AFS_DEBUG_IOPS_LOG(logFile);
@@ -4881,11 +4883,15 @@ TimeStampLogFile(char * log_path)
 }
 #endif
 
-void
-showlog(void)
+static void
+SalvageShowLog(void)
 {
     char line[256];
 
+    if (ShowLog == 0 || logFile == stdout || logFile == stderr) {
+       return;
+    }
+
 #ifndef AFS_NT40_ENV
     if (useSyslog) {
        printf("Can't show log since using syslog.\n");
@@ -4950,13 +4956,12 @@ Abort(const char *format, ...)
        if (logFile) {
            fprintf(logFile, "%s", tmp);
            fflush(logFile);
-           if (ShowLog)
-               showlog();
+           SalvageShowLog();
        }
 
     if (debug)
        abort();
-    Exit(1);
+    QuietExit(1);
 }
 
 char *
index 014cf68..83bc55f 100644 (file)
@@ -252,7 +252,6 @@ extern int SalvageVolumeHeaderFile(struct SalvInfo *salvinfo,
                                    struct InodeSummary *isp,
                                    struct ViceInodeInfo *inodes, int RW,
                                    int check, int *deleteMe);
-extern void showlog(void);
 extern int UseTheForceLuke(char *path);