extern int filesfrom_fd;
extern int connect_timeout;
extern int send_msgs_to_gen;
+extern dev_t filesystem_dev;
extern pid_t cleanup_child_pid;
extern size_t bwlimit_writemax;
extern unsigned int module_dirlen;
+extern BOOL flist_receiving_enabled;
extern BOOL shutting_down;
+extern int basis_dir_cnt;
extern struct stats stats;
extern char *stdout_format;
extern char *logfile_format;
uid_t our_uid;
gid_t our_gid;
-int am_generator = 0;
+int am_receiver = 0; /* Only set to 1 after the receiver/generator fork. */
+int am_generator = 0; /* Only set to 1 after the receiver/generator fork. */
int local_server = 0;
int daemon_over_rsh = 0;
mode_t orig_umask = 0;
pid_t wait_process(pid_t pid, int *status_ptr, int flags)
{
pid_t waited_pid;
-
+
do {
waited_pid = waitpid(pid, status_ptr, flags);
} while (waited_pid == -1 && errno == EINTR);
rprintf(FCLIENT, "\n");
rprintf(FINFO, RSYNC_NAME "[%d] (%s%s%s) heap statistics:\n",
- getpid(), am_server ? "server " : "",
+ (int)getpid(), am_server ? "server " : "",
am_daemon ? "daemon " : "", who_am_i());
rprintf(FINFO, " arena: %10ld (bytes from sbrk)\n",
(long)mi.arena);
int *f_in_p, int *f_out_p)
{
int i, argc = 0;
- char *args[MAX_ARGS];
+ char *args[MAX_ARGS], *need_to_free = NULL;
pid_t pid;
int dash_l_set = 0;
cmd = rsh_env;
if (!cmd)
cmd = RSYNC_RSH;
- cmd = strdup(cmd); /*MEMORY LEAK*/
+ cmd = need_to_free = strdup(cmd);
if (!cmd)
goto oom;
rprintf(FERROR, "internal: args[] overflowed in do_cmd()\n");
exit_cleanup(RERR_SYNTAX);
}
- args[argc++] = *remote_argv++;
+ if (**remote_argv == '-') {
+ if (asprintf(args + argc++, "./%s", *remote_argv++) < 0)
+ out_of_memory("do_cmd");
+ } else
+ args[argc++] = *remote_argv++;
remote_argc--;
}
}
send_protected_args(*f_out_p, args);
}
+ if (need_to_free)
+ free(need_to_free);
+
return pid;
oom:
if (!dest_path || list_only)
return NULL;
+ /* Treat an empty string as a copy into the current directory. */
+ if (!*dest_path)
+ dest_path = ".";
+
if (daemon_filter_list.head) {
char *slash = strrchr(dest_path, '/');
if (slash && (slash[1] == '\0' || (slash[1] == '.' && slash[2] == '\0')))
if ((*dest_path != '.' || dest_path[1] != '\0')
&& (check_filter(&daemon_filter_list, FLOG, dest_path, 0) < 0
|| check_filter(&daemon_filter_list, FLOG, dest_path, 1) < 0)) {
- rprintf(FERROR, "skipping daemon-excluded destination \"%s\"\n",
+ rprintf(FERROR, "ERROR: daemon has excluded destination \"%s\"\n",
dest_path);
exit_cleanup(RERR_FILESELECT);
}
full_fname(dest_path));
exit_cleanup(RERR_FILESELECT);
}
+ filesystem_dev = st.st_dev; /* ensures --force works right w/-x */
return NULL;
}
if (file_total > 1) {
exit_cleanup(RERR_SYNTAX);
}
- if (mkdir_defmode(dest_path) != 0) {
+ if (do_mkdir(dest_path, ACCESSPERMS) != 0) {
rsyserr(FERROR, errno, "mkdir %s failed",
full_fname(dest_path));
exit_cleanup(RERR_FILEIO);
static void check_alt_basis_dirs(void)
{
STRUCT_STAT st;
- char **dir_p, *slash = strrchr(curr_dir, '/');
-
- for (dir_p = basis_dir; *dir_p; dir_p++) {
- if (dry_run > 1 && **dir_p != '/') {
- int len = curr_dir_len + 1 + strlen(*dir_p) + 1;
+ char *slash = strrchr(curr_dir, '/');
+ int j;
+
+ for (j = 0; j < basis_dir_cnt; j++) {
+ char *bdir = basis_dir[j];
+ int bd_len = strlen(bdir);
+ if (bd_len > 1 && bdir[bd_len-1] == '/')
+ bdir[--bd_len] = '\0';
+ if (dry_run > 1 && *bdir != '/') {
+ int len = curr_dir_len + 1 + bd_len + 1;
char *new = new_array(char, len);
if (!new)
out_of_memory("check_alt_basis_dirs");
- if (slash && strncmp(*dir_p, "../", 3) == 0) {
+ if (slash && strncmp(bdir, "../", 3) == 0) {
/* We want to remove only one leading "../" prefix for
* the directory we couldn't create in dry-run mode:
* this ensures that any other ".." references get
* evaluated the same as they would for a live copy. */
*slash = '\0';
- pathjoin(new, len, curr_dir, *dir_p + 3);
+ pathjoin(new, len, curr_dir, bdir + 3);
*slash = '/';
} else
- pathjoin(new, len, curr_dir, *dir_p);
- *dir_p = new;
- }
- if (do_stat(*dir_p, &st) < 0) {
- rprintf(FWARNING, "%s arg does not exist: %s\n",
- dest_option, *dir_p);
- } else if (!S_ISDIR(st.st_mode)) {
- rprintf(FWARNING, "%s arg is not a dir: %s\n",
- dest_option, *dir_p);
+ pathjoin(new, len, curr_dir, bdir);
+ basis_dir[j] = bdir = new;
}
+ if (do_stat(bdir, &st) < 0)
+ rprintf(FWARNING, "%s arg does not exist: %s\n", dest_option, bdir);
+ else if (!S_ISDIR(st.st_mode))
+ rprintf(FWARNING, "%s arg is not a dir: %s\n", dest_option, bdir);
}
}
struct file_list *flist;
char *dir = argv[0];
- if (DEBUG_GTE(SEND, 1)) {
- rprintf(FINFO, "server_sender starting pid=%ld\n",
- (long)getpid());
- }
+ if (DEBUG_GTE(SEND, 1))
+ rprintf(FINFO, "server_sender starting pid=%d\n", (int)getpid());
if (am_daemon && lp_write_only(module_id)) {
rprintf(FERROR, "ERROR: module is write only\n");
}
flist = send_file_list(f_out,argc,argv);
- if (!flist || flist->used == 0)
+ if (!flist || flist->used == 0) {
+ /* Make sure input buffering is off so we can't hang in noop_io_until_death(). */
+ io_end_buffering_in(0);
+ /* TODO: we should really exit in a more controlled manner. */
exit_cleanup(0);
+ }
io_start_buffering_in(f_in);
}
if (pid == 0) {
+ am_receiver = 1;
send_msgs_to_gen = am_server;
close(error_pipe[0]);
}
am_generator = 1;
+ flist_receiving_enabled = True;
io_end_multiplex_in(MPLX_SWITCHING);
if (write_batch && !am_server)
} else
negated_levels = 0;
- if (DEBUG_GTE(RECV, 1)) {
- rprintf(FINFO, "server_recv(%d) starting pid=%ld\n",
- argc, (long)getpid());
- }
+ if (DEBUG_GTE(RECV, 1))
+ rprintf(FINFO, "server_recv(%d) starting pid=%d\n", argc, (int)getpid());
if (am_daemon && read_only) {
rprintf(FERROR,"ERROR: module is read only\n");
remote_argc = argc = 1;
}
+ if (!rsync_port && remote_argc && !**remote_argv) /* Turn an empty arg into a dot dir. */
+ *remote_argv = ".";
+
if (am_sender) {
char *dummy_host;
int dummy_port = rsync_port;
rprintf(FERROR, "All source args must use the same port number.\n");
exit_cleanup(RERR_SYNTAX);
}
+ if (!rsync_port && !*arg) /* Turn an empty arg into a dot dir. */
+ arg = ".";
remote_argv[i] = arg;
}
}
if (DEBUG_GTE(CMD, 2)) {
rprintf(FINFO,"cmd=%s machine=%s user=%s path=%s\n",
NS(shell_cmd), NS(shell_machine), NS(shell_user),
- remote_argv ? NS(remote_argv[0]) : "");
+ NS(remote_argv[0]));
}
pid = do_cmd(shell_cmd, shell_machine, shell_user, remote_argv, remote_argc,
static RETSIGTYPE rsync_panic_handler(UNUSED(int whatsig))
{
char cmd_buf[300];
- int ret;
+ int ret, pid_int = getpid();
- snprintf(cmd_buf, sizeof cmd_buf, get_panic_action(),
- getpid(), getpid());
+ snprintf(cmd_buf, sizeof cmd_buf, get_panic_action(), pid_int, pid_int);
/* Unless we failed to execute gdb, we allow the process to
* continue. I'm not sure if that's right. */
exit_cleanup(RERR_SYNTAX);
}
- /* we set a 0 umask so that correct file permissions can be
- * carried across */
- orig_umask = umask(0);
+ /* Get the umask for use in permission calculations. We no longer set
+ * it to zero; that is ugly and pointless now that all the callers that
+ * relied on it have been reeducated to work with default ACLs. */
+ umask(orig_umask = umask(0));
#if defined CONFIG_LOCALE && defined HAVE_SETLOCALE
setlocale(LC_CTYPE, "");