MCPcopy Index your code
hub / github.com/RsyncProject/rsync / do_cmd

Function do_cmd

main.c:513–672  ·  view source on GitHub ↗

Start the remote shell. cmd may be NULL to use the default. */

Source from the content-addressed store, hash-verified

511
512/* Start the remote shell. cmd may be NULL to use the default. */
513static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, int remote_argc,
514 int *f_in_p, int *f_out_p)
515{
516 int i, argc = 0;
517 char *args[MAX_ARGS], *need_to_free = NULL;
518 pid_t pid;
519 int dash_l_set = 0;
520
521 if (!read_batch && !local_server) {
522 char *t, *f, in_quote = '\0';
523 char *rsh_env = getenv(RSYNC_RSH_ENV);
524 if (!cmd)
525 cmd = rsh_env;
526 if (!cmd)
527 cmd = RSYNC_RSH;
528 cmd = need_to_free = strdup(cmd);
529
530 for (t = f = cmd; *f; f++) {
531 if (*f == ' ')
532 continue;
533 /* Comparison leaves rooms for server_options(). */
534 if (argc >= MAX_ARGS - MAX_SERVER_ARGS)
535 goto arg_overflow;
536 args[argc++] = t;
537 while (*f != ' ' || in_quote) {
538 if (!*f) {
539 if (in_quote) {
540 rprintf(FERROR,
541 "Missing trailing-%c in remote-shell command.\n",
542 in_quote);
543 exit_cleanup(RERR_SYNTAX);
544 }
545 f--;
546 break;
547 }
548 if (*f == '\'' || *f == '"') {
549 if (!in_quote) {
550 in_quote = *f++;
551 continue;
552 }
553 if (*f == in_quote && *++f != in_quote) {
554 in_quote = '\0';
555 continue;
556 }
557 }
558 *t++ = *f++;
559 }
560 *t++ = '\0';
561 }
562
563 /* NOTE: must preserve t == start of command name until the end of the args handling! */
564 if ((t = strrchr(cmd, '/')) != NULL)
565 t++;
566 else
567 t = cmd;
568
569 /* Check to see if we've already been given '-l user' in the remote-shell command. */
570 for (i = 0; i < argc-1; i++) {

Callers 1

start_clientFunction · 0.85

Calls 10

server_optionsFunction · 0.85
safe_argFunction · 0.85
set_allow_inc_recurseFunction · 0.85
fd_pairFunction · 0.85
setup_iconvFunction · 0.85
local_childFunction · 0.85
piped_childFunction · 0.85
send_protected_argsFunction · 0.85
rprintfFunction · 0.70
rsyserrFunction · 0.70

Tested by

no test coverage detected