better error handling
authorAndrew Tridgell <tridge@samba.org>
Tue, 11 Dec 2001 05:47:26 +0000 (05:47 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 11 Dec 2001 05:47:26 +0000 (05:47 +0000)
(This used to be commit 75621d528433a9c1af3eada0b748dfbcfdb8ad62)

source3/utils/net_time.c

index 6c5f38c17ad7b31408a6d1cdfe8417c4205ed8ba..8d0c854e286caf55eb85a196724b85dad25194f5 100644 (file)
@@ -33,7 +33,12 @@ static time_t cli_servertime(const char *host, struct in_addr *ip)
        struct cli_state *cli = NULL;
 
        cli = cli_initialise(NULL);
-       if (!cli || !cli_connect(cli, host, ip)) goto done;
+       if (!cli) goto done;
+
+       if (!cli_connect(cli, host, ip)) {
+               fprintf(stderr,"Can't contact server\n");
+               goto done;
+       }
 
        make_nmb_name(&calling, global_myname, 0x0);
        if (host) {
@@ -42,8 +47,14 @@ static time_t cli_servertime(const char *host, struct in_addr *ip)
                make_nmb_name(&called, "*SMBSERVER", 0x20);
        }
 
-       if (!cli_session_request(cli, &calling, &called)) goto done;
-       if (!cli_negprot(cli)) goto done;
+       if (!cli_session_request(cli, &calling, &called)) {
+               fprintf(stderr,"Session request failed\n");
+               goto done;
+       }
+       if (!cli_negprot(cli)) {
+               fprintf(stderr,"Protocol negotiation failed\n");
+               goto done;
+       }
 
        ret = cli->servertime;
 
@@ -94,10 +105,7 @@ static int net_time_set(int argc, const char **argv)
        time_t t = nettime();
        char *cmd;
 
-       if (t == 0) {
-               d_printf("Can't contact server\n");
-               return -1;
-       }
+       if (t == 0) return -1;
        
        /* yes, I know this is cheesy. Use "net time system" if you want to 
           roll your own. I'm putting this in as it works on a large number
@@ -114,10 +122,7 @@ static int net_time_system(int argc, const char **argv)
 {
        time_t t = nettime();
 
-       if (t == 0) {
-               d_printf("Can't contact server\n");
-               return -1;
-       }
+       if (t == 0) return -1;
 
        printf("%s\n", systime(t));
 
@@ -148,6 +153,7 @@ int net_time(int argc, const char **argv)
 
        /* default - print the time */
        t = cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL);
+       if (t == 0) return -1;
 
        d_printf("%s", ctime(&t));
        return 0;