summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate Straz <nstraz@redhat.com>2006-03-17 17:08:30 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:46 -0400
commitbf9ccf5c489e920077c8956ae8b75f11caf75f41 (patch)
tree58343fa155e0617d37005fd45fbd35f1ef456928
parent6900e561ff2b0f63ab3b59498d403a80865c1ac6 (diff)
downloadqarsh-bf9ccf5c489e920077c8956ae8b75f11caf75f41.zip
qarsh-bf9ccf5c489e920077c8956ae8b75f11caf75f41.tar.gz
qarsh-bf9ccf5c489e920077c8956ae8b75f11caf75f41.tar.xz
rsync puts the hostname before the -l <user> arg so we need to act more like
OpenSSH. After they get to the end of the args and they haven't gotten a host name yet they chew the next arg as the hostname and restart parsing the command line. Now we do too.
-rw-r--r--qarsh.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/qarsh.c b/qarsh.c
index f6ce18e..0633023 100644
--- a/qarsh.c
+++ b/qarsh.c
@@ -356,7 +356,7 @@ main(int argc, char *argv[])
{
int c;
int port = 5008;
- char *host;
+ char *host = NULL;
char *remuser = NULL;
char *remgroup = NULL;
char *args;
@@ -373,6 +373,7 @@ main(int argc, char *argv[])
max_timeout = atoi(cp);
}
+again:
while ((c = getopt(argc, argv, "+p:l:g:t:")) != -1) {
switch (c) {
case 'l':
@@ -393,8 +394,24 @@ main(int argc, char *argv[])
usage(argv[0]);
exit(1);
} }
+ /* Some programs (rsync) put the hostname before some qarsh options
+ * We need to pull the hostname out and if there are still args
+ * keep trying to parse them. (code from OpenSSH)
+ */
+ argc -= optind;
+ argv += optind;
- if ((host = argv[optind++]) == NULL) {
+ if (argc > 0 && !host && **argv != '-') {
+ host = *argv;
+ if (argc > 1) {
+ optind = 1;
+ goto again;
+ }
+ argc--;
+ argv++;
+ }
+
+ if (!host) {
usage(argv[0]);
exit(1);
}
@@ -421,8 +438,6 @@ main(int argc, char *argv[])
remuser = strdup(pw->pw_name);
}
- argc -= optind;
- argv += optind;
if ((args = copyargs(argv)) == NULL) {
usage(argv[0]);
exit(1);