Avoid 'salvageserver -client -showlog' segfault
authorAndrew Deason <adeason@sinenomine.net>
Fri, 23 Oct 2009 20:02:12 +0000 (15:02 -0500)
committerDerrick Brashear <shadow|account-1000005@unknown>
Mon, 26 Oct 2009 18:54:04 +0000 (11:54 -0700)
Running salvageserver with the -client and -showlog options will
currently segfault, since -client does not open logFile, and -showlog
will attempt to rewind logFile on exit.

Fix this by not allowing -client and -showlog together (since it won't
work anyway, as -showlog tries to read SalvageLog), and by making
showlog() check logFile for NULL-ness.

Change-Id: I30f43ef1696f1e7e8873b9e1cc3867b4e06d1980
Reviewed-on: http://gerrit.openafs.org/734
Tested-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

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

index 2a79027..6094f1e 100644 (file)
@@ -274,6 +274,11 @@ handleit(struct cmd_syndesc *as, void *arock)
            vid = atoi(ti->data);
        }
 
+       if (ShowLog) {
+           printf("-showlog does not work with -client\n");
+           exit(-1);
+       }
+
        if (!seenpart || !seenvol) {
            printf("You must specify '-partition' and '-volumeid' with the '-client' option\n");
            exit(-1);
index f66ae82..e5daf80 100644 (file)
@@ -3563,8 +3563,10 @@ showlog(void)
     }
 #endif
 
-    rewind(logFile);
-    fclose(logFile);
+    if (logFile) {
+       rewind(logFile);
+       fclose(logFile);
+    }
 
     logFile = afs_fopen(AFSDIR_SERVER_SLVGLOG_FILEPATH, "r");