Fixed a bunch of "warn_unused_result" compiler warnings.
authorWayne Davison <wayned@samba.org>
Mon, 10 Nov 2008 02:46:55 +0000 (18:46 -0800)
committerWayne Davison <wayned@samba.org>
Mon, 10 Nov 2008 02:56:21 +0000 (18:56 -0800)
batch.c
clientserver.c
lib/pool_alloc.c
options.c
receiver.c
socket.c
util.c

diff --git a/batch.c b/batch.c
index ac89583..a351041 100644 (file)
--- a/batch.c
+++ b/batch.c
@@ -156,27 +156,37 @@ void check_batch_flags(void)
                append_mode = 2;
 }
 
                append_mode = 2;
 }
 
-static void write_arg(int fd, char *arg)
+static int write_arg(int fd, char *arg)
 {
        char *x, *s;
 {
        char *x, *s;
+       int len, ret = 0;
 
        if (*arg == '-' && (x = strchr(arg, '=')) != NULL) {
 
        if (*arg == '-' && (x = strchr(arg, '=')) != NULL) {
-               write(fd, arg, x - arg + 1);
+               if (write(fd, arg, x - arg + 1) != x - arg + 1)
+                       ret = -1;
                arg += x - arg + 1;
        }
 
        if (strpbrk(arg, " \"'&;|[]()$#!*?^\\") != NULL) {
                arg += x - arg + 1;
        }
 
        if (strpbrk(arg, " \"'&;|[]()$#!*?^\\") != NULL) {
-               write(fd, "'", 1);
+               if (write(fd, "'", 1) != 1)
+                       ret = -1;
                for (s = arg; (x = strchr(s, '\'')) != NULL; s = x + 1) {
                for (s = arg; (x = strchr(s, '\'')) != NULL; s = x + 1) {
-                       write(fd, s, x - s + 1);
-                       write(fd, "'", 1);
+                       if (write(fd, s, x - s + 1) != x - s + 1
+                        || write(fd, "'", 1) != 1)
+                               ret = -1;
                }
                }
-               write(fd, s, strlen(s));
-               write(fd, "'", 1);
-               return;
+               len = strlen(s);
+               if (write(fd, s, len) != len
+                || write(fd, "'", 1) != 1)
+                       ret = -1;
+               return ret;
        }
 
        }
 
-       write(fd, arg, strlen(arg));
+       len = strlen(arg);
+       if (write(fd, arg, len) != len)
+               ret = -1;
+
+       return ret;
 }
 
 static void write_filter_rules(int fd)
 }
 
 static void write_filter_rules(int fd)
@@ -205,7 +215,7 @@ static void write_filter_rules(int fd)
  * (hopefully) work. */
 void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
 {
  * (hopefully) work. */
 void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
 {
-       int fd, i, len;
+       int fd, i, len, err = 0;
        char *p, filename[MAXPATHLEN];
 
        stringjoin(filename, sizeof filename,
        char *p, filename[MAXPATHLEN];
 
        stringjoin(filename, sizeof filename,
@@ -219,7 +229,8 @@ void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
        }
 
        /* Write argvs info to BATCH.sh file */
        }
 
        /* Write argvs info to BATCH.sh file */
-       write_arg(fd, argv[0]);
+       if (write_arg(fd, argv[0]) < 0)
+               err = 1;
        if (filter_list.head) {
                if (protocol_version >= 29)
                        write_sbuf(fd, " --filter=._-");
        if (filter_list.head) {
                if (protocol_version >= 29)
                        write_sbuf(fd, " --filter=._-");
@@ -240,25 +251,31 @@ void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
                        i++;
                        continue;
                }
                        i++;
                        continue;
                }
-               write(fd, " ", 1);
+               if (write(fd, " ", 1) != 1)
+                       err = 1;
                if (strncmp(p, "--write-batch", len = 13) == 0
                 || strncmp(p, "--only-write-batch", len = 18) == 0) {
                if (strncmp(p, "--write-batch", len = 13) == 0
                 || strncmp(p, "--only-write-batch", len = 18) == 0) {
-                       write(fd, "--read-batch", 12);
+                       if (write(fd, "--read-batch", 12) != 12)
+                               err = 1;
                        if (p[len] == '=') {
                        if (p[len] == '=') {
-                               write(fd, "=", 1);
-                               write_arg(fd, p + len + 1);
+                               if (write(fd, "=", 1) != 1
+                                || write_arg(fd, p + len + 1) < 0)
+                                       err = 1;
                        }
                        }
-               } else
-                       write_arg(fd, p);
+               } else {
+                       if (write_arg(fd, p) < 0)
+                               err = 1;
+               }
        }
        if (!(p = check_for_hostspec(argv[argc - 1], &p, &i)))
                p = argv[argc - 1];
        }
        if (!(p = check_for_hostspec(argv[argc - 1], &p, &i)))
                p = argv[argc - 1];
