afsmonitor: remove unused LWP_WaitProcess
[openafs.git] / src / afsmonitor / afsmonitor.c
index 288a519..a6a9e97 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#include <stdio.h>
 #include <math.h>
-#include <string.h>
-#include <errno.h>
-#include <afs/cmd.h>
-#include <signal.h>
-#undef IN
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <netdb.h>
 #include <ctype.h>
-#ifdef HAVE_STDINT_H
-# include <stdint.h>
-#endif
+
+#include <afs/cmd.h>
 
 #include <afs/gtxwindows.h>            /*Generic window package */
 #include <afs/gtxobjects.h>            /*Object definitions */
@@ -66,7 +56,6 @@ int afsmon_debug = 0;         /* debug info to file ? */
 FILE *debugFD;                 /* debugging file descriptor */
 static int afsmon_output = 0;  /* output to file ? */
 static int afsmon_detOutput = 0;       /* detailed output ? */
-static int afsmon_onceOnly = 0;        /* probe once only ? (not implemented) */
 int afsmon_probefreq;          /* probe frequency */
 static int wpkg_to_use;                /* graphics package to use */
 static char output_filename[80];       /* output filename */
@@ -481,22 +470,22 @@ afsmon_Exit(int a_exitVal)        /* exit code */
 
 
     /* deallocate FS & CM Print buffers */
