More scp changes
Wayne Davison
wayne at blorf.net
Sat May 19 22:22:59 EST 2001
If you've applied my previous scp patch with the tempfile options and
the erase option, here's a diff that tweaks it a bit more.
Previously I had decided to use getcwd() in a certain local-to-local
special case (that needs to use scp rather than regular cp). This was
because spawing scp via ssh resets the current directory. This patch
choose to forego that in favor of a simpler approach: we just spawn scp
directly in this special local-to-local case.
..wayne..
-------------- next part --------------
Index: scp.c
--- old/scp.c Sat May 19 02:44:51 2001
+++ ./scp.c Sat May 19 02:49:29 2001
@@ -134,7 +134,8 @@
/*
* This function executes the given command as the specified user on the
- * given host. This returns < 0 if execution fails, and >= 0 otherwise. This
+ * given host. If host is NULL, execute the command locally without using
+ * ssh. This returns < 0 if execution fails, and >= 0 otherwise. This
* assigns the input and output file descriptors on success.
*/
@@ -143,10 +144,14 @@
{
int pin[2], pout[2], reserved[2];
- if (verbose_mode)
- fprintf(stderr, "Executing: program %s host %s, user %s, command %s\n",
- ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
-
+ if (verbose_mode) {
+ if (host) {
+ fprintf(stderr, "Executing: program %s host %s, user %s, command %s\n",
+ ssh_program, host, remuser ? remuser : "(unspecified)", cmd);
+ }
+ else
+ fprintf(stderr, "Executing: command %s\n", cmd);
+ }
/*
* Reserve two descriptors so that the real pipes won't get
* descriptors 0 and 1 because that will screw up dup2 below.
@@ -173,15 +178,24 @@
close(pin[0]);
close(pout[1]);
- args.list[0] = ssh_program;
- if (remuser != NULL)
- addargs(&args, "-l%s", remuser);
- addargs(&args, "%s", host);
- addargs(&args, "%s", cmd);
-
- execvp(ssh_program, args.list);
- perror(ssh_program);
- exit(1);
+ if (host) {
+ args.list[0] = ssh_program;
+ if (remuser != NULL)
+ addargs(&args, "-l%s", remuser);
+ addargs(&args, "%s", host);
+ addargs(&args, "%s", cmd);
+ }
+ else {
+ char *arg = strtok(cmd, " \t");
+ args.list = NULL;
+ do {
+ addargs(&args, "%s", arg);
+ } while ((arg = strtok(NULL, " \t")) != NULL);
+ }
+
+ execvp(args.list[0], args.list);
+ perror(args.list[0]);
+ _exit(1);
}
/* Parent. Close the other side, and return the local side. */
close(pin[0]);
@@ -439,8 +453,8 @@
int argc;
char *argv[];
{
- int i, len, cwd_len = 0;
- char *bp, *host, *src, *suser, cwd[MAXPATHLEN];
+ int i, len;
+ char *bp, *host, *src, *suser;
for (i = 0; i < argc - 1; i++) {
src = colon(argv[i]);
@@ -478,21 +492,7 @@
}
else {
src = argv[i];
- if (*src != '/') {
- if (!cwd_len) {
- if (!getcwd(cwd, sizeof cwd)) {
- error("Couldn't get local cwd: %s",
- strerror(errno));
- break;
- }
- cwd_len = strlen(cwd);
- }
- len = cwd_len + strlen(src) + 2;
- src = xmalloc(len);
- snprintf(src, len, "%s/%s", cwd, argv[i]);
- }
- host = "localhost";
- suser = NULL;
+ host = suser = NULL;
}
len = strlen(src) + cmdlen + 20;
bp = xmalloc(len);
More information about the openssh-unix-dev
mailing list