From 73cad3be0a3489237ab7e66d3b12c52ffb0b67d0 Mon Sep 17 00:00:00 2001 From: Jeffrey Hutzelman Date: Sun, 16 Jun 2013 16:28:22 -0400 Subject: [PATCH] Ignore return values harder 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 Reviewed-by: Benjamin Kaduk --- src/aklog/aklog.c | 5 ++++- src/butm/file_tm.c | 37 +++++++++++++++++++++++++++++-------- src/rx/rx_trace.c | 8 ++++++-- src/util/serverLog.c | 34 +++++++++++++++++++++------------- src/viced/viced.c | 3 ++- src/vol/vol-salvage.c | 3 ++- src/volser/vsprocs.c | 24 ++++++++++++++++-------- 7 files changed, 80 insertions(+), 34 deletions(-) diff --git a/src/aklog/aklog.c b/src/aklog/aklog.c index f7b131320..c098d8424 100644 --- a/src/aklog/aklog.c +++ b/src/aklog/aklog.c @@ -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); diff --git a/src/butm/file_tm.c b/src/butm/file_tm.c index d53dd4c4f..d25da7047 100644 --- a/src/butm/file_tm.c +++ b/src/butm/file_tm.c @@ -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 */ diff --git a/src/rx/rx_trace.c b/src/rx/rx_trace.c index d60e92896..94dc11714 100644 --- a/src/rx/rx_trace.c +++ b/src/rx/rx_trace.c @@ -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 diff --git a/src/util/serverLog.c b/src/util/serverLog.c index 877f488f8..64f081d6e 100644 --- a/src/util/serverLog.c +++ b/src/util/serverLog.c @@ -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(); diff --git a/src/viced/viced.c b/src/viced/viced.c index 7cc7aaad1..e529f69af 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -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 diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 547a5ca75..f961d9c57 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -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 diff --git a/src/volser/vsprocs.c b/src/volser/vsprocs.c index ac7fcf487..2735f78d9 100644 --- a/src/volser/vsprocs.c +++ b/src/volser/vsprocs.c @@ -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) { -- 2.39.5