If, e.g., "host" is down, "rdate -s host" will fail but still return 0. I have made a patch for this which is available at the URL given with this report. When there are several hosts on the command line, I have considered that successfully setting the clock with at least one is enough. (Setting it with each host would just write over the previous setting each time.) Essentially, I interpret rdate -s host1 host2 ... as "try each host until one succeeds". I have not explored in as many details what "rdate -p" should return when several hosts are given on the command line, nor have I explored the possibility of having a list of exit codes, each with its own precise meaning. Also, to be more consistent with what the GNU standards specify, "rdate -h" should write to stdout, whereas "rdate -bad-usage" should write to stderr.
I can't duplicate this. Can you send more info, and the patch?
Try something like rdate no_such_host. down_host.; echo $? and it will exit with 0, which is not very helpful in scripts. This is with rdate-1.0-1.i386.rpm.
--- rdate.c.orig-1.0 Fri Feb 4 14:07:08 2000 +++ rdate.c Wed Jul 12 03:48:52 2000 @@ -107,7 +107,9 @@ static void usage(int iserr) { - fprintf(stderr, "Usage: %s [-s] [-p] <host> ...\n", program_invocation_short_name); + fprintf(iserr ? stderr : stdout, + "Usage: %s [-s] [-p] <host> ...\n", + program_invocation_short_name); exit(iserr?1:0); } @@ -117,7 +119,7 @@ int print_mode = 0, set_mode = 0; char **hosts = NULL; int nhosts = 0; - int retval = 0; + int retval = 1; for(i = 1; i < argc; i++) { @@ -148,6 +150,9 @@ } } + if(!nhosts) + usage(1); + if(!set_mode && !print_mode) print_mode = 1; @@ -160,18 +165,32 @@ printf("[%s]\t%s", hosts[i], ctime(&timeval) /* ctime includes a trailing \n */); /* Do specified action(s) */ - if(set_mode && stime(&timeval) < 0) + if(set_mode) { - fprintf(stderr, "%s: could not set system time: %s\n", program_invocation_short_name, strerror(errno)); - retval = 1; - break; + if(stime(&timeval) == 0) + set_mode = 0; + else + { + fprintf(stderr, + "%s: could not set system time using host \"%s\": %s\n", + program_invocation_short_name, + hosts[i], + strerror(errno)); + } } - set_mode = 0; + + retval = 0; } } - if(!nhosts) - usage(1); - + if (set_mode) + { + if (nhosts > 1) + fprintf(stderr, + "%s: could not set system time at all\n", + program_invocation_short_name); + retval = 1; + } + return retval; }
The patch given is nasty, so I just did it myself. rdate now keeps track of successful calls to the internal rdate function. Maybe it could work better, but It does work, and I am marking it closed. The new version is rdate-1.0-4.src.rpm