Blame SOURCES/net-snmp-5.8-dskTable-dynamic.patch

17a0ab
diff -ruNp a/agent/mibgroup/ucd-snmp/disk.c b/agent/mibgroup/ucd-snmp/disk.c
17a0ab
--- a/agent/mibgroup/ucd-snmp/disk.c	2020-06-10 09:29:35.867328760 +0200
17a0ab
+++ b/agent/mibgroup/ucd-snmp/disk.c	2020-06-10 09:44:13.053535421 +0200
17a0ab
@@ -153,9 +153,10 @@ static void       disk_free_config(void)
17a0ab
 static void       disk_parse_config(const char *, char *);
17a0ab
 static void       disk_parse_config_all(const char *, char *);
17a0ab
 #if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS
17a0ab
-static void       find_and_add_allDisks(int minpercent);
17a0ab
+static void       refresh_disk_table(int addNewDisks, int minpercent);
17a0ab
 static void       add_device(char *path, char *device,
17a0ab
-	                     int minspace, int minpercent, int override);
17a0ab
+	                     int minspace, int minpercent, int addNewDisks,
17a0ab
+	                     int override);
17a0ab
 static void       modify_disk_parameters(int index, int minspace,
17a0ab
 	                                 int minpercent);
17a0ab
 static int        disk_exists(char *path);
17a0ab
@@ -167,6 +168,7 @@ struct diskpart {
17a0ab
     char            path[STRMAX];
17a0ab
     int             minimumspace;
17a0ab
     int             minpercent;
17a0ab
+    int             alive;
17a0ab
 };
17a0ab
 
17a0ab
 #define MAX_INT_32 0x7fffffff
17a0ab
@@ -174,6 +176,7 @@ struct diskpart {
17a0ab
 
17a0ab
 unsigned int    numdisks;
17a0ab
 int             allDisksIncluded = 0;
17a0ab
+int             allDisksMinPercent = 0;
17a0ab
 unsigned int    maxdisks = 0;
17a0ab
 struct diskpart *disks;
17a0ab
 
17a0ab
@@ -238,6 +241,7 @@ init_disk(void)
17a0ab
 				disk_free_config,
17a0ab
 				"minpercent%");
17a0ab
   allDisksIncluded = 0;
17a0ab
+  allDisksMinPercent = 0;
17a0ab
 }
17a0ab
 
17a0ab
 static void
17a0ab
@@ -253,6 +257,7 @@ disk_free_config(void)
17a0ab
     disks[i].minpercent = -1;
17a0ab
   }
17a0ab
   allDisksIncluded = 0;
17a0ab
+  allDisksMinPercent = 0;
17a0ab
 }
17a0ab
 
17a0ab
 static void 
17a0ab
@@ -313,7 +318,7 @@ disk_parse_config(const char *token, cha
17a0ab
    * check if the disk already exists, if so then modify its
17a0ab
    * parameters. if it does not exist then add it
17a0ab
    */
17a0ab
-  add_device(path, find_device(path), minspace, minpercent, 1);
17a0ab
+  add_device(path, find_device(path), minspace, minpercent, 1, 1);
17a0ab
 #endif /* HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS */
17a0ab
 }
17a0ab
 
