From bf9ccf5c489e920077c8956ae8b75f11caf75f41 Mon Sep 17 00:00:00 2001 From: Nate Straz Date: Fri, 17 Mar 2006 17:08:30 +0000 Subject: rsync puts the hostname before the -l 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. --- qarsh.c | 23 +++++++++++++++++++---- 1 file 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); -- cgit