From d62bcc17f303f30d1e3df1051b1390202a21cf9c Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sat, 15 May 2004 19:31:10 +0000 Subject: [PATCH] Changed rprintf() calls that included strerror() to use rsyserr(). --- backup.c | 36 ++++++++++++++++++------------------ batch.c | 39 ++++++++++++++++----------------------- clientname.c | 3 +-- clientserver.c | 8 ++++---- flist.c | 26 ++++++++++++-------------- generator.c | 43 ++++++++++++++++++++++--------------------- hlink.c | 11 +++++------ io.c | 47 ++++++++++++++++++++++------------------------- params.c | 4 ++-- pipe.c | 20 +++++++++----------- receiver.c | 33 +++++++++++++++++---------------- rsync.c | 40 ++++++++++++++++++++-------------------- sender.c | 13 +++++++------ socket.c | 32 +++++++++++++------------------- util.c | 23 +++++++++-------------- 15 files changed, 177 insertions(+), 201 deletions(-) diff --git a/backup.c b/backup.c index 391e3556..2c69acd1 100644 --- a/backup.c +++ b/backup.c @@ -49,7 +49,8 @@ static int make_simple_backup(char *fname) if (do_rename(fname, fnamebak) != 0) { /* cygwin (at least version b19) reports EINVAL */ if (errno != ENOENT && errno != EINVAL) { - rsyserr(FERROR, errno, "rename %s to backup %s", fname, fnamebak); + rsyserr(FERROR, errno, + "rename %s to backup %s", fname, fnamebak); return 0; } } else if (verbose > 1) { @@ -84,9 +85,9 @@ static int make_bak_dir(char *fullpath) if (do_mkdir(fullpath, 0777 & ~orig_umask) == 0) break; if (errno != ENOENT) { - rprintf(FERROR, - "make_bak_dir mkdir %s failed: %s\n", - full_fname(fullpath), strerror(errno)); + rsyserr(FERROR, errno, + "make_bak_dir mkdir %s failed", + full_fname(fullpath)); goto failure; } } @@ -98,9 +99,9 @@ static int make_bak_dir(char *fullpath) /* Try to transfer the directory settings of the * actual dir that the files are coming from. */ if (do_lstat(rel, &st) != 0) { - rprintf(FERROR, - "make_bak_dir stat %s failed: %s\n", - full_fname(rel), strerror(errno)); + rsyserr(FERROR, errno, + "make_bak_dir stat %s failed", + full_fname(rel)); } else { do_lchown(fullpath, st.st_uid, st.st_gid); do_chmod(fullpath, st.st_mode); @@ -111,9 +112,8 @@ static int make_bak_dir(char *fullpath) if (p == end) break; if (do_mkdir(fullpath, 0777 & ~orig_umask) < 0) { - rprintf(FERROR, - "make_bak_dir mkdir %s failed: %s\n", - full_fname(fullpath), strerror(errno)); + rsyserr(FERROR, errno, "make_bak_dir mkdir %s failed", + full_fname(fullpath)); goto failure; } } @@ -172,8 +172,8 @@ static int keep_backup(char *fname) if (do_mknod(backup_dir_buf, file->mode, file->u.rdev) < 0 && (errno != ENOENT || make_bak_dir(backup_dir_buf) < 0 || do_mknod(backup_dir_buf, file->mode, file->u.rdev) < 0)) { - rprintf(FERROR, "mknod %s failed: %s\n", - full_fname(backup_dir_buf), strerror(errno)); + rsyserr(FERROR, errno, "mknod %s failed", + full_fname(backup_dir_buf)); } else if (verbose > 2) { rprintf(FINFO, "make_backup: DEVICE %s successful.\n", @@ -190,8 +190,8 @@ static int keep_backup(char *fname) if (do_mkdir(backup_dir_buf, file->mode) < 0 && (errno != ENOENT || make_bak_dir(backup_dir_buf) < 0 || do_mkdir(backup_dir_buf, file->mode) < 0)) { - rprintf(FINFO, "mkdir %s failed: %s\n", - full_fname(backup_dir_buf), strerror(errno)); + rsyserr(FINFO, errno, "mkdir %s failed", + full_fname(backup_dir_buf)); } ret_code = do_rmdir(fname); @@ -214,8 +214,8 @@ static int keep_backup(char *fname) if (do_symlink(file->u.link, backup_dir_buf) < 0 && (errno != ENOENT || make_bak_dir(backup_dir_buf) < 0 || do_symlink(file->u.link, backup_dir_buf) < 0)) { - rprintf(FERROR, "link %s -> %s : %s\n", - full_fname(backup_dir_buf), file->u.link, strerror(errno)); + rsyserr(FERROR, errno, "link %s -> \"%s\"", + full_fname(backup_dir_buf), file->u.link); } do_unlink(fname); kept = 1; @@ -230,8 +230,8 @@ static int keep_backup(char *fname) /* move to keep tree if a file */ if (!kept) { if (robust_move(fname, backup_dir_buf) != 0) { - rprintf(FERROR, "keep_backup failed: %s -> \"%s\": %s\n", - full_fname(fname), backup_dir_buf, strerror(errno)); + rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"", + full_fname(fname), backup_dir_buf); } } set_perms(backup_dir_buf, file, NULL, 0); diff --git a/batch.c b/batch.c index 33364e6b..ade94847 100644 --- a/batch.c +++ b/batch.c @@ -34,8 +34,7 @@ void write_batch_flist_info(int flist_count, struct file_struct **files) f = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (f < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s open error", filename); exit_cleanup(1); } @@ -72,8 +71,7 @@ void write_batch_argvs_file(int argc, char *argv[]) f = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IEXEC); if (f < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s open error", filename); exit_cleanup(1); } buff[0] = '\0'; @@ -111,8 +109,7 @@ void write_batch_argvs_file(int argc, char *argv[]) } strlcat(buff, "\n", sizeof buff); if (!write(f, buff, strlen(buff))) { - rprintf(FERROR, "Batch file %s write error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s write error", filename); close(f); exit_cleanup(1); } @@ -131,8 +128,7 @@ struct file_list *create_flist_from_batch(void) f = do_open(filename, O_RDONLY, 0); if (f < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s open error", filename); exit_cleanup(1); } @@ -161,8 +157,7 @@ struct file_list *create_flist_from_batch(void) void write_batch_csums_file(void *buff, int bytes_to_write) { if (write(f_csums, buff, bytes_to_write) < 0) { - rprintf(FERROR, "Batch file write error: %s\n", - strerror(errno)); + rsyserr(FERROR, errno, "Batch file write error"); close(f_csums); exit_cleanup(1); } @@ -196,8 +191,8 @@ void write_batch_csum_info(int *flist_entry, struct sum_struct *s) f_csums = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (f_csums < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s open error", + filename); close(f_csums); exit_cleanup(1); } @@ -221,7 +216,7 @@ int read_batch_csums_file(char *buff, int len) int bytes_read; if ((bytes_read = read(f_csums, buff, len)) < 0) { - rprintf(FERROR, "Batch file read error: %s\n", strerror(errno)); + rsyserr(FERROR, errno, "Batch file read error"); close(f_csums); exit_cleanup(1); } @@ -244,8 +239,8 @@ void read_batch_csum_info(int flist_entry, struct sum_struct *s, f_csums = do_open(filename, O_RDONLY, 0); if (f_csums < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s open error", + filename); close(f_csums); exit_cleanup(1); } @@ -284,15 +279,14 @@ void write_batch_delta_file(char *buff, int bytes_to_write) f_delta = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (f_delta < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s open error", + filename); exit_cleanup(1); } } if (write(f_delta, buff, bytes_to_write) < 0) { - rprintf(FERROR, "Batch file %s write error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s write error", filename); close(f_delta); exit_cleanup(1); } @@ -315,8 +309,8 @@ int read_batch_delta_file(char *buff, int len) f_delta = do_open(filename, O_RDONLY, 0); if (f_delta < 0) { - rprintf(FERROR, "Batch file %s open error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s open error", + filename); close(f_delta); exit_cleanup(1); } @@ -324,8 +318,7 @@ int read_batch_delta_file(char *buff, int len) bytes_read = read(f_delta, buff, len); if (bytes_read < 0) { - rprintf(FERROR, "Batch file %s read error: %s\n", - filename, strerror(errno)); + rsyserr(FERROR, errno, "Batch file %s read error", filename); close(f_delta); exit_cleanup(1); } diff --git a/clientname.c b/clientname.c index 53167dfb..b54e745f 100644 --- a/clientname.c +++ b/clientname.c @@ -170,8 +170,7 @@ void client_sockaddr(int fd, if (getpeername(fd, (struct sockaddr *) ss, ss_len)) { /* FIXME: Can we really not continue? */ - rprintf(FERROR, RSYNC_NAME ": getpeername on fd%d failed: %s\n", - fd, strerror(errno)); + rsyserr(FERROR, errno, "getpeername on fd%d failed", fd); exit_cleanup(RERR_SOCKETIO); } diff --git a/clientserver.c b/clientserver.c index dbc80e82..a1e15c06 100644 --- a/clientserver.c +++ b/clientserver.c @@ -233,10 +233,10 @@ static int rsync_module(int f_in, int f_out, int i) if (!claim_connection(lp_lock_file(i), lp_max_connections(i))) { if (errno) { - rprintf(FERROR,"failed to open lock file %s : %s\n", - lp_lock_file(i), strerror(errno)); - io_printf(f_out, "@ERROR: failed to open lock file %s : %s\n", - lp_lock_file(i), strerror(errno)); + rsyserr(FERROR, errno, "failed to open lock file %s", + lp_lock_file(i)); + io_printf(f_out, "@ERROR: failed to open lock file %s\n", + lp_lock_file(i)); } else { rprintf(FERROR,"max connections (%d) reached\n", lp_max_connections(i)); diff --git a/flist.c b/flist.c index e905a18f..41acca35 100644 --- a/flist.c +++ b/flist.c @@ -778,8 +778,8 @@ struct file_struct *make_file(char *fname, } else { io_error |= IOERR_GENERAL; - rprintf(FERROR, "readlink %s failed: %s\n", - full_fname(thisname), strerror(save_errno)); + rsyserr(FERROR, save_errno, "readlink %s failed", + full_fname(thisname)); } return NULL; } @@ -970,8 +970,7 @@ static void send_directory(int f, struct file_list *flist, char *dir) d = opendir(dir); if (!d) { io_error |= IOERR_GENERAL; - rprintf(FERROR, "opendir %s failed: %s\n", - full_fname(dir), strerror(errno)); + rsyserr(FERROR, errno, "opendir %s failed", full_fname(dir)); return; } @@ -1018,8 +1017,7 @@ static void send_directory(int f, struct file_list *flist, char *dir) } if (errno) { io_error |= IOERR_GENERAL; - rprintf(FERROR, "readdir(%s): (%d) %s\n", - dir, errno, strerror(errno)); + rsyserr(FERROR, errno, "readdir(%s)", dir); } closedir(d); @@ -1054,8 +1052,8 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) io_start_buffering_out(f); if (filesfrom_fd >= 0) { if (argv[0] && !push_dir(argv[0])) { - rprintf(FERROR, "push_dir %s failed: %s\n", - full_fname(argv[0]), strerror(errno)); + rsyserr(FERROR, errno, "push_dir %s failed", + full_fname(argv[0])); exit_cleanup(RERR_FILESELECT); } use_ff_fd = 1; @@ -1092,8 +1090,8 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) if (link_stat(fname, &st) != 0) { if (f != -1) { io_error |= IOERR_GENERAL; - rprintf(FERROR, "link_stat %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "link_stat %s failed", + full_fname(fname)); } continue; } @@ -1162,8 +1160,8 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) if (!push_dir(dir)) { io_error |= IOERR_GENERAL; - rprintf(FERROR, "push_dir %s failed: %s\n", - full_fname(dir), strerror(errno)); + rsyserr(FERROR, errno, "push_dir %s failed", + full_fname(dir)); continue; } @@ -1185,8 +1183,8 @@ struct file_list *send_file_list(int f, int argc, char *argv[]) flist_dir = NULL; flist_dir_len = 0; if (!pop_dir(olddir)) { - rprintf(FERROR, "pop_dir %s failed: %s\n", - full_fname(dir), strerror(errno)); + rsyserr(FERROR, errno, "pop_dir %s failed", + full_fname(dir)); exit_cleanup(RERR_FILESELECT); } } diff --git a/generator.c b/generator.c index 4a6d82ef..01cba43c 100644 --- a/generator.c +++ b/generator.c @@ -309,19 +309,20 @@ void recv_generator(char *fname, struct file_struct *file, int i, int f_out) if (dry_run) return; /* XXXX -- might cause inaccuracies?? -- mbp */ if (statret == 0 && !S_ISDIR(st.st_mode)) { if (robust_unlink(fname) != 0) { - rprintf(FERROR, - "recv_generator: unlink %s to make room for directory: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, + "recv_generator: unlink %s to make room for directory", + full_fname(fname)); return; } statret = -1; } if (statret != 0 && do_mkdir(fname,file->mode) != 0 && errno != EEXIST) { - if (!(relative_paths && errno==ENOENT && - create_directory_path(fname, orig_umask)==0 && - do_mkdir(fname,file->mode)==0)) { - rprintf(FERROR, "recv_generator: mkdir %s failed: %s\n", - full_fname(fname), strerror(errno)); + if (!(relative_paths && errno == ENOENT + && create_directory_path(fname, orig_umask) == 0 + && do_mkdir(fname, file->mode) == 0)) { + rsyserr(FERROR, errno, + "recv_generator: mkdir %s failed", + full_fname(fname)); } } /* f_out is set to -1 when doing final directory @@ -362,8 +363,8 @@ void recv_generator(char *fname, struct file_struct *file, int i, int f_out) delete_file(fname); } if (do_symlink(file->u.link,fname) != 0) { - rprintf(FERROR, "symlink %s -> \"%s\" failed: %s\n", - full_fname(fname), file->u.link, strerror(errno)); + rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed", + full_fname(fname), file->u.link); } else { set_perms(fname,file,NULL,0); if (verbose) { @@ -380,12 +381,13 @@ void recv_generator(char *fname, struct file_struct *file, int i, int f_out) st.st_mode != file->mode || st.st_rdev != file->u.rdev) { delete_file(fname); - if (verbose > 2) + if (verbose > 2) { rprintf(FINFO,"mknod(%s,0%o,0x%x)\n", fname,(int)file->mode,(int)file->u.rdev); + } if (do_mknod(fname,file->mode,file->u.rdev) != 0) { - rprintf(FERROR, "mknod %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "mknod %s failed", + full_fname(fname)); } else { set_perms(fname,file,NULL,0); if (verbose) @@ -421,9 +423,8 @@ void recv_generator(char *fname, struct file_struct *file, int i, int f_out) else if (link_dest && !dry_run) { if (do_link(fnamecmpbuf, fname) != 0) { if (verbose > 0) { - rprintf(FINFO,"link %s => %s : %s\n", - fnamecmpbuf, fname, - strerror(errno)); + rsyserr(FINFO, errno, "link %s => %s", + fnamecmpbuf, fname); } } fnamecmp = fnamecmpbuf; @@ -440,9 +441,9 @@ void recv_generator(char *fname, struct file_struct *file, int i, int f_out) write_int(f_out,i); if (!dry_run) write_sum_head(f_out, NULL); } else if (verbose > 1) { - rprintf(FERROR, - "recv_generator: failed to open %s: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, + "recv_generator: failed to open %s", + full_fname(fname)); } return; } @@ -493,8 +494,8 @@ void recv_generator(char *fname, struct file_struct *file, int i, int f_out) fd = do_open(fnamecmp, O_RDONLY, 0); if (fd == -1) { - rprintf(FERROR, "failed to open %s, continuing: %s\n", - full_fname(fnamecmp), strerror(errno)); + rsyserr(FERROR, errno, "failed to open %s, continuing", + full_fname(fnamecmp)); /* pretend the file didn't exist */ if (preserve_hard_links && hard_link_check(file, HL_SKIP)) return; diff --git a/hlink.c b/hlink.c index 3ee84335..29ddbaf7 100644 --- a/hlink.c +++ b/hlink.c @@ -154,8 +154,8 @@ static void hard_link_one(char *hlink1, char *hlink2) { if (do_link(hlink1, hlink2)) { if (verbose) { - rprintf(FINFO, "link %s => %s failed: %s\n", - hlink2, hlink1, strerror(errno)); + rsyserr(FINFO, errno, "link %s => %s failed", + hlink2, hlink1); } } else if (verbose) @@ -196,10 +196,9 @@ void do_hard_links(void) continue; } else if (robust_unlink(hlink2)) { if (verbose > 0) { - rprintf(FINFO, - "unlink %s failed: %s\n", - full_fname(hlink2), - strerror(errno)); + rsyserr(FINFO, errno, + "unlink %s failed", + full_fname(hlink2)); } continue; } diff --git a/io.c b/io.c index c09a315a..c9691ed1 100644 --- a/io.c +++ b/io.c @@ -1,19 +1,19 @@ /* -*- c-file-style: "linux" -*- - * - * Copyright (C) 1996-2001 by Andrew Tridgell + * + * Copyright (C) 1996-2001 by Andrew Tridgell * Copyright (C) Paul Mackerras 1996 * Copyright (C) 2001, 2002 by Martin Pool - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -137,7 +137,7 @@ static void check_timeout(void) if (last_io && io_timeout && (t-last_io) >= io_timeout) { if (!am_server && !am_daemon) { - rprintf(FERROR,"io timeout after %d seconds - exiting\n", + rprintf(FERROR, "io timeout after %d seconds - exiting\n", (int)(t-last_io)); } exit_cleanup(RERR_TIMEOUT); @@ -334,10 +334,9 @@ static void whine_about_eof(void) if (kludge_around_eof) exit_cleanup(0); else { - rprintf(FERROR, - "%s: connection unexpectedly closed " + rprintf(FERROR, RSYNC_NAME ": connection unexpectedly closed " "(%.0f bytes read so far)\n", - RSYNC_NAME, (double)stats.total_read); + (double)stats.total_read); exit_cleanup(RERR_STREAMIO); } @@ -349,8 +348,7 @@ static void die_from_readerr(int err) /* this prevents us trying to write errors on a dead socket */ io_multiplexing_close(); - rprintf(FERROR, "%s: read error: %s\n", - RSYNC_NAME, strerror(err)); + rsyserr(FERROR, err, "read error"); exit_cleanup(RERR_STREAMIO); } @@ -368,7 +366,7 @@ static void die_from_readerr(int err) */ static int read_timeout(int fd, char *buf, size_t len) { - int n, ret=0; + int n, ret = 0; io_flush(NORMAL_FLUSH); @@ -508,8 +506,8 @@ static int read_timeout(int fd, char *buf, size_t len) whine_about_eof(); return -1; /* doesn't return */ } else if (n < 0) { - if (errno == EINTR || errno == EWOULDBLOCK || - errno == EAGAIN) + if (errno == EINTR || errno == EWOULDBLOCK + || errno == EAGAIN) continue; die_from_readerr(errno); } @@ -587,8 +585,8 @@ static void read_loop(int fd, char *buf, size_t len) /** * Read from the file descriptor handling multiplexing - return number * of bytes read. - * - * Never returns <= 0. + * + * Never returns <= 0. */ static int read_unbuffered(int fd, char *buf, size_t len) { @@ -671,7 +669,7 @@ static int read_unbuffered(int fd, char *buf, size_t len) static void readfd(int fd, char *buffer, size_t N) { int ret; - size_t total=0; + size_t total = 0; while (total < N) { ret = read_unbuffered(fd, buffer + total, N-total); @@ -785,7 +783,7 @@ static void writefd_unbuffered(int fd,char *buf,size_t len) if (msg_fd_in >= 0) { FD_ZERO(&r_fds); FD_SET(msg_fd_in,&r_fds); - if (msg_fd_in > fd_count) + if (msg_fd_in > fd_count) fd_count = msg_fd_in; } @@ -829,15 +827,14 @@ static void writefd_unbuffered(int fd,char *buf,size_t len) /* Don't try to write errors back * across the stream */ io_multiplexing_close(); - rprintf(FERROR, RSYNC_NAME - ": writefd_unbuffered failed to write %ld bytes: phase \"%s\": %s\n", - (long) len, io_write_phase, - strerror(errno)); + rsyserr(FERROR, errno, + "writefd_unbuffered failed to write %ld bytes: phase \"%s\"", + (long) len, io_write_phase); exit_cleanup(RERR_STREAMIO); } sleep_for_bwlimit(ret); - + total += ret; if (io_timeout) @@ -896,7 +893,7 @@ static void mplex_write(int fd, enum msgcode code, char *buf, size_t len) void io_flush(int flush_it_all) { int fd = multiplex_out_fd; - + msg_list_push(flush_it_all); if (!io_buffer_count || no_flush) @@ -1033,7 +1030,7 @@ int read_line(int f, char *buf, size_t maxlen) void io_printf(int fd, const char *format, ...) { - va_list ap; + va_list ap; char buf[1024]; int len; diff --git a/params.c b/params.c index 56a2a914..95981464 100644 --- a/params.c +++ b/params.c @@ -491,8 +491,8 @@ static FILE *OpenConfFile( char *FileName ) OpenedFile = fopen( FileName, "r" ); if( NULL == OpenedFile ) { - rprintf(FERROR,"rsync: unable to open configuration file \"%s\": %s\n", - FileName, strerror(errno)); + rsyserr(FERROR, errno, "rsync: unable to open configuration file \"%s\"", + FileName); } return( OpenedFile ); diff --git a/pipe.c b/pipe.c index 408b2f86..18e9a722 100644 --- a/pipe.c +++ b/pipe.c @@ -52,14 +52,14 @@ pid_t piped_child(char **command, int *f_in, int *f_out) } if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) { - rprintf(FERROR, "pipe: %s\n", strerror(errno)); + rsyserr(FERROR, errno, "pipe"); exit_cleanup(RERR_IPC); } pid = do_fork(); if (pid == -1) { - rprintf(FERROR, "fork: %s\n", strerror(errno)); + rsyserr(FERROR, errno, "fork"); exit_cleanup(RERR_IPC); } @@ -68,8 +68,7 @@ pid_t piped_child(char **command, int *f_in, int *f_out) close(to_child_pipe[1]) < 0 || close(from_child_pipe[0]) < 0 || dup2(from_child_pipe[1], STDOUT_FILENO) < 0) { - rprintf(FERROR, "Failed to dup/close : %s\n", - strerror(errno)); + rsyserr(FERROR, errno, "Failed to dup/close"); exit_cleanup(RERR_IPC); } if (to_child_pipe[0] != STDIN_FILENO) @@ -81,13 +80,12 @@ pid_t piped_child(char **command, int *f_in, int *f_out) if (blocking_io > 0) set_blocking(STDOUT_FILENO); execvp(command[0], command); - rprintf(FERROR, "Failed to exec %s : %s\n", - command[0], strerror(errno)); + rsyserr(FERROR, errno, "Failed to exec %s", command[0]); exit_cleanup(RERR_IPC); } if (close(from_child_pipe[1]) < 0 || close(to_child_pipe[0]) < 0) { - rprintf(FERROR, "Failed to close : %s\n", strerror(errno)); + rsyserr(FERROR, errno, "Failed to close"); exit_cleanup(RERR_IPC); } @@ -106,14 +104,14 @@ pid_t local_child(int argc, char **argv,int *f_in,int *f_out, if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) { - rprintf(FERROR,"pipe: %s\n",strerror(errno)); + rsyserr(FERROR, errno, "pipe"); exit_cleanup(RERR_IPC); } pid = do_fork(); if (pid == -1) { - rprintf(FERROR,"fork: %s\n",strerror(errno)); + rsyserr(FERROR, errno, "fork"); exit_cleanup(RERR_IPC); } @@ -128,7 +126,7 @@ pid_t local_child(int argc, char **argv,int *f_in,int *f_out, close(to_child_pipe[1]) < 0 || close(from_child_pipe[0]) < 0 || dup2(from_child_pipe[1], STDOUT_FILENO) < 0) { - rprintf(FERROR,"Failed to dup/close : %s\n",strerror(errno)); + rsyserr(FERROR, errno, "Failed to dup/close"); exit_cleanup(RERR_IPC); } if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]); @@ -141,7 +139,7 @@ pid_t local_child(int argc, char **argv,int *f_in,int *f_out, if (close(from_child_pipe[1]) < 0 || close(to_child_pipe[0]) < 0) { - rprintf(FERROR,"Failed to close : %s\n",strerror(errno)); + rsyserr(FERROR, errno, "Failed to close"); exit_cleanup(RERR_IPC); } diff --git a/receiver.c b/receiver.c index acc5da85..c7cde828 100644 --- a/receiver.c +++ b/receiver.c @@ -51,16 +51,17 @@ static void delete_one(char *fn, int is_dir) { if (!is_dir) { if (robust_unlink(fn) != 0) { - rprintf(FERROR, "delete_one: unlink %s failed: %s\n", - full_fname(fn), strerror(errno)); + rsyserr(FERROR, errno, "delete_one: unlink %s failed", + full_fname(fn)); } else if (verbose) { rprintf(FINFO, "deleting %s\n", fn); } } else { if (do_rmdir(fn) != 0) { if (errno != ENOTEMPTY && errno != EEXIST) { - rprintf(FERROR, "delete_one: rmdir %s failed: %s\n", - full_fname(fn), strerror(errno)); + rsyserr(FERROR, errno, + "delete_one: rmdir %s failed", + full_fname(fn)); } } else if (verbose) { rprintf(FINFO, "deleting directory %s\n", fn); @@ -223,8 +224,8 @@ static int receive_data(int f_in,struct map_struct *mapbuf,int fd,char *fname, sum_update(data,i); if (fd != -1 && write_file(fd,data,i) != i) { - rprintf(FERROR, "write failed on %s: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "write failed on %s", + full_fname(fname)); exit_cleanup(RERR_FILEIO); } offset += i; @@ -251,8 +252,8 @@ static int receive_data(int f_in,struct map_struct *mapbuf,int fd,char *fname, } if (fd != -1 && write_file(fd,map,len) != (int) len) { - rprintf(FERROR, "write failed on %s: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "write failed on %s", + full_fname(fname)); exit_cleanup(RERR_FILEIO); } offset += len; @@ -264,8 +265,8 @@ static int receive_data(int f_in,struct map_struct *mapbuf,int fd,char *fname, end_progress(total_size); if (fd != -1 && offset > 0 && sparse_end(fd) != 0) { - rprintf(FERROR, "write failed on %s: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "write failed on %s", + full_fname(fname)); exit_cleanup(RERR_FILEIO); } @@ -371,8 +372,8 @@ int recv_files(int f_in,struct file_list *flist,char *local_name) } if (fd1 != -1 && do_fstat(fd1,&st) != 0) { - rprintf(FERROR, "fstat %s failed: %s\n", - full_fname(fnamecmp), strerror(errno)); + rsyserr(FERROR, errno, "fstat %s failed", + full_fname(fnamecmp)); receive_data(f_in,NULL,-1,NULL,file->length); close(fd1); continue; @@ -436,8 +437,8 @@ int recv_files(int f_in,struct file_list *flist,char *local_name) fd2 = do_mkstemp(fnametmp, file->mode & INITACCESSPERMS); } if (fd2 == -1) { - rprintf(FERROR, "mkstemp %s failed: %s\n", - full_fname(fnametmp), strerror(errno)); + rsyserr(FERROR, errno, "mkstemp %s failed", + full_fname(fnametmp)); receive_data(f_in,mapbuf,-1,NULL,file->length); if (mapbuf) unmap_file(mapbuf); if (fd1 != -1) close(fd1); @@ -460,8 +461,8 @@ int recv_files(int f_in,struct file_list *flist,char *local_name) close(fd1); } if (close(fd2) < 0) { - rprintf(FERROR, "close failed on %s: %s\n", - full_fname(fnametmp), strerror(errno)); + rsyserr(FERROR, errno, "close failed on %s", + full_fname(fnametmp)); exit_cleanup(RERR_FILEIO); } diff --git a/rsync.c b/rsync.c index 6c3f8069..7af64e7e 100644 --- a/rsync.c +++ b/rsync.c @@ -68,8 +68,8 @@ int delete_file(char *fname) if (!S_ISDIR(st.st_mode)) { if (robust_unlink(fname) == 0 || errno == ENOENT) return 0; - rprintf(FERROR, "delete_file: unlink %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "delete_file: unlink %s failed", + full_fname(fname)); return -1; } @@ -77,15 +77,15 @@ int delete_file(char *fname) return 0; if (!force_delete || !recurse || (errno != ENOTEMPTY && errno != EEXIST)) { - rprintf(FERROR, "delete_file: rmdir %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "delete_file: rmdir %s failed", + full_fname(fname)); return -1; } /* now we do a recsursive delete on the directory ... */ if (!(d = opendir(fname))) { - rprintf(FERROR, "delete_file: opendir %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "delete_file: opendir %s failed", + full_fname(fname)); return -1; } @@ -103,8 +103,8 @@ int delete_file(char *fname) } } if (errno) { - rprintf(FERROR, "delete_file: readdir %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "delete_file: readdir %s failed", + full_fname(fname)); closedir(d); return -1; } @@ -112,8 +112,8 @@ int delete_file(char *fname) closedir(d); if (do_rmdir(fname) != 0) { - rprintf(FERROR, "delete_file: rmdir %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "delete_file: rmdir %s failed", + full_fname(fname)); return -1; } @@ -131,8 +131,8 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st, if (!st) { if (link_stat(fname,&st2) != 0) { - rprintf(FERROR, "stat %s failed: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "stat %s failed", + full_fname(fname)); return 0; } st = &st2; @@ -146,8 +146,8 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st, * because some filesystems can't do it */ if (set_modtime(fname,file->modtime) != 0 && !S_ISDIR(st->st_mode)) { - rprintf(FERROR, "failed to set times on %s: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "failed to set times on %s", + full_fname(fname)); return 0; } updated = 1; @@ -174,9 +174,9 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st, change_gid ? file->gid : st->st_gid) != 0) { /* shouldn't have attempted to change uid or gid * unless have the privilege */ - rprintf(FERROR, "%s %s failed: %s\n", + rsyserr(FERROR, errno, "%s %s failed", change_uid ? "chown" : "chgrp", - full_fname(fname), strerror(errno)); + full_fname(fname)); return 0; } /* a lchown had been done - we have to re-stat if the @@ -193,8 +193,8 @@ int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st, if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) { updated = 1; if (do_chmod(fname,(file->mode & CHMOD_BITS)) != 0) { - rprintf(FERROR, "failed to set permissions on %s: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, "failed to set permissions on %s", + full_fname(fname)); return 0; } } @@ -239,9 +239,9 @@ void finish_transfer(char *fname, char *fnametmp, struct file_struct *file, /* move tmp file over real file */ ret = robust_rename(fnametmp, fname, file->mode & INITACCESSPERMS); if (ret < 0) { - rprintf(FERROR, "%s %s -> \"%s\": %s\n", + rsyserr(FERROR, errno, "%s %s -> \"%s\"", ret == -2 ? "copy" : "rename", - full_fname(fnametmp), fname, strerror(errno)); + full_fname(fnametmp), fname); do_unlink(fnametmp); } else { set_perms(fname, file, NULL, diff --git a/sender.c b/sender.c index a1cd3f41..d563df1c 100644 --- a/sender.c +++ b/sender.c @@ -201,8 +201,9 @@ void send_files(struct file_list *flist, int f_out, int f_in) full_fname(fname)); } else { io_error |= IOERR_GENERAL; - rprintf(FERROR, "send_files failed to open %s: %s\n", - full_fname(fname), strerror(errno)); + rsyserr(FERROR, errno, + "send_files failed to open %s", + full_fname(fname)); } free_sums(s); continue; @@ -211,7 +212,7 @@ void send_files(struct file_list *flist, int f_out, int f_in) /* map the local file */ if (do_fstat(fd, &st) != 0) { io_error |= IOERR_GENERAL; - rprintf(FERROR, "fstat failed: %s\n", strerror(errno)); + rsyserr(FERROR, errno, "fstat failed"); free_sums(s); close(fd); return; @@ -287,9 +288,9 @@ void send_files(struct file_list *flist, int f_out, int f_in) j = unmap_file(mbuf); if (j) { io_error |= IOERR_GENERAL; - rprintf(FERROR, - "read errors mapping %s: (%d) %s\n", - full_fname(fname), j, strerror(j)); + rsyserr(FERROR, j, + "read errors mapping %s", + full_fname(fname)); } } close(fd); diff --git a/socket.c b/socket.c index 88ef93ec..549d40d4 100644 --- a/socket.c +++ b/socket.c @@ -71,15 +71,13 @@ static int establish_proxy_connection(int fd, char *host, int port, host, port, authhdr, authbuf); len = strlen(buffer); if (write(fd, buffer, len) != len) { - rprintf(FERROR, "failed to write to proxy: %s\n", - strerror(errno)); + rsyserr(FERROR, errno, "failed to write to proxy"); return -1; } for (cp = buffer; cp < &buffer[sizeof buffer - 1]; cp++) { if (read(fd, cp, 1) != 1) { - rprintf(FERROR, "failed to read from proxy: %s\n", - strerror(errno)); + rsyserr(FERROR, errno, "failed to read from proxy"); return -1; } if (*cp == '\n') @@ -108,8 +106,8 @@ static int establish_proxy_connection(int fd, char *host, int port, while (1) { for (cp = buffer; cp < &buffer[sizeof buffer - 1]; cp++) { if (read(fd, cp, 1) != 1) { - rprintf(FERROR, "failed to read from proxy: %s\n", - strerror(errno)); + rsyserr(FERROR, errno, + "failed to read from proxy"); return -1; } if (*cp == '\n') @@ -278,8 +276,7 @@ int open_socket_out(char *host, int port, const char *bind_address, } freeaddrinfo(res0); if (s < 0) { - rprintf(FERROR, RSYNC_NAME ": failed to connect to %s: %s\n", - h, strerror(errno)); + rsyserr(FERROR, errno, "failed to connect to %s", h); return -1; } return s; @@ -450,8 +447,7 @@ void start_accept_loop(int port, int (*fn)(int, int)) FD_ZERO(&deffds); for (i = 0, maxfd = -1; sp[i] >= 0; i++) { if (listen(sp[i], 5) < 0) { - rprintf(FERROR, "listen() on socket failed: %s\n", - strerror(errno)); + rsyserr(FERROR, errno, "listen() on socket failed"); #ifdef INET6 if (errno == EADDRINUSE && i > 0) { rprintf(FINFO, @@ -513,10 +509,8 @@ void start_accept_loop(int port, int (*fn)(int, int)) close_all(); _exit(ret); } else if (pid < 0) { - rprintf(FERROR, - RSYNC_NAME - ": could not create child server process: %s\n", - strerror(errno)); + rsyserr(FERROR, errno, + "could not create child server process"); close(fd); /* This might have happened because we're * overloaded. Sleep briefly before trying to @@ -633,9 +627,10 @@ void set_socket_options(int fd, char *options) break; } - if (ret != 0) - rprintf(FERROR, "failed to set socket option %s: %s\n", tok, - strerror(errno)); + if (ret != 0) { + rsyserr(FERROR, errno, + "failed to set socket option %s", tok); + } } free(options); @@ -765,8 +760,7 @@ int sock_exec(const char *prog) int fd[2]; if (socketpair_tcp(fd) != 0) { - rprintf(FERROR, RSYNC_NAME ": socketpair_tcp failed (%s)\n", - strerror(errno)); + rsyserr(FERROR, errno, "socketpair_tcp failed"); return -1; } if (verbose >= 2) diff --git a/util.c b/util.c index 6fe19fcd..a474c9be 100644 --- a/util.c +++ b/util.c @@ -252,29 +252,25 @@ int copy_file(char *source, char *dest, mode_t mode) ifd = do_open(source, O_RDONLY, 0); if (ifd == -1) { - rprintf(FERROR,"open %s: %s\n", - full_fname(source), strerror(errno)); + rsyserr(FERROR, errno, "open %s", full_fname(source)); return -1; } if (robust_unlink(dest) && errno != ENOENT) { - rprintf(FERROR,"unlink %s: %s\n", - full_fname(dest), strerror(errno)); + rsyserr(FERROR, errno, "unlink %s", full_fname(dest)); return -1; } ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode); if (ofd == -1) { - rprintf(FERROR,"open %s: %s\n", - full_fname(dest), strerror(errno)); + rsyserr(FERROR, errno, "open %s", full_fname(dest)); close(ifd); return -1; } while ((len = safe_read(ifd, buf, sizeof buf)) > 0) { if (full_write(ofd, buf, len) < 0) { - rprintf(FERROR,"write %s: %s\n", - full_fname(dest), strerror(errno)); + rsyserr(FERROR, errno, "write %s", full_fname(dest)); close(ifd); close(ofd); return -1; @@ -282,21 +278,20 @@ int copy_file(char *source, char *dest, mode_t mode) } if (len < 0) { - rprintf(FERROR, "read %s: %s\n", - full_fname(source), strerror(errno)); + rsyserr(FERROR, errno, "read %s", full_fname(source)); close(ifd); close(ofd); return -1; } if (close(ifd) < 0) { - rprintf(FINFO, "close failed on %s: %s\n", - full_fname(source), strerror(errno)); + rsyserr(FINFO, errno, "close failed on %s", + full_fname(source)); } if (close(ofd) < 0) { - rprintf(FERROR, "close failed on %s: %s\n", - full_fname(dest), strerror(errno)); + rsyserr(FERROR, errno, "close failed on %s", + full_fname(dest)); return -1; } -- 2.34.1