16439911 snmpd stuck looping on ioctl(13, MNTIOC_GETMNTENT,) wo traffic
authorLijo George<lijo.x.george@oracle.com>
Thu, 07 Aug 2014 11:31:36 -0700
changeset 2034 c533107e2bd5
parent 2033 fe424cca0a17
child 2035 57b13bbbb179
16439911 snmpd stuck looping on ioctl(13, MNTIOC_GETMNTENT,) wo traffic
components/net-snmp/patches/048.16439911.hr_filesys.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/net-snmp/patches/048.16439911.hr_filesys.patch	Thu Aug 07 11:31:36 2014 -0700
@@ -0,0 +1,144 @@
+This fix has been submitted upstream as part of a combined patch
+which has fixes for CR15758982(027.7118090.hr_filesys.patch) and this CR(16439911).
+This can be found in the following location.
+https://sourceforge.net/p/net-snmp/patches/1287/. 
+
+This patch has not been accepted yet. 
+--- net-snmp-5.4.1.old/agent/mibgroup/host/hr_filesys.c	2014-07-15 01:53:05.131000348 -0700
++++ net-snmp-5.4.1/agent/mibgroup/host/hr_filesys.c	2014-07-15 01:48:04.221278640 -0700
[email protected]@ -698,20 +698,25 @@
+ static int 
+ load_mnttab_cache_solaris()
+ {
+-    char buf[512] = {NULL};
++    char buf[MNT_LINE_MAX] = {NULL};
+     int i = 0;
+     struct stat file_stat;
+     const char **cpp;
+-    char *ch;
++    char *ch, *token_ptr;
+     int token_flag = 0;
+     int skip_flag = 0;
+     int ignore_flag = 0;
+     int j = 0;
+     int lines = 0;
+     int ret = 0;
++    int chk_mnt = -1;
+     HRFS_index = 0;
+ 
+-    stat(ETC_MNTTAB, &file_stat);
++    if(stat(ETC_MNTTAB, &file_stat) != 0)
++    {
++        DEBUGMSGTL(("host/hr_filesys", "stat failed for mnttab.\n"));
++        return -1;
++    }
+     if (last_access == -1 || last_access != file_stat.st_mtime) {
+         fp = fopen(ETC_MNTTAB, "r");
+         if(fp == NULL)
[email protected]@ -731,7 +736,7 @@
+              * which determines the valid entries.
+              */
+ 
+-            ch = strtok(buf, " \t");
++            ch = strtok_r(buf, " \t", &token_ptr);
+             while (ch != NULL) {
+                 j++;
+                 if(j == 3) {
[email protected]@ -745,7 +750,7 @@
+                 }
+                 if(token_flag)
+                     break;
+-                ch = strtok(NULL, " \t");
++                ch = strtok_r(NULL, " \t", &token_ptr);
+              }
+              if(!skip_flag)
+                  lines++;
[email protected]@ -765,25 +770,43 @@
+             free(HRFS_list);
+             return -1;
+         }
+-
+-        while (i < fscount) {
+-            if (getmntent(fp, &HRFS_entry_struct) == 0) {
+-                 for (cpp = HRFS_ignores; *cpp != NULL; ++cpp) {
+-                     if (!strcmp(HRFS_entry_struct.HRFS_type, *cpp)) {
+-                         ignore_flag = 1;
+-                         break;
+-                     }
++        while ((chk_mnt = getmntent(fp, &HRFS_entry_struct)) != -1) {
++             if(chk_mnt != 0)
++                 continue;
++             for (cpp = HRFS_ignores; *cpp != NULL; ++cpp) {
++                 if (!strcmp(HRFS_entry_struct.mnt_fstype, *cpp)) {
++                     ignore_flag = 1;
++                     break;
+                  }
+-
+-                 if(!ignore_flag) {
+-                     HRFS_list[i].mnt_special = strdup(HRFS_entry_struct.mnt_special);
+-                     HRFS_list[i].mnt_mountp = strdup(HRFS_entry_struct.mnt_mountp);
+-                     HRFS_list[i].mnt_fstype = strdup(HRFS_entry_struct.mnt_fstype);
+-                     HRFS_list[i].mnt_mntopts = strdup(HRFS_entry_struct.mnt_mntopts);
+-                     i++;
++             }
++             if(!ignore_flag) {
++                 if(i >= fscount)
++                 {
++                    DEBUGMSGTL(("host/hr_filesys","increasing cachesize from %d to %d",fscount,i+1));
++                    HRFS_list = realloc(HRFS_list, sizeof(struct mnttab) * (i+1));
++                    fscount = i+1;
++                    if(HRFS_list == NULL)
++                    {
++                        DEBUGMSGTL(("host/hr_filesys","\nrealloc failed for mnttab cache.\n"));
++                        return -1;
++                    }
+                  }
+-
+-                 ignore_flag = 0;
++                 HRFS_list[i].mnt_special = strdup(HRFS_entry_struct.mnt_special);
++                 HRFS_list[i].mnt_mountp = strdup(HRFS_entry_struct.mnt_mountp);
++                 HRFS_list[i].mnt_fstype = strdup(HRFS_entry_struct.mnt_fstype);
++                 HRFS_list[i].mnt_mntopts = strdup(HRFS_entry_struct.mnt_mntopts);
++                 i++;
++             }
++             ignore_flag = 0;
++        }
++        if(i < fscount)
++        {
++            DEBUGMSGTL(("host/hr_filesys","\ndecreasing cachesize from %d to %d\n",fscount,i));
++            HRFS_list = realloc(HRFS_list, sizeof(struct mnttab) * i );
++            if(HRFS_list == NULL)
++            {
++                DEBUGMSGTL(("host/hr_filesys","\nrealloc failed for mnttab cache.\n"));
++                return -1;
+             }
+         }
+ 
[email protected]@ -925,19 +948,19 @@
+         HRFS_entry = NULL;
+     }
+ #else
+-    int i = 0;
+     if (fp != NULL)
+         fclose(fp);
+     fp = NULL;
+ 
+ #ifdef solaris2
+-while (i < fscount) {
+-    free(HRFS_list[i].mnt_special);
+-    free(HRFS_list[i].mnt_mountp);
+-    free(HRFS_list[i].mnt_fstype);
+-    free(HRFS_list[i].mnt_mntopts);
+-    i++;
+-}
++    int i = 0;
++    while (i < fscount) {
++        free(HRFS_list[i].mnt_special);
++        free(HRFS_list[i].mnt_mountp);
++        free(HRFS_list[i].mnt_fstype);
++        free(HRFS_list[i].mnt_mntopts);
++        i++;
++    }
+     if (HRFS_list != NULL)
+         free(HRFS_list);
+     last_access = -1;