summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2008-11-09 18:55:14 -0800
committerWayne Davison <wayned@samba.org>2008-11-09 18:55:14 -0800
commit3082dffbe25505db86d16a938f92b77c84ffb1fd (patch)
tree5acf18cf2bba8bb2fecf31457df854b625321e8c
parent42130f9cb0eff5a6bc7a60f7d4588663cc1361c8 (diff)
downloadrsync-3082dffbe25505db86d16a938f92b77c84ffb1fd.tar.gz
rsync-3082dffbe25505db86d16a938f92b77c84ffb1fd.tar.bz2
rsync-3082dffbe25505db86d16a938f92b77c84ffb1fd.zip
Fixed a bunch of "warn_unused_result" compiler warnings.
-rw-r--r--batch.c57
-rw-r--r--clientserver.c10
-rw-r--r--lib/pool_alloc.c33
-rw-r--r--options.c3
-rw-r--r--receiver.c8
-rw-r--r--socket.c20
-rw-r--r--util.c5
7 files changed, 92 insertions, 44 deletions
diff --git a/batch.c b/batch.c
index 033368a3..b2206cdd 100644
--- a/batch.c
+++ b/batch.c
@@ -156,27 +156,37 @@ void check_batch_flags(void)
append_mode = 2;
}
-static void write_arg(int fd, char *arg)
+static int write_arg(int fd, char *arg)
{
char *x, *s;
+ int len, ret = 0;
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) {
- write(fd, "'", 1);
+ if (write(fd, "'", 1) != 1)
+ ret = -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)
@@ -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)
{
- int fd, i, len;
+ int fd, i, len, err = 0;
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_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=._-");
@@ -240,25 +251,31 @@ void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt)
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) {
- write(fd, "--read-batch", 12);
+ if (write(fd, "--read-batch", 12) != 12)
+ err = 1;
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];
- 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);
- 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);
diff --git a/clientserver.c b/clientserver.c
index 9500bf01..28eae1b4 100644
--- a/clientserver.c
+++ b/clientserver.c
@@ -604,7 +604,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);
- system(lp_postxfer_exec(i));
+ if (system(lp_postxfer_exec(i)) < 0)
+ status = -1;
_exit(status);
}
}
@@ -970,20 +971,23 @@ static void create_pid_file(void)
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) {
+ 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);
- write(fd, pidbuf, strlen(pidbuf));
+ len = strlen(pidbuf);
+ if (write(fd, pidbuf, len) != len)
+ goto failure;
close(fd);
}
diff --git a/lib/pool_alloc.c b/lib/pool_alloc.c
index 0fb31225..292167a4 100644
--- a/lib/pool_alloc.c
+++ b/lib/pool_alloc.c
@@ -295,24 +295,30 @@ pool_boundary(alloc_pool_t p, size_t len)
}
#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) \
- 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];
+ int ret = 0;
if (!pool)
- return;
+ return ret;
FDPRINT(" Extent size: %12ld\n", (long) pool->size);
FDPRINT(" Alloc quantum: %12ld\n", (long) pool->quantum);
@@ -324,13 +330,16 @@ pool_stats(alloc_pool_t p, int fd, int summarize)
FDPRINT(" Bytes freed: %12.0f\n", (double) pool->b_freed);
if (summarize)
- return;
+ return ret;
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);
+
+ return ret;
}
diff --git a/options.c b/options.c
index 71fda24f..90c0b914 100644
--- a/options.c
+++ b/options.c
@@ -228,7 +228,8 @@ static void print_rsync_version(enum logcode f)
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 = "";
diff --git a/receiver.c b/receiver.c
index 1fe2fe15..44df007e 100644
--- a/receiver.c
+++ b/receiver.c
@@ -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
- 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 (do_progress)
diff --git a/socket.c b/socket.c
index 8d4a89db..bc3bb374 100644
--- a/socket.c
+++ b/socket.c
@@ -823,6 +823,7 @@ static int socketpair_tcp(int fd[2])
**/
int sock_exec(const char *prog)
{
+ pid_t pid;
int fd[2];
if (socketpair_tcp(fd) != 0) {
@@ -831,14 +832,23 @@ int sock_exec(const char *prog)
}
if (verbose >= 2)
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(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));
}
+
close(fd[1]);
return fd[0];
}
diff --git a/util.c b/util.c
index 4981d764..fb82e537 100644
--- a/util.c
+++ b/util.c
@@ -979,7 +979,10 @@ int change_dir(const char *dir, int set_path_only)
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);
}