From: Chris Turner Date: Wed, 12 Sep 2012 13:11:31 +0000 (+0000) Subject: hammer(8): add HAMMER_RSH environment variable support. X-Git-Tag: v3.2.0~167 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/e2c596b1a494dc77d2e42a43f4bd5ad414d20320 hammer(8): add HAMMER_RSH environment variable support. Add support for a HAMMER_RSH environment variable which can be used to select an alternate remote shell to be used for hammer remote operations, change remote shell invocation to rsh(1) style '-l user host' instead of ssh-style user@host to permit usage of rsh(1) as an alternate HAMMER_RSH without the need for a wrapper script. Also change exec call of subshell to use execvp instead of a hardcoded path to facillitate this change. Update hammer.8 docs, along with minor formatting fix to environment variable summary header sentence. --- diff --git a/sbin/hammer/cmd_mirror.c b/sbin/hammer/cmd_mirror.c index 918c528ce6..a3039be78a 100644 --- a/sbin/hammer/cmd_mirror.c +++ b/sbin/hammer/cmd_mirror.c @@ -1053,7 +1053,7 @@ hammer_cmd_mirror_copy(char **av, int ac, int streaming) int fds[2]; const char *xav[32]; char tbuf[16]; - char *ptr; + char *sh, *user, *host, *rfs; int xac; if (ac != 2) @@ -1077,17 +1077,38 @@ again: dup2(fds[0], 1); close(fds[0]); close(fds[1]); - if ((ptr = strchr(av[0], ':')) != NULL) { - *ptr++ = 0; + if ((rfs = strchr(av[0], ':')) != NULL) { xac = 0; - xav[xac++] = "ssh"; + + if((sh = getenv("HAMMER_RSH")) == NULL) + xav[xac++] = "ssh"; + else + xav[xac++] = sh; + if (CompressOpt) xav[xac++] = "-C"; + + user = strndup(av[0], (rfs - av[0])); + + if ((host = strchr(av[0], '@')) != NULL) { + user = strndup( av[0], (host++ - av[0])); + host = strndup( host, (rfs++ - host)); + xav[xac++] = "-l"; + xav[xac++] = user; + xav[xac++] = host; + } + else { + host = strndup( av[0], (rfs++ - av[0])); + user = NULL; + xav[xac++] = host; + } + + if (SshPort) { xav[xac++] = "-p"; xav[xac++] = SshPort; } - xav[xac++] = av[0]; + xav[xac++] = "hammer"; switch(VerboseOpt) { @@ -1120,9 +1141,9 @@ again: xav[xac++] = "mirror-read-stream"; else xav[xac++] = "mirror-read"; - xav[xac++] = ptr; + xav[xac++] = rfs; xav[xac++] = NULL; - execv("/usr/bin/ssh", (void *)xav); + execvp(*xav, (void *)xav); } else { hammer_cmd_mirror_read(av, 1, streaming); fflush(stdout); @@ -1140,17 +1161,37 @@ again: dup2(fds[1], 1); close(fds[0]); close(fds[1]); - if ((ptr = strchr(av[1], ':')) != NULL) { - *ptr++ = 0; + if ((rfs = strchr(av[1], ':')) != NULL) { xac = 0; - xav[xac++] = "ssh"; + + if((sh = getenv("HAMMER_RSH")) == NULL) + xav[xac++] = "ssh"; + else + xav[xac++] = sh; + if (CompressOpt) xav[xac++] = "-C"; + + user = strndup(av[1], (rfs - av[1])); + + if ((host = strchr(av[1], '@')) != NULL) { + user = strndup( av[1], (host++ - av[1])); + host = strndup( host, (rfs++ - host)); + xav[xac++] = "-l"; + xav[xac++] = user; + xav[xac++] = host; + } + else { + host = strndup( av[1], (rfs++ - av[1])); + user = NULL; + xav[xac++] = host; + } + if (SshPort) { xav[xac++] = "-p"; xav[xac++] = SshPort; } - xav[xac++] = av[1]; + xav[xac++] = "hammer"; switch(VerboseOpt) { @@ -1171,9 +1212,9 @@ again: } xav[xac++] = "-2"; xav[xac++] = "mirror-write"; - xav[xac++] = ptr; + xav[xac++] = rfs; xav[xac++] = NULL; - execv("/usr/bin/ssh", (void *)xav); + execvp(*xav, (void *)xav); } else { hammer_cmd_mirror_write(av + 1, 1); fflush(stdout); diff --git a/sbin/hammer/hammer.8 b/sbin/hammer/hammer.8 index 7c276b9da5..00c884fa8f 100644 --- a/sbin/hammer/hammer.8 +++ b/sbin/hammer/hammer.8 @@ -1360,7 +1360,9 @@ command to a command. If a remote host specification is made the program forks a .Xr ssh 1 -and execs the +(or other program as specified by the +.Ev HAMMER_RSH +environment variable) and execs the .Cm mirror-read and/or .Cm mirror-write @@ -1800,18 +1802,31 @@ important directories/files can be .Nm null mounted to the new PFS. .Sh ENVIRONMENT -If the following environment variables exist, they will be used by: +The following environment variables affect the execution of +.Nm : .Bl -tag -width ".Ev EDITOR" .It Ev EDITOR The editor program specified in the variable .Ev EDITOR will be invoked instead of the default editor, which is .Xr vi 1 . +.It Ev HAMMER_RSH +The command specified in the variable +.Ev HAMMER_RSH +will be used to initiate remote operations for the mirror-copy and +mirror-stream commands instead of the default command, which is +.Xr ssh 1 . +The program will be invoked via +.Xr execvp 3 +using a typical +.Xr rsh 1 +style +.Cm -l user host +command line. .It Ev VISUAL Same effect as .Ev EDITOR variable. -.El .Sh FILES .Bl -tag -width ".It Pa /var/slaves/" -compact .It Pa /snapshots