Ignore return values harder
authorJeffrey Hutzelman <jhutz@cmu.edu>
Sun, 16 Jun 2013 20:28:22 +0000 (16:28 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 5 Feb 2015 19:50:27 +0000 (14:50 -0500)
In various places where we intentionally ignore the return values of system
calls and standard library routines, this changes the way in which we do so,
to avoid compiler warnings when building on Ubuntu 12.10, with gcc 4.7.2 and
eglibc 2.15-0ubuntu20.1.

Change-Id: I41f806a686d68b02aec2847886bd5d787cbff3d3
Reviewed-on: http://gerrit.openafs.org/9980
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/aklog/aklog.c
src/butm/file_tm.c
src/rx/rx_trace.c
src/util/serverLog.c
src/viced/viced.c
src/vol/vol-salvage.c
src/volser/vsprocs.c

index f7b1313..c098d84 100644 (file)
@@ -1094,8 +1094,11 @@ auth_to_cell(krb5_context context, const char *config,
         * this routine, it will not add the token. It is not clear what
         * is going on here! So we will do the following operation.
         * On AIX 5, it causes the parent program to die, so we won't.
+        * We don't care about the return value, but need to collect it
+        * to avoid compiler warnings.
         */
-       write(2,"",0); /* dummy write */
+       if (write(2,"",0) < 0) /* dummy write */
+           ; /* don't care */
 #endif
        token_setPag(token, afssetpag);
        status = ktc_SetTokenEx(token);
index d53dd4c..d25da70 100644 (file)
@@ -204,8 +204,13 @@ ForkIoctl(usd_handle_t fd, int op, int count)
        /* do the ioctl call */
        ioctl_rc = USD_IOCTL(fd, USD_IOCTL_TAPEOPERATION, (void *)&tapeop);
 
-       /* send the return code back to the parent */
-       write(pipefd[1], &ioctl_rc, sizeof(int));
+       /*
+        * Send the return code back to the parent.
+        * If this fails, there's nothing we can do, but we must test
+        * it in order to avoid complier warnings on some platforms.
+        */
+       if (write(pipefd[1], &ioctl_rc, sizeof(int)) < 0)
+           ; /* don't care */
 
        exit(0);
     } else {                   /* parent process */
@@ -327,8 +332,13 @@ ForkOpen(char *device)
            USD_CLOSE(fd);
        }
 
-       /* send the return code back to the parent */
-       write(pipefd[1], &open_rc, sizeof(open_rc));
+       /*
+        * Send the return code back to the parent.
+        * If this fails, there's nothing we can do, but we must test
+        * it in order to avoid complier warnings on some platforms.
+        */
+       if (write(pipefd[1], &open_rc, sizeof(open_rc)) < 0)
+           ; /* don't care */
 
        exit(0);
     } else {                   /* parent process */
@@ -452,15 +462,26 @@ ForkClose(usd_handle_t fd)
            }
        }
 
-       /* the parent writes the control pipe after it closes the device */
-       read(ctlpipe[0], &close_rc, sizeof(int));
+       /*
+        * The parent writes the control pipe after it closes the device.
+        * We don't actually care about the read; we're just using it to
+        * block until the parent is ready.  But we must do something
+        * with the result, to avoid complier warnings on some platforms.
+        */
+       if (read(ctlpipe[0], &close_rc, sizeof(int)) < 0)
+           ; /* don't care */
        close(ctlpipe[0]);
 
        /* do the close */
        close_rc = USD_CLOSE(fd);
 
-       /* send the return code back to the parent */
-       write(pipefd[1], &close_rc, sizeof(int));
+       /*
+        * Send the return code back to the parent.
+        * If this fails, there's nothing we can do, but we must test
+        * it in order to avoid complier warnings on some platforms.
+        */
+       if (write(pipefd[1], &close_rc, sizeof(int)) < 0)
+           ; /* don't care */
 
        exit(0);
     } else {                   /* parent process */
index d60e928..94dc117 100644 (file)
@@ -55,9 +55,13 @@ struct rx_trace {
 void
 rxi_flushtrace(void)
 {
-    if (rxi_logfd >= 0)
-       write(rxi_logfd, rxi_tracebuf, rxi_tracepos);
+    afs_uint32 len = rxi_tracepos;
+
     rxi_tracepos = 0;
+    if (rxi_logfd < 0)
+       return;
+    if (write(rxi_logfd, rxi_tracebuf, len) < 0)
+       ; /* don't care */
 }
 
 void
index 877f488..64f081d 100644 (file)
@@ -81,8 +81,10 @@ void
 WriteLogBuffer(char *buf, afs_uint32 len)
 {
     LOCK_SERVERLOG();
-    if (serverLogFD > 0)
-       (void)write(serverLogFD, buf, len);
+    if (serverLogFD > 0) {
+       if (write(serverLogFD, buf, len) < 0)
+           ; /* don't care */
+    }
     UNLOCK_SERVERLOG();
 }
 
@@ -125,8 +127,10 @@ vFSLog(const char *format, va_list args)
        syslog(LOG_INFO, "%s", info);
     } else
 #endif
-    if (serverLogFD > 0)
-       (void)write(serverLogFD, tbuffer, len);
+    if (serverLogFD > 0) {
+       if (write(serverLogFD, tbuffer, len) < 0)
+           ; /* don't care */
+    }
     UNLOCK_SERVERLOG();
 
 #if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
@@ -340,13 +344,15 @@ OpenLog(const char *fileName)
        return -1;
     }
     /* redirect stdout and stderr so random printf's don't write to data */