17a0ab
@@ -372,7 +377,7 @@ disk_parse_config_all(const char *token,
17a0ab
 
17a0ab
 #if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS
17a0ab
 static void
17a0ab
-add_device(char *path, char *device, int minspace, int minpercent, int override) 
17a0ab
+add_device(char *path, char *device, int minspace, int minpercent, int addNewDisks, int override) 
17a0ab
 {
17a0ab
   int index;
17a0ab
 
17a0ab
@@ -402,10 +407,16 @@ add_device(char *path, char *device, int
17a0ab
   }
17a0ab
 
17a0ab
   index = disk_exists(path);
17a0ab
-  if((index != -1) && (index < maxdisks) && (override==1)) {
17a0ab
-    modify_disk_parameters(index, minspace, minpercent);
17a0ab
+  if((index != -1) && (index < maxdisks)) {
17a0ab
+    /* the path is already in the table */
17a0ab
+    disks[index].alive = 1;
17a0ab
+    /* -> update its device */
17a0ab
+    strlcpy(disks[index].device, device, sizeof(disks[index].device));
17a0ab
+    if (override == 1) {
17a0ab
+        modify_disk_parameters(index, minspace, minpercent);
17a0ab
+    }
17a0ab
   }
17a0ab
-  else if(index == -1){
17a0ab
+  else if(index == -1 && addNewDisks){
17a0ab
     /* add if and only if the device was found */
17a0ab
     if(device[0] != 0) {
17a0ab
       /* The following buffers are cleared above, no need to add '\0' */
17a0ab
@@ -413,6 +424,7 @@ add_device(char *path, char *device, int
17a0ab
       strlcpy(disks[numdisks].device, device, sizeof(disks[numdisks].device));
17a0ab
       disks[numdisks].minimumspace = minspace;
17a0ab
       disks[numdisks].minpercent   = minpercent;
17a0ab
+      disks[numdisks].alive        = 1;
17a0ab
       numdisks++;  
17a0ab
     }
17a0ab
     else {
17a0ab
@@ -420,6 +432,7 @@ add_device(char *path, char *device, int
17a0ab
       disks[numdisks].minpercent = -1;
17a0ab
       disks[numdisks].path[0] = 0;
17a0ab
       disks[numdisks].device[0] = 0;
17a0ab
+      disks[numdisks].alive = 0;
17a0ab
     }
17a0ab
   }
17a0ab
 }
17a0ab
@@ -444,7 +457,7 @@ int disk_exists(char *path)
17a0ab
 }
17a0ab
 
17a0ab
 static void 
17a0ab
-find_and_add_allDisks(int minpercent)
17a0ab
+refresh_disk_table(int addNewDisks, int minpercent)
17a0ab
 {
17a0ab
 #if HAVE_GETMNTENT
17a0ab
 #if HAVE_SYS_MNTTAB_H
17a0ab
@@ -480,7 +493,7 @@ find_and_add_allDisks(int minpercent)
17a0ab
       return;
17a0ab
   }
17a0ab
   while (mntfp && NULL != (mntent = getmntent(mntfp))) {
17a0ab
-    add_device(mntent->mnt_dir, mntent->mnt_fsname, -1, minpercent, 0);
17a0ab
+    add_device(mntent->mnt_dir, mntent->mnt_fsname, -1, minpercent, addNewDisks, 0);
17a0ab
     dummy = 1;
17a0ab
   }
17a0ab
   if (mntfp)
17a0ab
@@ -497,7 +510,7 @@ find_and_add_allDisks(int minpercent)
17a0ab
       return;
17a0ab
   }
17a0ab
   while ((i = getmntent(mntfp, &mnttab)) == 0) {
17a0ab
-    add_device(mnttab.mnt_mountp, mnttab.mnt_special, -1, minpercent, 0);
17a0ab
+    add_device(mnttab.mnt_mountp, mnttab.mnt_special, -1, minpercent, addNewDisks, 0);
17a0ab
     dummy = 1;
17a0ab
   }
17a0ab
   fclose(mntfp);
17a0ab
@@ -510,7 +523,7 @@ find_and_add_allDisks(int minpercent)
17a0ab
 #elif HAVE_FSTAB_H
17a0ab
   setfsent();			/* open /etc/fstab */
17a0ab
   while((fstab1 = getfsent()) != NULL) {
17a0ab
-    add_device(fstab1->fs_file, fstab1->fs_spec, -1, minpercent, 0);
17a0ab
+    add_device(fstab1->fs_file, fstab1->fs_spec, -1, minpercent, addNewDisks, 0);
17a0ab
     dummy = 1;
17a0ab
   }
17a0ab
   endfsent();			/* close /etc/fstab */
17a0ab
@@ -521,7 +534,7 @@ find_and_add_allDisks(int minpercent)
17a0ab
     mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
17a0ab
     for (i = 0; i < mntsize; i++) {
17a0ab
       if (strncmp(mntbuf[i].f_fstypename, "zfs", 3) == 0) {
17a0ab
-	add_device(mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname, -1, minpercent, 0);
17a0ab
+    	add_device(mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname, -1, minpercent, addNewDisks, 0);
17a0ab
       }
17a0ab
     }
17a0ab
   }
17a0ab
@@ -537,7 +550,7 @@ find_and_add_allDisks(int minpercent)
17a0ab
    * statfs we default to the root partition "/"
17a0ab
    */
17a0ab
   if (statfs("/", &statf) == 0) {
17a0ab
-    add_device("/", statf.f_mntfromname, -1, minpercent, 0);
17a0ab
+    add_device("/", statf.f_mntfromname, -1, minpercent, addNewDisks, 0);
17a0ab
   }
17a0ab
 #endif
17a0ab
   else {
17a0ab
@@ -696,6 +709,10 @@ fill_dsk_entry(int disknum, struct dsk_e
17a0ab
 #endif
17a0ab
 #endif
17a0ab
 
17a0ab
+    if (disks[disknum].alive == 0){
17a0ab
+        return -1;
17a0ab
+    }
17a0ab
+
17a0ab
     entry->dskPercentInode = -1;
17a0ab
 
17a0ab
 #if defined(HAVE_STATVFS) || defined(HAVE_STATFS)
17a0ab
@@ -826,6 +843,13 @@ var_extensible_disk(struct variable *vp,
17a0ab
     static long     long_ret;
17a0ab
     static char    *errmsg;
17a0ab
 
17a0ab
+    int i;
17a0ab
+    for (i = 0; i < numdisks; i++){
17a0ab
+        disks[i].alive = 0;
17a0ab
+    }
17a0ab
+    /* dynamically add new disks + update alive flag */
17a0ab
+    refresh_disk_table(allDisksIncluded, allDisksMinPercent);
17a0ab
+
17a0ab
 tryAgain:
17a0ab
     if (header_simple_table
17a0ab
         (vp, name, length, exact, var_len, write_method, numdisks))