-       write(fd, " ${1:-", 6);
-       write_arg(fd, p);
+       if (write(fd, " ${1:-", 6) != 6
+        || write_arg(fd, p) < 0)
+               err = 1;
        write_byte(fd, '}');
        if (filter_list.head)
                write_filter_rules(fd);
        write_byte(fd, '}');
        if (filter_list.head)
                write_filter_rules(fd);
-       if (write(fd, "\n", 1) != 1 || close(fd) < 0) {
+       if (write(fd, "\n", 1) != 1 || close(fd) < 0 || err) {
                rsyserr(FERROR, errno, "Batch file %s write error",
                        filename);
                exit_cleanup(RERR_FILEIO);
                rsyserr(FERROR, errno, "Batch file %s write error",
                        filename);
                exit_cleanup(RERR_FILEIO);
index b891d79..5002959 100644 (file)
@@ -603,7 +603,8 @@ static int rsync_module(int f_in, int f_out, int i, char *addr, char *host)
                                        status = -1;
                                if (asprintf(&p, "RSYNC_EXIT_STATUS=%d", status) > 0)
                                        putenv(p);
                                        status = -1;
                                if (asprintf(&p, "RSYNC_EXIT_STATUS=%d", status) > 0)
                                        putenv(p);
-                               system(lp_postxfer_exec(i));
+                               if (system(lp_postxfer_exec(i)) < 0)
+                                       status = -1;
                                _exit(status);
                        }
                }
                                _exit(status);
                        }
                }
@@ -974,20 +975,23 @@ static void create_pid_file(void)
        char *pid_file = lp_pid_file();
        char pidbuf[16];
        pid_t pid = getpid();
        char *pid_file = lp_pid_file();
        char pidbuf[16];
        pid_t pid = getpid();
-       int fd;
+       int fd, len;
 
        if (!pid_file || !*pid_file)
                return;
 
        cleanup_set_pid(pid);
        if ((fd = do_open(pid_file, O_WRONLY|O_CREAT|O_EXCL, 0666 & ~orig_umask)) == -1) {
 
        if (!pid_file || !*pid_file)
                return;
 
        cleanup_set_pid(pid);
        if ((fd = do_open(pid_file, O_WRONLY|O_CREAT|O_EXCL, 0666 & ~orig_umask)) == -1) {
+         failure:
                cleanup_set_pid(0);
                fprintf(stderr, "failed to create pid file %s: %s\n", pid_file, strerror(errno));
                rsyserr(FLOG, errno, "failed to create pid file %s", pid_file);
                exit_cleanup(RERR_FILEIO);
        }
        snprintf(pidbuf, sizeof pidbuf, "%ld\n", (long)pid);
                cleanup_set_pid(0);
                fprintf(stderr, "failed to create pid file %s: %s\n", pid_file, strerror(errno));
                rsyserr(FLOG, errno, "failed to create pid file %s", pid_file);
                exit_cleanup(RERR_FILEIO);
        }
        snprintf(pidbuf, sizeof pidbuf, "%ld\n", (long)pid);
-       write(fd, pidbuf, strlen(pidbuf));
+       len = strlen(pidbuf);
+       if (write(fd, pidbuf, len) != len)
+               goto failure;
        close(fd);
 }
 
        close(fd);
 }
 
index 4c76d35..5856d59 100644 (file)
@@ -326,24 +326,30 @@ pool_boundary(alloc_pool_t p, size_t len)
 }
 
 #define FDPRINT(label, value) \
 }
 
 #define FDPRINT(label, value) \
-       snprintf(buf, sizeof buf, label, value), \
-       write(fd, buf, strlen(buf))
+       do { \
+               int len = snprintf(buf, sizeof buf, label, value); \
+               if (write(fd, buf, len) != len) \
+                       ret = -1; \
+       } while (0)
 
 #define FDEXTSTAT(ext) \
 
 #define FDEXTSTAT(ext) \