-    (void)freopen(fileName, "a", stdout);
-    (void)freopen(fileName, "a", stderr);
+    if (freopen(fileName, "a", stdout) == NULL)
+       ; /* don't care */
+    if (freopen(fileName, "a", stderr) != NULL) {
 #ifdef HAVE_SETVBUF
-    setvbuf(stderr, NULL, _IONBF, 0);
+       setvbuf(stderr, NULL, _IONBF, 0);
 #else
-    setbuf(stderr, NULL);
+       setbuf(stderr, NULL);
 #endif
+    }
 
 #if defined(AFS_PTHREAD_ENV)
     opr_Verify(pthread_mutex_init(&serverLogMutex, NULL) == 0);
@@ -384,17 +390,19 @@ ReOpenLog(const char *fileName)
        close(serverLogFD);
     serverLogFD = open(fileName, O_WRONLY | O_APPEND | O_CREAT | (isfifo?O_NONBLOCK:0), 0666);
     if (serverLogFD > 0) {
-       (void)freopen(fileName, "a", stdout);
-       (void)freopen(fileName, "a", stderr);
+       if (freopen(fileName, "a", stdout) == NULL)
+           ; /* don't care */
+       if (freopen(fileName, "a", stderr) != NULL) {
 #ifdef HAVE_SETVBUF
 #ifdef SETVBUF_REVERSED
-       setvbuf(stderr, _IONBF, NULL, 0);
+           setvbuf(stderr, _IONBF, NULL, 0);
 #else
-       setvbuf(stderr, NULL, _IONBF, 0);
+           setvbuf(stderr, NULL, _IONBF, 0);
 #endif
 #else
-       setbuf(stderr, NULL);
+           setbuf(stderr, NULL);
 #endif
+       }
 
     }
     UNLOCK_SERVERLOG();
index 7cc7aaa..e529f69 100644 (file)
@@ -1912,7 +1912,8 @@ main(int argc, char *argv[])
     if (SawLock)
        plock(PROCLOCK);
 #elif !defined(AFS_NT40_ENV)
-    nice(-5);                  /* TODO: */
+    if (nice(-5) < 0)
+       ; /* don't care */
 #endif
     DInit(buffs);
 #ifdef AFS_DEMAND_ATTACH_FS
index 547a5ca..f961d9c 100644 (file)
@@ -4874,7 +4874,8 @@ TimeStampLogFile(char * log_path)
 
     /* try to link the logfile to a timestamped filename */
     /* if it fails, oh well, nothing we can do */
-    link(log_path, stampSlvgLog);
+    if (link(log_path, stampSlvgLog))
+       ; /* oh well */
 }
 #endif
 
index ac7fcf4..2735f78 100644 (file)
@@ -1562,8 +1562,10 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
        fprintf(STDOUT, "First test point - operation not started.\n");
        fprintf(STDOUT, "...test here (y, n)? ");
        fflush(STDOUT);
-       fscanf(stdin, "%c", &in);
-       fscanf(stdin, "%c", &lf);       /* toss away */
+       if (fscanf(stdin, "%c", &in) < 1)
+           in = 0;
+       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
+           ; /* don't care */
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {
@@ -1918,8 +1920,10 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
                "Second test point - operation in progress but not complete.\n");
        fprintf(STDOUT, "...test here (y, n)? ");
        fflush(STDOUT);
-       fscanf(stdin, "%c", &in);
-       fscanf(stdin, "%c", &lf);       /* toss away */
+       if (fscanf(stdin, "%c", &in) < 1)
+           in = 0;
+       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
+           ; /* don't care */
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {
@@ -1951,8 +1955,10 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
                "Third test point - operation complete but no cleanup.\n");
        fprintf(STDOUT, "...test here (y, n)? ");
        fflush(STDOUT);
-       fscanf(stdin, "%c", &in);
-       fscanf(stdin, "%c", &lf);       /* toss away */
+       if (fscanf(stdin, "%c", &in) < 1)
+           in = 0;
+       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
+           ; /* don't care */
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {
@@ -2034,8 +2040,10 @@ UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
        fprintf(STDOUT, "Fourth test point - operation complete.\n");
        fprintf(STDOUT, "...test here (y, n)? ");
        fflush(STDOUT);
-       fscanf(stdin, "%c", &in);
-       fscanf(stdin, "%c", &lf);       /* toss away */
+       if (fscanf(stdin, "%c", &in) < 1)
+           in = 0;
+       if (fscanf(stdin, "%c", &lf) < 0)       /* toss away */
+           ; /* don't care */
        if (in == 'y') {
            fprintf(STDOUT, "type control-c\n");
            while (1) {