afsmonitor: Use NULL, rather than (struct foo *)0
[openafs.git] / src / afsmonitor / afsmonitor.c
index 45df72e..1f019a6 100644 (file)
@@ -299,7 +299,7 @@ strcasestr(s1, s2)
     len2 = strlen(s2);
 
     if (len1 < len2)
-       return ((char *)NULL);
+       return (NULL);
 
     ptr = s1;
 
@@ -309,7 +309,7 @@ strcasestr(s1, s2)
        ptr++;
        len1--;
     }
-    return ((char *)NULL);
+    return (NULL);
 }
 #endif
 
@@ -481,22 +481,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);
@@ -569,8 +569,7 @@ insert_FS(char *a_hostName)         /* name of cache manager to be inserted in list */
 
     if (*a_hostName == '\0')
        return (-1);
-    curr_item = (struct afsmon_hostEntry *)
-       malloc(sizeof(struct afsmon_hostEntry));
+    curr_item = malloc(sizeof(struct afsmon_hostEntry));
     if (curr_item == (struct afsmon_hostEntry *)0) {
        fprintf(stderr, "Failed to allocate space for FS nameList\n");
        return (-1);
@@ -656,8 +655,7 @@ insert_CM(char *a_hostName)         /* name of cache manager to be inserted in list */
 
     if (*a_hostName == '\0')
        return (-1);
-    curr_item = (struct afsmon_hostEntry *)
-       malloc(sizeof(struct afsmon_hostEntry));
+    curr_item = malloc(sizeof(struct afsmon_hostEntry));
     if (curr_item == (struct afsmon_hostEntry *)0) {
        fprintf(stderr, "Failed to allocate space for CM nameList\n");
        return (-1);
@@ -1160,8 +1158,8 @@ parse_showEntry(char *a_line)
        /* if it is a section/group name, find it in the fs_categories[] array */
 
        found = 0;
-       if (strcasestr(arg2, "_section") != (char *)NULL
-           || strcasestr(arg2, "_group") != (char *)NULL) {
+       if (strcasestr(arg2, "_section") != NULL
+           || strcasestr(arg2, "_group") != NULL) {
            idx = 0;
            while (idx < FS_NUM_DATA_CATEGORIES) {
                sscanf(fs_categories[idx], "%s %d %d", catName, &fromIdx,
@@ -1184,7 +1182,7 @@ parse_showEntry(char *a_line)
        /* if it is a group name, read its start/end indices and fill in the
         * fs_Display_map[]. */
 
-       if (strcasestr(arg2, "_group") != (char *)NULL) {
+       if (strcasestr(arg2, "_group") != NULL) {
 
            if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_FS_STAT_ENTRIES
                || toIdx > NUM_FS_STAT_ENTRIES)
@@ -1204,7 +1202,7 @@ parse_showEntry(char *a_line)
            /* if it is a section name, get the count of number of groups in it and
             * for each group fill in the start/end indices in the fs_Display_map[] */
 
-       if (strcasestr(arg2, "_section") != (char *)NULL) {
+       if (strcasestr(arg2, "_section") != NULL) {
            /* fromIdx is actually the number of groups in thi section */
            numGroups = fromIdx;
            /* for each group in section */
@@ -1275,8 +1273,8 @@ parse_showEntry(char *a_line)
        /* if it is a section/group name, find it in the cm_categories[] array */
 
        found = 0;
-       if (strcasestr(arg2, "_section") != (char *)NULL
-           || strcasestr(arg2, "_group") != (char *)NULL) {
+       if (strcasestr(arg2, "_section") != NULL
+           || strcasestr(arg2, "_group") != NULL) {
            idx = 0;
            while (idx < CM_NUM_DATA_CATEGORIES) {
                sscanf(cm_categories[idx], "%s %d %d", catName, &fromIdx,
@@ -1299,7 +1297,7 @@ parse_showEntry(char *a_line)
        /* if it is a group name, read its start/end indices and fill in the
         * cm_Display_map[]. */
 
-       if (strcasestr(arg2, "_group") != (char *)NULL) {
+       if (strcasestr(arg2, "_group") != NULL) {
 
            if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_CM_STAT_ENTRIES
                || toIdx > NUM_CM_STAT_ENTRIES)
@@ -1319,7 +1317,7 @@ parse_showEntry(char *a_line)
            /* if it is a section name, get the count of number of groups in it and
             * for each group fill in the start/end indices in the cm_Display_map[] */
 
-       if (strcasestr(arg2, "_section") != (char *)NULL) {
+       if (strcasestr(arg2, "_section") != NULL) {
            /* fromIdx is actually the number of groups in thi section */
            numGroups = fromIdx;
            /* for each group in section */
@@ -1417,7 +1415,6 @@ process_config_file(char *a_config_filename)
     char *handlerPtr;          /* ptr to pass theresh handler string */
     int code = 0;              /* error code */
     int linenum = 0;           /* config file line number */
-    int threshCount;           /* count of thresholds for each server */
     int error_in_config;       /* syntax errors in config file  ?? */
     int i;
     int numBytes;
@@ -1453,7 +1450,6 @@ process_config_file(char *a_config_filename)
 
     numFS = 0;
     numCM = 0;
-    threshCount = 0;
     error_in_config = 0;       /* flag to note if config file has syntax errors */
 
     while ((fgets(line, CFG_STR_LEN, configFD)) != NULL) {
@@ -1541,7 +1537,7 @@ process_config_file(char *a_config_filename)
        }
        if (curr_host->numThresh) {
            numBytes = curr_host->numThresh * sizeof(struct Threshold);
-           curr_host->thresh = (struct Threshold *)malloc(numBytes);
+           curr_host->thresh = malloc(numBytes);
            if (curr_host->thresh == NULL) {
                fprintf(stderr, "[ %s ] Memory Allocation error 1", rn);
                afsmon_Exit(25);
@@ -1559,7 +1555,7 @@ process_config_file(char *a_config_filename)
        }
        if (curr_host->numThresh) {
            numBytes = curr_host->numThresh * sizeof(struct Threshold);
-           curr_host->thresh = (struct Threshold *)malloc(numBytes);
+           curr_host->thresh = malloc(numBytes);
            if (curr_host->thresh == NULL) {
                fprintf(stderr, "[ %s ] Memory Allocation error 2", rn);
                afsmon_Exit(35);
@@ -1737,12 +1733,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
@@ -1878,34 +1873,25 @@ fs_FullPerfs_ltoa(struct fs_Display_Data *a_fsData,
 {
     afs_int32 *srcbuf;
     struct fs_stats_FullPerfStats *fullPerfP;
+    struct fs_stats_FullPerfStats buffer;
     int idx;
     int i, j;
     afs_int32 *tmpbuf;
-    afs_int32 numInt32s;
-
-    fullPerfP = (struct fs_stats_FullPerfStats *)
-       (a_fsResults->data.AFS_CollData_val);
+    int code;
 
     /* there are two parts to the xstat FS statistics
      * - fullPerfP->overall which give the overall performance statistics, and
      * - fullPerfP->det which gives detailed info about file server operation
      * execution times */
 
-    /*
-     * Unfortunately, the full perf stats contain timeval structures which
-     * do not have the same size everywhere. Avoid displaying gargbage,
-     * but at least try to show the overall stats.
-     */
-    numInt32s = a_fsResults->data.AFS_CollData_len;
-    if (numInt32s !=
-       (sizeof(struct fs_stats_FullPerfStats) / sizeof(afs_int32))) {
-       srcbuf = a_fsResults->data.AFS_CollData_val;
+    code = xstat_fs_DecodeFullPerfStats(&fullPerfP,
+                                       a_fsResults->data.AFS_CollData_val,
+                                       a_fsResults->data.AFS_CollData_len,
+                                       &buffer);
+    if (code) {
+       /* Not able to decode the full perf stats. Avoid displaying garbage. */
        for (i = 0; i < NUM_FS_STAT_ENTRIES; i++) {
-           if (i < numInt32s && i < NUM_XSTAT_FS_AFS_PERFSTATS_LONGS) {
-               sprintf(a_fsData->data[i], "%d", srcbuf[i]);
-           } else {
-               sprintf(a_fsData->data[i], "%s", "--");
-           }
+           sprintf(a_fsData->data[i], "%s", "--");
        }
        return 0;
     }
@@ -2053,7 +2039,6 @@ execute_thresh_handler(char *a_handler,           /* ptr to handler function + args */
     char fileName[256];                /* file name to execute */
     int i;
     char *ch;
-    int code;
     int argNum;
     int anotherArg;            /* boolean used to flag if another arg is available */
 
@@ -2118,7 +2103,7 @@ execute_thresh_handler(char *a_handler,           /* ptr to handler function + args */
 
     if (fork() == 0) {
        exec_fsThreshHandler = 1;
-       code = afsmon_Exit(60);
+       afsmon_Exit(60);
     }
 
     return (0);
@@ -3508,8 +3493,8 @@ init_cm_buffers(void)
                    /* >>>  need to allocate rx connection info structure here <<< */
 
                    new_cmPR->data.AFSCB_CollData_val =
-                       (afs_int32 *) malloc(XSTAT_CM_FULLPERF_RESULTS_LEN
-                                            * sizeof(afs_int32));
+                       malloc(XSTAT_CM_FULLPERF_RESULTS_LEN
+                              *sizeof(afs_int32));
                    if (new_cmPR->data.AFSCB_CollData_val == NULL) {
                        free(new_cmlist_item);
                        free(new_cmPR->connP);
@@ -3600,7 +3585,7 @@ init_print_buffers(void)
 
     if (numFS) {
        numBytes = numFS * sizeof(struct fs_Display_Data);
-       curr_fsData = (struct fs_Display_Data *)malloc(numBytes);
+       curr_fsData = malloc(numBytes);
        if (curr_fsData == (struct fs_Display_Data *)0) {
            fprintf(stderr, "[ %s ] Memory allocation failure\n", rn);
            return (-1);
@@ -3608,7 +3593,7 @@ init_print_buffers(void)
        memset(curr_fsData, 0, numBytes);
 
        numBytes = numFS * sizeof(struct fs_Display_Data);
-       prev_fsData = (struct fs_Display_Data *)malloc(numBytes);
+       prev_fsData = malloc(numBytes);
        if (prev_fsData == (struct fs_Display_Data *)0) {
            fprintf(stderr, "[ %s ] Memory allocation failure\n", rn);
            return (-5);
@@ -3637,7 +3622,7 @@ init_print_buffers(void)
     if (numCM) {
        numBytes = numCM * sizeof(struct cm_Display_Data);
 
-       curr_cmData = (struct cm_Display_Data *)malloc(numBytes);
+       curr_cmData = malloc(numBytes);
        if (curr_cmData == (struct cm_Display_Data *)0) {
            fprintf(stderr, "[ %s ] Memory allocation failure\n", rn);
            return (-10);
@@ -3645,7 +3630,7 @@ init_print_buffers(void)
        memset(curr_cmData, 0, numBytes);
 
        numBytes = numCM * sizeof(struct cm_Display_Data);
-       prev_cmData = (struct cm_Display_Data *)malloc(numBytes);
+       prev_cmData = malloc(numBytes);
        if (prev_cmData == (struct cm_Display_Data *)0) {
            fprintf(stderr, "[ %s ] Memory allocation failure\n", rn);
            return (-15);
@@ -3738,7 +3723,7 @@ afsmon_execute(void)
        /* Allocate an array of sockets for each fileserver we monitor */
 
        FSsktbytes = numFS * sizeof(struct sockaddr_in);
-       FSSktArray = (struct sockaddr_in *)malloc(FSsktbytes);
+       FSSktArray = malloc(FSsktbytes);
        if (FSSktArray == (struct sockaddr_in *)0) {
            fprintf(stderr,
                    "[ %s ] cannot malloc %d sockaddr_ins for fileservers\n",
@@ -3823,7 +3808,7 @@ afsmon_execute(void)
        /* Allocate an array of sockets for each cache manager we monitor */
 
        CMsktbytes = numCM * sizeof(struct sockaddr_in);
-       CMSktArray = (struct sockaddr_in *)malloc(CMsktbytes);
+       CMSktArray = malloc(CMsktbytes);
        if (CMSktArray == (struct sockaddr_in *)0) {
            fprintf(stderr,
                    "[ %s ] cannot malloc %d sockaddr_ins for CM entries\n",
@@ -3847,12 +3832,8 @@ afsmon_execute(void)
            }
            strncpy(curr_CM->hostName, he->h_name, HOST_NAME_LEN);      /* complete name */
            memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
-           curr_skt->sin_family = AF_INET;             /*Internet family */
-#else
-           curr_skt->sin_family = htons(AF_INET);      /*Internet family */
-#endif
-           curr_skt->sin_port = htons(7001);   /*Cache Manager port */
+           curr_skt->sin_family = AF_INET;
+           curr_skt->sin_port = htons(7001);   /* Cache Manager port */
 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
            curr_skt->sin_len = sizeof(struct sockaddr_in);
 #endif