-       snprintf(buf, sizeof buf, "  %12ld  %5ld\n", \
-               (long) ext->free, \
-               (long) ext->bound), \
-       write(fd, buf, strlen(buf))
-
-void
+       do { \
+               int len = snprintf(buf, sizeof buf, "  %12ld  %5ld\n", \
+                                  (long)ext->free, (long)ext->bound); \
+               if (write(fd, buf, len) != len) \
+                       ret = -1; \
+       } while (0)
+
+int
 pool_stats(alloc_pool_t p, int fd, int summarize)
 {
        struct alloc_pool *pool = (struct alloc_pool *) p;
        struct pool_extent *cur;
        char buf[BUFSIZ];
 pool_stats(alloc_pool_t p, int fd, int summarize)
 {
        struct alloc_pool *pool = (struct alloc_pool *) p;
        struct pool_extent *cur;
        char buf[BUFSIZ];
+       int ret = 0;
 
        if (!pool)
 
        if (!pool)
-               return;
+               return ret;
 
        FDPRINT("  Extent size:       %12ld\n", (long)  pool->size);
        FDPRINT("  Alloc quantum:     %12ld\n", (long)  pool->quantum);
 
        FDPRINT("  Extent size:       %12ld\n", (long)  pool->size);
        FDPRINT("  Alloc quantum:     %12ld\n", (long)  pool->quantum);
@@ -355,13 +361,16 @@ pool_stats(alloc_pool_t p, int fd, int summarize)
        FDPRINT("  Bytes freed:       %12.0f\n", (double) pool->b_freed);
 
        if (summarize)
        FDPRINT("  Bytes freed:       %12.0f\n", (double) pool->b_freed);
 
        if (summarize)
-               return;
+               return ret;
 
        if (!pool->extents)
 
        if (!pool->extents)
-               return;
+               return ret;
 
 
-       write(fd, "\n", 1);
+       if (write(fd, "\n", 1) != 1)
+               ret = -1;
 
        for (cur = pool->extents; cur; cur = cur->next)
                FDEXTSTAT(cur);
 
        for (cur = pool->extents; cur; cur = cur->next)
                FDEXTSTAT(cur);
+
+       return ret;
 }
 }
index 1e5d45f..c561f47 100644 (file)
--- a/options.c
+++ b/options.c
@@ -565,7 +565,8 @@ static void print_rsync_version(enum logcode f)
        STRUCT_STAT *dumstat;
 
 #if SUBPROTOCOL_VERSION != 0
        STRUCT_STAT *dumstat;
 
 #if SUBPROTOCOL_VERSION != 0
-       asprintf(&subprotocol, ".PR%d", SUBPROTOCOL_VERSION);
+       if (asprintf(&subprotocol, ".PR%d", SUBPROTOCOL_VERSION) < 0)
+               out_of_memory("print_rsync_version");
 #endif
 #ifdef HAVE_SOCKETPAIR
        got_socketpair = "";
 #endif
 #ifdef HAVE_SOCKETPAIR
        got_socketpair = "";
index 9164247..7efd3d2 100644 (file)
@@ -285,8 +285,12 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
                goto report_write_error;
 
 #ifdef HAVE_FTRUNCATE
                goto report_write_error;
 
 #ifdef HAVE_FTRUNCATE
-       if (inplace && fd != -1)
-               ftruncate(fd, offset);
+       if (inplace && fd != -1) {
+               if (ftruncate(fd, offset) < 0) {
+                       rsyserr(FWARNING, errno, "ftruncate failed on %s",
+                               full_fname(fname));
+               }
+       }
 #endif
 
        if (INFO_GTE(PROGRESS, 1))
 #endif
 
        if (INFO_GTE(PROGRESS, 1))
index 87b1ec3..0ad766d 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -823,6 +823,7 @@ static int socketpair_tcp(int fd[2])
  **/
 int sock_exec(const char *prog)
 {
  **/
 int sock_exec(const char *prog)
 {
+       pid_t pid;
        int fd[2];
 
        if (socketpair_tcp(fd) != 0) {
        int fd[2];
 
        if (socketpair_tcp(fd) != 0) {
@@ -831,14 +832,23 @@ int sock_exec(const char *prog)
        }
        if (DEBUG_GTE(CMD, 1))
                rprintf(FINFO, "Running socket program: \"%s\"\n", prog);
        }
        if (DEBUG_GTE(CMD, 1))
                rprintf(FINFO, "Running socket program: \"%s\"\n", prog);
-       if (fork() == 0) {
+
+       pid = fork();
+       if (pid < 0) {
+               rsyserr(FERROR, errno, "fork");
+               exit_cleanup(RERR_IPC);
+       }
+
+       if (pid == 0) {
                close(fd[0]);
                close(fd[0]);
-               close(0);
-               close(1);
-               dup(fd[1]);
-               dup(fd[1]);
+               if (dup2(fd[1], STDIN_FILENO) < 0
+                || dup2(fd[1], STDOUT_FILENO) < 0) {
+                       fprintf(stderr, "Failed to run \"%s\"\n", prog);
+                       exit(1);
+               }
                exit(system(prog));
        }
                exit(system(prog));
        }
+
        close(fd[1]);
        return fd[0];
 }
        close(fd[1]);
        return fd[0];
 }
diff --git a/util.c b/util.c
index 6b075d0..373ce33 100644 (file)
--- a/util.c
+++ b/util.c
@@ -979,7 +979,10 @@ int change_dir(const char *dir, int set_path_only)
 
        if (!initialised) {
                initialised = 1;
 
        if (!initialised) {
                initialised = 1;
-               getcwd(curr_dir, sizeof curr_dir - 1);
+               if (getcwd(curr_dir, sizeof curr_dir - 1) == NULL) {
+                       rsyserr(FERROR, errno, "getcwd()");
+                       exit_cleanup(RERR_FILESELECT);
+               }
                curr_dir_len = strlen(curr_dir);
        }
 
                curr_dir_len = strlen(curr_dir);
        }