-    if (curr_fsData != (struct fs_Display_Data *)0) {
+    if (curr_fsData != NULL) {
        if (afsmon_debug)
            fprintf(debugFD, "Deallocating FS Print Buffers .... curr");
        free(curr_fsData);
     }
-    if (prev_fsData != (struct fs_Display_Data *)0) {
+    if (prev_fsData != NULL) {
        if (afsmon_debug)
            fprintf(debugFD, ", prev \n");
        free(prev_fsData);
     }
-    if (prev_cmData != (struct cm_Display_Data *)0) {
+    if (curr_cmData != NULL) {
        if (afsmon_debug)
            fprintf(debugFD, "Deallocating CM Print Buffers .... curr");
        free(curr_cmData);
     }
-    if (prev_cmData != (struct cm_Display_Data *)0) {
+    if (prev_cmData != NULL) {
        if (afsmon_debug)
            fprintf(debugFD, ", prev \n");
        free(prev_cmData);
@@ -999,10 +988,12 @@ store_threshold(int a_type,               /* 1 = fs , 2 = cm */
            for (j = 0; j < tmp_host->numThresh; j++) {
                if ((threshP->itemName[0] == '\0')
                    || (strcasecmp(threshP->itemName, a_varName) == 0)) {
-                   strncpy(threshP->itemName, a_varName,
-                           THRESH_VAR_NAME_LEN);
-                   strncpy(threshP->threshVal, a_value, THRESH_VAR_LEN);
-                   strcpy(threshP->handler, a_handler);
+                   strlcpy(threshP->itemName, a_varName,
+                           sizeof(threshP->itemName));
+                   strlcpy(threshP->threshVal, a_value,
+                           sizeof(threshP->threshVal));
+                   strlcpy(threshP->handler, a_handler,
+                           sizeof(threshP->handler));
                    threshP->index = index;
                    done = 1;
                    break;
@@ -1054,9 +1045,9 @@ store_threshold(int a_type,               /* 1 = fs , 2 = cm */
     for (i = 0; i < tmp_host->numThresh; i++) {
        if ((threshP->itemName[0] == '\0')
            || (strcasecmp(threshP->itemName, a_varName) == 0)) {
-           strncpy(threshP->itemName, a_varName, THRESH_VAR_NAME_LEN);
-           strncpy(threshP->threshVal, a_value, THRESH_VAR_LEN);
-           strcpy(threshP->handler, a_handler);
+           strlcpy(threshP->itemName, a_varName, sizeof(threshP->itemName));
+           strlcpy(threshP->threshVal, a_value, sizeof(threshP->threshVal));
+           strlcpy(threshP->handler, a_handler, sizeof(threshP->handler));
            threshP->index = index;
            done = 1;
            break;
@@ -1184,8 +1175,8 @@ parse_showEntry(char *a_line)
 
        if (strcasestr(arg2, "_group") != NULL) {
 
-           if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_FS_STAT_ENTRIES
-               || toIdx > NUM_FS_STAT_ENTRIES)
+           if (fromIdx < 0 || toIdx < 0 || fromIdx >= NUM_FS_STAT_ENTRIES
+               || toIdx >= NUM_FS_STAT_ENTRIES)
                return (-2);
            for (j = fromIdx; j <= toIdx; j++) {
                if (!fs_showFlags[j]) {
@@ -1193,7 +1184,7 @@ parse_showEntry(char *a_line)
                    fs_DisplayItems_count++;
                    fs_showFlags[j] = 1;
                }
-               if (fs_DisplayItems_count > NUM_FS_STAT_ENTRIES) {
+               if (fs_DisplayItems_count >= NUM_FS_STAT_ENTRIES) {
                    fprintf(stderr, "[ %s ] fs_DisplayItems_count ovf\n", rn);
                    return (-3);
                }
@@ -1212,8 +1203,8 @@ parse_showEntry(char *a_line)
 
                if (strcasestr(catName, "_group") != NULL) {
                    if (fromIdx < 0 || toIdx < 0
-                       || fromIdx > NUM_FS_STAT_ENTRIES
-                       || toIdx > NUM_FS_STAT_ENTRIES)
+                       || fromIdx >= NUM_FS_STAT_ENTRIES
+                       || toIdx >= NUM_FS_STAT_ENTRIES)
                        return (-4);
                    for (j = fromIdx; j <= toIdx; j++) {
                        if (!fs_showFlags[j]) {
@@ -1221,7 +1212,7 @@ parse_showEntry(char *a_line)
                            fs_DisplayItems_count++;
                            fs_showFlags[j] = 1;
                        }
-                       if (fs_DisplayItems_count > NUM_FS_STAT_ENTRIES) {
+                       if (fs_DisplayItems_count >= NUM_FS_STAT_ENTRIES) {
                            fprintf(stderr,
                                    "[ %s ] fs_DisplayItems_count ovf\n", rn);
                            return (-5);
@@ -1299,8 +1290,8 @@ parse_showEntry(char *a_line)
 
        if (strcasestr(arg2, "_group") != NULL) {
 
-           if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_CM_STAT_ENTRIES
-               || toIdx > NUM_CM_STAT_ENTRIES)
+           if (fromIdx < 0 || toIdx < 0 || fromIdx >= NUM_CM_STAT_ENTRIES
+               || toIdx >= NUM_CM_STAT_ENTRIES)
                return (-10);
            for (j = fromIdx; j <= toIdx; j++) {
                if (!cm_showFlags[j]) {
@@ -1308,7 +1299,7 @@ parse_showEntry(char *a_line)
                    cm_DisplayItems_count++;
                    cm_showFlags[j] = 1;
                }
-               if (cm_DisplayItems_count > NUM_CM_STAT_ENTRIES) {
+               if (cm_DisplayItems_count >= NUM_CM_STAT_ENTRIES) {
                    fprintf(stderr, "[ %s ] cm_DisplayItems_count ovf\n", rn);
                    return (-11);
                }
@@ -1327,8 +1318,8 @@ parse_showEntry(char *a_line)
 
                if (strcasestr(catName, "_group") != NULL) {
                    if (fromIdx < 0 || toIdx < 0
-                       || fromIdx > NUM_CM_STAT_ENTRIES
-                       || toIdx > NUM_CM_STAT_ENTRIES)
+                       || fromIdx >= NUM_CM_STAT_ENTRIES
+                       || toIdx >= NUM_CM_STAT_ENTRIES)
                        return (-12);
                    for (j = fromIdx; j <= toIdx; j++) {
                        if (!cm_showFlags[j]) {
@@ -1336,7 +1327,7 @@ parse_showEntry(char *a_line)
                            cm_DisplayItems_count++;
                            cm_showFlags[j] = 1;
                        }
-                       if (cm_DisplayItems_count > NUM_CM_STAT_ENTRIES) {
+                       if (cm_DisplayItems_count >= NUM_CM_STAT_ENTRIES) {
                            fprintf(stderr,
                                    "[ %s ] cm_DisplayItems_count ovf\n", rn);
                            return (-13);
@@ -1733,12 +1724,11 @@ save_FS_results_inCB(int a_newProbeCycle)       /* start of a new probe cycle ? */
        break;
     case AFS_XSTATSCOLL_CBSTATS:
        index = 1;
+       break;
     default:
-       if (index < 0) {
-           fprintf(stderr, "[ %s ] collection number %d is out of range.\n",
-                   rn, xstat_fs_Results.collectionNumber);
-           afsmon_Exit(51);
-       }
+       fprintf(stderr, "[ %s ] collection number %d is out of range.\n",
+               rn, xstat_fs_Results.collectionNumber);
+       afsmon_Exit(51);
     }
 
     /* If a new probe cycle started, mark the list in the current buffer
@@ -1879,6 +1869,7 @@ fs_FullPerfs_ltoa(struct fs_Display_Data *a_fsData,
     int i, j;
     afs_int32 *tmpbuf;
     int code;
+    int large_time;
 
     /* there are two parts to the xstat FS statistics
      * - fullPerfP->overall which give the overall performance statistics, and
@@ -1915,6 +1906,15 @@ fs_FullPerfs_ltoa(struct fs_Display_Data *a_fsData,
 
     srcbuf = (afs_int32 *) (fullPerfP->det.rpcOpTimes);
 
+    /*
+     * For every time value below, we'll have to skip an additional
+     * 64 bits of input if struct timeval uses 64-bit values
+     */
+    if (sizeof(struct timeval) == 16)
+       large_time = 1;
+    else
+       large_time = 0;
+
     for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++) {
        sprintf(a_fsData->data[idx], "%d", *srcbuf);    /* numOps */
        idx++;
@@ -1926,18 +1926,26 @@ fs_FullPerfs_ltoa(struct fs_Display_Data *a_fsData,
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
        tmpbuf = srcbuf++;      /* sqr time */
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
        tmpbuf = srcbuf++;      /* min time */
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
        tmpbuf = srcbuf++;      /* max time */
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
     }
 
     /* copy fs transfer timings */
@@ -1954,18 +1962,26 @@ fs_FullPerfs_ltoa(struct fs_Display_Data *a_fsData,
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
        tmpbuf = srcbuf++;      /* sqr time */
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
        tmpbuf = srcbuf++;      /* min time */
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
        tmpbuf = srcbuf++;      /* max time */
        sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
        idx++;
        srcbuf++;
+       if (large_time)
+           srcbuf += 2;
        sprintf(a_fsData->data[idx], "%d", *srcbuf);    /* sum bytes */
        idx++;
        srcbuf++;
@@ -3777,8 +3793,6 @@ afsmon_execute(void)
        }
 
        FSinitFlags = 0;
-       if (afsmon_onceOnly)    /* option not provided at this time */
-           FSinitFlags |= XSTAT_FS_INITFLAG_ONE_SHOT;
 
        if (afsmon_debug) {
            fprintf(debugFD, "[ %s ] Calling xstat_fs_Init \n", rn);
@@ -3850,8 +3864,6 @@ afsmon_execute(void)
        collIDs[num_cm_collections++] = AFSCB_XSTATSCOLL_FULL_PERF_INFO;
 
        CMinitFlags = 0;
-       if (afsmon_onceOnly)    /* once only ? */
-           CMinitFlags |= XSTAT_CM_INITFLAG_ONE_SHOT;
 
        if (afsmon_debug) {
            fprintf(debugFD, "[ %s ] Calling xstat_cm_Init \n", rn);
@@ -3875,19 +3887,6 @@ afsmon_execute(void)
 
 
     /* end of process cache manager entries */
-    /* if only one probe was required setup a waiting process for the
-     * termination signal */
-    if (afsmon_onceOnly) {
-       code = LWP_WaitProcess(&terminationEvent);
-       if (code) {
-           if (afsmon_debug) {
-               fprintf(debugFD, "LWP_WaitProcess() returned error %d\n",
-                       code);
-               fflush(debugFD);
-           }
-           afsmon_Exit(135);
-       }
-    }
 
     /* start the gtx input server */
     code = (intptr_t)gtx_InputServer(afsmon_win);
@@ -4238,7 +4237,7 @@ main(int argc, char **argv)
     /*
      * Set up the commands we understand.
      */
-    ts = cmd_CreateSyntax("initcmd", afsmonInit, NULL, "initialize the program");
+    ts = cmd_CreateSyntax("initcmd", afsmonInit, NULL, 0, "initialize the program");
     cmd_AddParm(ts, "-config", CMD_SINGLE, CMD_OPTIONAL,
                "configuration file");
     cmd_AddParm(ts, "-frequency", CMD_SINGLE, CMD_OPTIONAL,