summaryrefslogtreecommitdiffhomepage
path: root/scp.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-04-08 01:50:52 -0400
committerMike Frysinger <vapier@gentoo.org>2012-04-08 01:50:52 -0400
commitc957edbe759ba8d708a882dcb9ab3b2aa1a72ad1 (patch)
tree36beaf972edc2571688c80a213848939aadc2f06 /scp.c
parent33ae2be52e57d407df5cdfd836f66a8210a54e5b (diff)
check for fork() and not __uClinux__
Diffstat (limited to 'scp.c')
-rw-r--r--scp.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/scp.c b/scp.c
index 961165a..6911ca2 100644
--- a/scp.c
+++ b/scp.c
@@ -130,22 +130,22 @@ do_local_cmd(arglist *a)
fprintf(stderr, " %s", a->list[i]);
fprintf(stderr, "\n");
}
-#ifdef __uClinux__
+#ifndef HAVE_FORK
pid = vfork();
#else
pid = fork();
-#endif /* __uClinux__ */
+#endif
if (pid == -1)
fatal("do_local_cmd: fork: %s", strerror(errno));
if (pid == 0) {
execvp(a->list[0], a->list);
perror(a->list[0]);
-#ifdef __uClinux__
+#ifndef HAVE_FORK
_exit(1);
#else
exit(1);
-#endif /* __uClinux__ */
+#endif
}
do_cmd_pid = pid;
@@ -171,6 +171,16 @@ do_local_cmd(arglist *a)
* assigns the input and output file descriptors on success.
*/
+static void
+arg_setup(char *host, char *remuser, char *cmd)
+{
+ replacearg(&args, 0, "%s", ssh_program);
+ if (remuser != NULL)
+ addargs(&args, "-l%s", remuser);
+ addargs(&args, "%s", host);
+ addargs(&args, "%s", cmd);
+}
+
int
do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
{
@@ -198,22 +208,18 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
close(reserved[0]);
close(reserved[1]);
- /* uClinux needs to build the args here before vforking,
- otherwise we do it later on. */
-#ifdef __uClinux__
- replacearg(&args, 0, "%s", ssh_program);
- if (remuser != NULL)
- addargs(&args, "-l%s", remuser);
- addargs(&args, "%s", host);
- addargs(&args, "%s", cmd);
-#endif /* __uClinux__ */
+ /* uClinux needs to build the args here before vforking,
+ otherwise we do it later on. */
+#ifndef HAVE_FORK
+ arg_setup(host, remuser, cmd);
+#endif
/* Fork a child to execute the command on the remote host using ssh. */
-#ifdef __uClinux__
+#ifndef HAVE_FORK
do_cmd_pid = vfork();
#else
do_cmd_pid = fork();
-#endif /* __uClinux__ */
+#endif
if (do_cmd_pid == 0) {
/* Child. */
@@ -224,27 +230,22 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
close(pin[0]);
close(pout[1]);
-#ifndef __uClinux__
- replacearg(&args, 0, "%s", ssh_program);
- if (remuser != NULL)
- addargs(&args, "-l%s", remuser);
- addargs(&args, "%s", host);
- addargs(&args, "%s", cmd);
-#endif /* __uClinux__ */
+#ifndef HAVE_FORK
+ arg_setup(host, remuser, cmd);
+#endif
execvp(ssh_program, args.list);
perror(ssh_program);
-#ifndef __uClinux__
- exit(1);
-#else
+#ifndef HAVE_FORK
_exit(1);
-#endif /* __uClinux__ */
+#else
+ exit(1);
+#endif
} else if (do_cmd_pid == -1) {
fatal("fork: %s", strerror(errno));
}
-
-#ifdef __uClinux__
+#ifndef HAVE_FORK
/* clean up command */
/* pop cmd */
xfree(args.list[args.num-1]);
@@ -260,7 +261,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
args.list[args.num-1]=NULL;
args.num--;
}
-#endif /* __uClinux__ */
+#endif
/* Parent. Close the other side, and return the local side. */
close(pin[0]);