udebug-display-lastyeshost-order-20080510
[openafs.git] / src / ubik / udebug.c
index b79955d..bde8dce 100644 (file)
@@ -15,13 +15,7 @@ RCSID
 
 #include <sys/types.h>
 #include <stdlib.h>
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
 #else
@@ -34,6 +28,7 @@ RCSID
 #include <unistd.h>
 #endif
 #include <signal.h>
+#include <afs/afsutil.h>
 #include <time.h>
 
 #include <lock.h>
@@ -45,6 +40,7 @@ RCSID
 #include "ubik.h"
 #include "ubik_int.h"
 
+/* needed by Irix. Include a header to get it, or leave it alone. */
 extern struct hostent *hostutil_GetHostByName();
 
 static short
@@ -88,15 +84,14 @@ PortName(char *aname)
 }
 
 static int
-CommandProc(struct cmd_syndesc *as, char *arock)
+CommandProc(struct cmd_syndesc *as, void *arock)
 {
     char *hostName, *portName, *times;
     afs_int32 hostAddr;
-    struct in_addr inhostAddr;
     register afs_int32 i, j, code;
     short port;
     int int32p;
-    afs_int32 now, diff, newtime;
+    time_t now, then, diff, newtime;
     struct hostent *th;
     struct rx_connection *tconn;
     struct rx_securityClass *sc;
@@ -160,11 +155,11 @@ CommandProc(struct cmd_syndesc *as, char *arock)
        exit(0);
     }
     now = time(0);
+    then = udebug.now;
 
     /* now print the main info */
-    times = ctime((time_t *) & udebug.now);
+    times = ctime(&then);
     times[24] = 0;
-    inhostAddr.s_addr = hostAddr;
     if (!oldServer) {
        printf("Host's addresses are: ");
        for (j = 0; udebug.interfaceAddr[j] && (j < UBIK_MAX_INTERFACE_ADDR);
@@ -172,13 +167,13 @@ CommandProc(struct cmd_syndesc *as, char *arock)
            printf("%s ", afs_inet_ntoa(htonl(udebug.interfaceAddr[j])));
        printf("\n");
     }
-    printf("Host's %s time is %s\n", inet_ntoa(inhostAddr), times);
+    printf("Host's %s time is %s\n", afs_inet_ntoa(hostAddr), times);
 
     times = ctime(&now);
     times[24] = 0;
     diff = now - udebug.now;
-    printf("Local time is %s (time differential %d secs)\n", times, diff);
-    if (abs(diff) >= MAXSKEW)
+    printf("Local time is %s (time differential %d secs)\n", times, (int)diff);
+    if (abs((int)diff) >= MAXSKEW)
        printf("****clock may be bad\n");
 
     /* UBIK skips the voting if 1 server - so we fudge it here */
@@ -195,17 +190,16 @@ CommandProc(struct cmd_syndesc *as, char *arock)
     if (udebug.lastYesHost == 0xffffffff) {
        printf("Last yes vote not cast yet \n");
     } else {
-       inhostAddr.s_addr = htonl(udebug.lastYesHost);
        diff = udebug.now - udebug.lastYesTime;
        printf("Last yes vote for %s was %d secs ago (%ssync site); \n",
-              inet_ntoa(inhostAddr), diff,
+              afs_inet_ntoa(udebug.lastYesHost), (int)diff,
               ((udebug.lastYesState) ? "" : "not "));
 
        diff = udebug.now - udebug.lastYesClaim;
        newtime = now - diff;
        times = ctime(&newtime);
        times[24] = 0;
-       printf("Last vote started %d secs ago (at %s)\n", diff, times);
+       printf("Last vote started %d secs ago (at %s)\n", (int)diff, times);
     }
 
     printf("Local db version is %d.%d\n", udebug.localVersion.epoch,
@@ -222,7 +216,7 @@ CommandProc(struct cmd_syndesc *as, char *arock)
            times[24] = 0;
            printf
                ("I am sync site until %d secs from now (at %s) (%d server%s)\n",
-                diff, times, udebug.nServers,
+                (int)diff, times, udebug.nServers,
                 ((udebug.nServers > 1) ? "s" : ""));
        }
        printf("Recovery state %x\n", udebug.recoveryState);
@@ -235,15 +229,15 @@ CommandProc(struct cmd_syndesc *as, char *arock)
            printf("I am a clone and never can become sync site\n");
        else
            printf("I am not sync site\n");
-       inhostAddr.s_addr = htonl(udebug.lowestHost);
        diff = udebug.now - udebug.lowestTime;
-       printf("Lowest host %s was set %d secs ago\n", inet_ntoa(inhostAddr),
-              diff);
+       printf("Lowest host %s was set %d secs ago\n",
+              afs_inet_ntoa(htonl(udebug.lowestHost)),
+              (int)diff);
 
-       inhostAddr.s_addr = htonl(udebug.syncHost);
        diff = udebug.now - udebug.syncTime;
-       printf("Sync host %s was set %d secs ago\n", inet_ntoa(inhostAddr),
-              diff);
+       printf("Sync host %s was set %d secs ago\n",
+              afs_inet_ntoa(htonl(udebug.syncHost)),
+              (int)diff);
     }
 
     printf("Sync site's db version is %d.%d\n", udebug.syncVersion.epoch,
@@ -271,7 +265,7 @@ CommandProc(struct cmd_syndesc *as, char *arock)
        times[24] = 0;
        printf
            ("Last time a new db version was labelled was:\n\t %d secs ago (at %s)\n",
-            diff, times);
+            (int)diff, times);
     }
 
     if (int32p || udebug.amSyncSite) {
@@ -292,7 +286,6 @@ CommandProc(struct cmd_syndesc *as, char *arock)
                printf("error code %d from VOTE_SDebug\n", code);
                break;
            }
-           inhostAddr.s_addr = htonl(usdebug.addr);
            /* otherwise print the structure */
            printf("\nServer (%s", afs_inet_ntoa(htonl(usdebug.addr)));
            for (j = 0;
@@ -312,7 +305,7 @@ CommandProc(struct cmd_syndesc *as, char *arock)
                newtime = now - diff;
                times = ctime(&newtime);
                times[24] = 0;
-               printf("    last vote rcvd %d secs ago (at %s),\n", diff,
+               printf("    last vote rcvd %d secs ago (at %s),\n", (int)diff,
                       times);
            }
 
@@ -325,7 +318,7 @@ CommandProc(struct cmd_syndesc *as, char *arock)
                times[24] = 0;
                printf
                    ("    last beacon sent %d secs ago (at %s), last vote was %s\n",
-                    diff, times, ((usdebug.lastVote) ? "yes" : "no"));
+                    (int)diff, times, ((usdebug.lastVote) ? "yes" : "no"));
            }
 
            printf("    dbcurrent=%d, up=%d beaconSince=%d\n",
@@ -356,7 +349,7 @@ main(int argc, char **argv)
     nsa.sa_flags = SA_FULLDUMP;
     sigaction(SIGSEGV, &nsa, NULL);
 #endif
-    ts = cmd_CreateSyntax(NULL, CommandProc, 0, "probe ubik server");
+    ts = cmd_CreateSyntax(NULL, CommandProc, NULL, "probe ubik server");
     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "server machine");
     cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "IP port");
     cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "print all info");