From f7f72c9098477d64394ed0fbd19374d3670447e9 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. Reviewed-on: http://gerrit.openafs.org/9980 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk (cherry picked from commit 73cad3be0a3489237ab7e66d3b12c52ffb0b67d0) Change-Id: I934406d67d7409655a7084894fd231c410d72c58 Reviewed-on: http://gerrit.openafs.org/11715 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Reviewed-by: Daria Phoebe Brashear Reviewed-by: Mark Vitale Reviewed-by: Stephan Wiesand --- 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 b19124931..5aab5226e 100644 --- a/src/aklog/aklog.c +++ b/src/aklog/aklog.c @@ -1104,8 +1104,11 @@ auth_to_cell(krb5_context context, char *cell, char *realm, char **linkedcell) * 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 status = set_kernel_token(&cellconf, username, token, afssetpag); if (status) { diff --git a/src/butm/file_tm.c b/src/butm/file_tm.c index d70751075..b637f9983 100644 --- a/src/butm/file_tm.c +++ b/src/butm/file_tm.c @@ -211,8 +211,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 */ @@ -334,8 +339,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 */ @@ -459,15 +469,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 973f795a1..8c47377b3 100644 --- a/src/rx/rx_trace.c +++ b/src/rx/rx_trace.c @@ -56,9 +56,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 aaa499203..380cb792e 100644 --- a/src/util/serverLog.c +++ b/src/util/serverLog.c @@ -101,8 +101,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(); } @@ -146,8 +148,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) @@ -359,13 +363,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) MUTEX_INIT(&serverLogMutex, "serverlog", MUTEX_DEFAULT, 0); @@ -403,17 +409,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 a7e022101..966571ddb 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -2102,7 +2102,8 @@ main(int argc, char *argv[]) plock(PROCLOCK); #else #ifndef AFS_NT40_ENV - nice(-5); /* TODO: */ + if (nice(-5) < 0) + ; /* don't care */ #endif #endif osi_Assert(DInit(buffs) == 0); diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index e72832fa4..53519dcc2 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -4904,7 +4904,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 6cbf9c375..d3ab6094c 100644 --- a/src/volser/vsprocs.c +++ b/src/volser/vsprocs.c @@ -1435,8 +1435,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) { @@ -1791,8 +1793,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) { @@ -1824,8 +1828,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) { @@ -1907,8 +1913,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