Skip to content

Commit

Permalink
Change daemon variable & simplify some option code
Browse files Browse the repository at this point in the history
- Rename daemon_over_rsh -> daemon_connection since it is also used to
  indicate if a non-rsh daemon connection is active.
- Move the daemon-over-rsh exception out of server_options() to the one
  caller that needs that behavior.
- Don't allow noop_io_until_death() to be short-circuited when talking
  to a daemon over a socket, because it can't send errors via stderr.
  • Loading branch information
WayneD committed Jul 25, 2020
1 parent a5a9f26 commit f9bb8f7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
5 changes: 0 additions & 5 deletions clientserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ extern int protect_args;
extern int ignore_errors;
extern int preserve_xattrs;
extern int kluge_around_eof;
extern int daemon_over_rsh;
extern int munge_symlinks;
extern int open_noatime;
extern int sanitize_paths;
Expand Down Expand Up @@ -282,10 +281,6 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
fclose(f);
}

/* set daemon_over_rsh to false since we need to build the
* true set of args passed through the rsh/ssh connection;
* this is a no-op for direct-socket-connection mode */
daemon_over_rsh = 0;
server_options(sargs, &sargc);

if (sargc >= MAX_ARGS - 2)
Expand Down
7 changes: 6 additions & 1 deletion io.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern int read_batch;
extern int compat_flags;
extern int protect_args;
extern int checksum_seed;
extern int daemon_connection;
extern int protocol_version;
extern int remove_source_files;
extern int preserve_hard_links;
Expand Down Expand Up @@ -917,7 +918,11 @@ void noop_io_until_death(void)
{
char buf[1024];

if (!iobuf.in.buf || !iobuf.out.buf || iobuf.in_fd < 0 || iobuf.out_fd < 0 || kluge_around_eof || msgs2stderr)
if (!iobuf.in.buf || !iobuf.out.buf || iobuf.in_fd < 0 || iobuf.out_fd < 0 || kluge_around_eof)
return;

/* If we're talking to a daemon over a socket, don't short-circuit this logic */
if (msgs2stderr && daemon_connection >= 0)
return;

kluge_around_eof = 2;
Expand Down
28 changes: 16 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ gid_t our_gid;
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;
int daemon_connection = 0; /* 0 = no daemon, 1 = daemon via remote shell, -1 = daemon via socket */
mode_t orig_umask = 0;
int batch_gen_fd = -1;
int sender_keeps_checksum = 0;
Expand Down Expand Up @@ -566,12 +566,12 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
#ifdef HAVE_REMSH
/* remsh (on HPUX) takes the arguments the other way around */
args[argc++] = machine;
if (user && !(daemon_over_rsh && dash_l_set)) {
if (user && !(daemon_connection && dash_l_set)) {
args[argc++] = "-l";
args[argc++] = user;
}
#else
if (user && !(daemon_over_rsh && dash_l_set)) {
if (user && !(daemon_connection && dash_l_set)) {
args[argc++] = "-l";
args[argc++] = user;
}
Expand All @@ -591,15 +591,19 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
if (blocking_io < 0 && (strcmp(t, "rsh") == 0 || strcmp(t, "remsh") == 0))
blocking_io = 1;

server_options(args, &argc);
if (daemon_connection > 0) {
args[argc++] = "--server";
args[argc++] = "--daemon";
} else
server_options(args, &argc);

if (argc >= MAX_ARGS - 2)
goto arg_overflow;
}

args[argc++] = ".";

if (!daemon_over_rsh) {
if (!daemon_connection) {
while (remote_argc > 0) {
if (argc >= MAX_ARGS - 1) {
arg_overflow:
Expand Down Expand Up @@ -652,7 +656,7 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
#ifdef ICONV_CONST
setup_iconv();
#endif
if (protect_args && !daemon_over_rsh)
if (protect_args && !daemon_connection)
send_protected_args(*f_out_p, args);
}

Expand Down Expand Up @@ -1407,7 +1411,7 @@ static int start_client(int argc, char *argv[])
}
am_sender = 0;
if (rsync_port)
daemon_over_rsh = shell_cmd ? 1 : -1;
daemon_connection = shell_cmd ? 1 : -1;
} else { /* source is local, check dest arg */
am_sender = 1;

Expand Down Expand Up @@ -1439,7 +1443,7 @@ static int start_client(int argc, char *argv[])
} else { /* hostspec was found, so dest is remote */
argv[argc] = path;
if (rsync_port)
daemon_over_rsh = shell_cmd ? 1 : -1;
daemon_connection = shell_cmd ? 1 : -1;
}
}
} else { /* read_batch */
Expand Down Expand Up @@ -1502,10 +1506,10 @@ static int start_client(int argc, char *argv[])
else
env_port = rsync_port;

if (daemon_over_rsh < 0)
if (daemon_connection < 0)
return start_socket_client(shell_machine, remote_argc, remote_argv, argc, argv);

if (password_file && !daemon_over_rsh) {
if (password_file && !daemon_connection) {
rprintf(FERROR, "The --password-file option may only be "
"used when accessing an rsync daemon.\n");
exit_cleanup(RERR_SYNTAX);
Expand Down Expand Up @@ -1533,15 +1537,15 @@ static int start_client(int argc, char *argv[])
}

#ifdef HAVE_PUTENV
if (daemon_over_rsh)
if (daemon_connection)
set_env_num("RSYNC_PORT", env_port);
#endif

pid = do_cmd(shell_cmd, shell_machine, shell_user, remote_argv, remote_argc, &f_in, &f_out);

/* if we're running an rsync server on the remote host over a
* remote shell command, we need to do the RSYNCD protocol first */
if (daemon_over_rsh) {
if (daemon_connection) {
int tmpret;
tmpret = start_inband_exchange(f_in, f_out, shell_user, remote_argc, remote_argv);
if (tmpret < 0)
Expand Down
8 changes: 0 additions & 8 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
extern int module_id;
extern int local_server;
extern int sanitize_paths;
extern int daemon_over_rsh;
extern unsigned int module_dirlen;
extern struct name_num_obj valid_checksums;
extern struct name_num_obj valid_compressions;
Expand Down Expand Up @@ -2683,13 +2682,6 @@ void server_options(char **args, int *argc_p)
/* This should always remain first on the server's command-line. */
args[ac++] = "--server";

if (daemon_over_rsh > 0) {
args[ac++] = "--daemon";
*argc_p = ac;
/* if we're passing --daemon, we're done */
return;
}

if (!am_sender)
args[ac++] = "--sender";

Expand Down

0 comments on commit f9bb8f7

Please sign in to comment.