Bug 13796 - "rdate -s host" can fail but still exit(0)
Summary: "rdate -s host" can fail but still exit(0)
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: rdate   
(Show other bugs)
Version: 6.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Crutcher Dunnavant
QA Contact:
URL: http://www.larim.polymtl.ca/~chuck/rd...
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-07-12 14:26 UTC by charles
Modified: 2008-05-01 15:37 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-07-26 23:35:58 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description charles 2000-07-12 14:26:27 UTC
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.

Comment 1 Crutcher Dunnavant 2000-07-26 22:37:48 UTC
I can't duplicate this.
Can you send more info, and the patch?

Comment 2 charles 2000-07-26 23:26:51 UTC
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.


Comment 3 charles 2000-07-26 23:35:58 UTC
--- 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;  }

Comment 4 Crutcher Dunnavant 2000-07-31 18:41:57 UTC
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


Note You need to log in before you can comment on or make changes to this bug.