Resolves: #1810104 - fix skip autofs patch

This commit is contained in:
Josef Řídký 2020-04-09 16:56:33 +02:00
parent b2ce63191d
commit 69b13ec687
2 changed files with 82 additions and 110 deletions

View File

@ -1,31 +1,6 @@
From cf41e6e910158fb4c4cb546c49acd587c5f58232 Mon Sep 17 00:00:00 2001
From: Josef Ridky <jridky@redhat.com>
Date: Wed, 24 Jul 2019 07:23:47 -0700
Subject: [PATCH] HOST-MIB: Skip autofs entries
Do not call statfs() for autofs entries.
See also https://sourceforge.net/p/net-snmp/patches/1350/.
See also https://sourceforge.net/p/net-snmp/bugs/2968/.
[ bvanassche: Made several small edits ]
---
agent/mibgroup/hardware/fsys/fsys_mntctl.c | 8 ++++++--
agent/mibgroup/hardware/fsys/fsys_mntent.c | 11 +++++++++++
agent/mibgroup/hardware/fsys/mnttypes.h | 3 +++
agent/mibgroup/host/hr_filesys.c | 21 +++++++++++++++++++++
agent/mibgroup/host/hr_filesys.h | 1 +
agent/mibgroup/host/hr_storage.c | 5 ++++-
agent/mibgroup/host/hrh_filesys.c | 6 ++++++
agent/mibgroup/host/hrh_filesys.h | 1 +
agent/mibgroup/host/hrh_storage.c | 5 ++++-
include/net-snmp/agent/hardware/fsys.h | 1 +
10 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/agent/mibgroup/hardware/fsys/fsys_mntctl.c b/agent/mibgroup/hardware/fsys/fsys_mntctl.c
index e7d9a1c5a..782c8edd2 100644
--- a/agent/mibgroup/hardware/fsys/fsys_mntctl.c
+++ b/agent/mibgroup/hardware/fsys/fsys_mntctl.c
diff -urNp b/agent/mibgroup/hardware/fsys/fsys_mntctl.c net-snmp-5.8/agent/mibgroup/hardware/fsys/fsys_mntctl.c
--- b/agent/mibgroup/hardware/fsys/fsys_mntctl.c 2018-07-18 16:12:20.674499629 +0200
+++ net-snmp-5.8/agent/mibgroup/hardware/fsys/fsys_mntctl.c 2018-07-18 16:15:46.782859398 +0200
@@ -43,8 +43,9 @@ _fsys_type( int type)
case MNT_NFS:
@ -37,27 +12,24 @@ index e7d9a1c5a..782c8edd2 100644
/*
* The following code covers selected filesystems
@@ -155,12 +156,15 @@ netsnmp_fsys_arch_load( void )
*/
@@ -156,10 +157,12 @@ netsnmp_fsys_arch_load( void )
/*
- * Optionally skip retrieving statistics for remote mounts
+ * Skip retrieving statistics for AUTOFS and optionally for remote
+ * mounts.
* Optionally skip retrieving statistics for remote mounts
+ * AUTOFS is skipped by default
*/
if ( (entry->flags & NETSNMP_FS_FLAG_REMOTE) &&
- if ( (entry->flags & NETSNMP_FS_FLAG_REMOTE) &&
+ if ( ((entry->flags & NETSNMP_FS_FLAG_REMOTE) &&
netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES))
- NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES))
+ NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) ||
+ entry->type == (NETSNMP_FS_TYPE_AUTOFS))
continue;
+ if (entry->type == NETSNMP_FS_TYPE_AUTOFS)
+ continue;
if ( statfs( entry->path, &stat_buf ) < 0 ) {
snprintf( tmpbuf, sizeof(tmpbuf), "Cannot statfs %s", entry->path );
diff --git a/agent/mibgroup/hardware/fsys/fsys_mntent.c b/agent/mibgroup/hardware/fsys/fsys_mntent.c
index 3cdcea1fb..79e6e4f72 100644
--- a/agent/mibgroup/hardware/fsys/fsys_mntent.c
+++ b/agent/mibgroup/hardware/fsys/fsys_mntent.c
diff -urNp b/agent/mibgroup/hardware/fsys/fsys_mntent.c net-snmp-5.8/agent/mibgroup/hardware/fsys/fsys_mntent.c
--- b/agent/mibgroup/hardware/fsys/fsys_mntent.c 2018-07-18 16:12:20.674499629 +0200
+++ net-snmp-5.8/agent/mibgroup/hardware/fsys/fsys_mntent.c 2018-07-18 16:15:46.782859398 +0200
@@ -150,6 +150,13 @@ _fsys_type( char *typename )
!strcmp(typename, MNTTYPE_LOFS))
return NETSNMP_FS_TYPE_OTHER;
@ -65,7 +37,7 @@ index 3cdcea1fb..79e6e4f72 100644
+ /* Detection of AUTOFS.
+ * This file system will be ignored by default
+ */
+ else if (!strcmp(typename, MNTTYPE_AUTOFS))
+ else if ( !strcmp(typename, MNTTYPE_AUTOFS))
+ return NETSNMP_FS_TYPE_AUTOFS;
+
+
@ -76,17 +48,16 @@ index 3cdcea1fb..79e6e4f72 100644
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES))
continue;
+ /* Skip AUTOFS entries */
+ if (entry->type == NETSNMP_FS_TYPE_AUTOFS)
+ /* Skip AUTOFS enteries */
+ if ( entry->type == (NETSNMP_FS_TYPE_AUTOFS))
+ continue;
+
#ifdef irix6
if ( NSFS_STATFS( entry->path, &stat_buf, sizeof(struct statfs), 0) < 0 )
#else
diff --git a/agent/mibgroup/hardware/fsys/mnttypes.h b/agent/mibgroup/hardware/fsys/mnttypes.h
index bb1b40173..53f1cc896 100644
--- a/agent/mibgroup/hardware/fsys/mnttypes.h
+++ b/agent/mibgroup/hardware/fsys/mnttypes.h
diff -urNp b/agent/mibgroup/hardware/fsys/mnttypes.h net-snmp-5.8/agent/mibgroup/hardware/fsys/mnttypes.h
--- b/agent/mibgroup/hardware/fsys/mnttypes.h 2018-07-18 16:12:20.674499629 +0200
+++ net-snmp-5.8/agent/mibgroup/hardware/fsys/mnttypes.h 2018-07-18 16:15:46.782859398 +0200
@@ -165,6 +165,9 @@
#ifndef MNTTYPE_APP
#define MNTTYPE_APP "app"
@ -97,10 +68,9 @@ index bb1b40173..53f1cc896 100644
#ifndef MNTTYPE_DEVPTS
#define MNTTYPE_DEVPTS "devpts"
#endif
diff --git a/agent/mibgroup/host/hr_filesys.c b/agent/mibgroup/host/hr_filesys.c
index 56c8b2095..8caeecf4e 100644
--- a/agent/mibgroup/host/hr_filesys.c
+++ b/agent/mibgroup/host/hr_filesys.c
diff -urNp b/agent/mibgroup/host/hr_filesys.c net-snmp-5.8/agent/mibgroup/host/hr_filesys.c
--- b/agent/mibgroup/host/hr_filesys.c 2018-07-18 16:12:20.668499652 +0200
+++ net-snmp-5.8/agent/mibgroup/host/hr_filesys.c 2018-07-18 16:15:46.783859399 +0200
@@ -834,6 +834,27 @@ Check_HR_FileSys_NFS (void)
return 0; /* no NFS file system */
}
@ -110,14 +80,14 @@ index 56c8b2095..8caeecf4e 100644
+ * return 1 if AutoFs, 0 otherwise
+ */
+int
+Check_HR_FileSys_AutoFs(void)
+Check_HR_FileSys_AutoFs (void)
+{
+#if HAVE_GETFSSTAT
+ if (HRFS_entry->HRFS_type != NULL &&
+ if ( HRFS_entry->HRFS_type != NULL &&
+#if defined(MNTTYPE_AUTOFS)
+ !strcmp(HRFS_entry->HRFS_type, MNTTYPE_AUTOFS)
+ !strcmp( HRFS_entry->HRFS_type, MNTTYPE_AUTOFS)
+#else
+ !strcmp(HRFS_entry->HRFS_type, "autofs")
+ !strcmp( HRFS_entry->HRFS_type, "autofs")
+#endif
+ )
+#endif /* HAVE_GETFSSTAT */
@ -129,10 +99,9 @@ index 56c8b2095..8caeecf4e 100644
void
End_HR_FileSys(void)
{
diff --git a/agent/mibgroup/host/hr_filesys.h b/agent/mibgroup/host/hr_filesys.h
index 2f00355f3..36cd7dd08 100644
--- a/agent/mibgroup/host/hr_filesys.h
+++ b/agent/mibgroup/host/hr_filesys.h
diff -urNp b/agent/mibgroup/host/hr_filesys.h net-snmp-5.8/agent/mibgroup/host/hr_filesys.h
--- b/agent/mibgroup/host/hr_filesys.h 2018-07-18 16:12:20.669499648 +0200
+++ net-snmp-5.8/agent/mibgroup/host/hr_filesys.h 2018-07-18 16:15:46.784859400 +0200
@@ -10,6 +10,7 @@ extern void Init_HR_FileSys(void);
extern FindVarMethod var_hrfilesys;
extern int Get_Next_HR_FileSys(void);
@ -141,33 +110,9 @@ index 2f00355f3..36cd7dd08 100644
extern int Get_FSIndex(char *);
extern long Get_FSSize(char *); /* Temporary */
diff --git a/agent/mibgroup/host/hr_storage.c b/agent/mibgroup/host/hr_storage.c
index a86898451..6b459ec51 100644
--- a/agent/mibgroup/host/hr_storage.c
+++ b/agent/mibgroup/host/hr_storage.c
@@ -544,6 +544,8 @@ var_hrstore(struct variable *vp,
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) &&
Check_HR_FileSys_NFS())
return NULL; /* or goto try_next; */
+ if (Check_HR_FileSys_AutoFs())
+ return NULL;
if (HRFS_statfs(HRFS_entry->HRFS_mount, &stat_buf) < 0) {
snmp_log_perror(HRFS_entry->HRFS_mount);
goto try_next;
@@ -683,7 +685,8 @@ Get_Next_HR_Store(void)
if (HRS_index >= 0) {
if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) &&
- Check_HR_FileSys_NFS())) {
+ Check_HR_FileSys_NFS()) &&
+ !Check_HR_FileSys_AutoFs()) {
return HRS_index + NETSNMP_MEM_TYPE_MAX;
}
} else {
diff --git a/agent/mibgroup/host/hrh_filesys.c b/agent/mibgroup/host/hrh_filesys.c
index 5ad82b20f..5d2102e24 100644
--- a/agent/mibgroup/host/hrh_filesys.c
+++ b/agent/mibgroup/host/hrh_filesys.c
diff -urNp b/agent/mibgroup/host/hrh_filesys.c net-snmp-5.8/agent/mibgroup/host/hrh_filesys.c
--- b/agent/mibgroup/host/hrh_filesys.c 2018-07-18 16:12:20.668499652 +0200
+++ net-snmp-5.8/agent/mibgroup/host/hrh_filesys.c 2018-07-18 16:15:46.785859402 +0200
@@ -429,3 +429,9 @@ Check_HR_FileSys_NFS (void)
{
return (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOTE) ? 1 : 0;
@ -176,12 +121,11 @@ index 5ad82b20f..5d2102e24 100644
+int
+Check_HR_FileSys_AutoFs (void)
+{
+ return HRFS_entry->type == NETSNMP_FS_TYPE_AUTOFS;
+ return (HRFS_entry->type == (NETSNMP_FS_TYPE_AUTOFS)) ? 1 : 0;
+}
diff --git a/agent/mibgroup/host/hrh_filesys.h b/agent/mibgroup/host/hrh_filesys.h
index 568917e09..c0f5d6e8c 100644
--- a/agent/mibgroup/host/hrh_filesys.h
+++ b/agent/mibgroup/host/hrh_filesys.h
diff -urNp b/agent/mibgroup/host/hrh_filesys.h net-snmp-5.8/agent/mibgroup/host/hrh_filesys.h
--- b/agent/mibgroup/host/hrh_filesys.h 2018-07-18 16:12:20.669499648 +0200
+++ net-snmp-5.8/agent/mibgroup/host/hrh_filesys.h 2018-07-18 16:15:46.785859402 +0200
@@ -10,6 +10,7 @@ extern void Init_HR_FileSys(void);
extern FindVarMethod var_hrhfilesys;
extern int Get_Next_HR_FileSys(void);
@ -190,20 +134,23 @@ index 568917e09..c0f5d6e8c 100644
extern int Get_FSIndex(char *);
extern long Get_FSSize(char *); /* Temporary */
diff --git a/agent/mibgroup/host/hrh_storage.c b/agent/mibgroup/host/hrh_storage.c
index 810766946..6f8ff6c53 100644
--- a/agent/mibgroup/host/hrh_storage.c
+++ b/agent/mibgroup/host/hrh_storage.c
@@ -371,6 +371,8 @@ var_hrstore(struct variable *vp,
diff -urNp b/agent/mibgroup/host/hrh_storage.c net-snmp-5.8/agent/mibgroup/host/hrh_storage.c
--- b/agent/mibgroup/host/hrh_storage.c 2018-07-18 16:12:20.668499652 +0200
+++ net-snmp-5.8/agent/mibgroup/host/hrh_storage.c 2018-07-18 16:15:46.786859402 +0200
@@ -367,9 +367,10 @@ really_try_next:
store_idx = name[ HRSTORE_ENTRY_NAME_LENGTH ];
if (HRFS_entry &&
store_idx > NETSNMP_MEM_TYPE_MAX &&
- netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
+ ((netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) &&
Check_HR_FileSys_NFS())
- Check_HR_FileSys_NFS())
+ Check_HR_FileSys_NFS()) ||
+ Check_HR_FileSys_AutoFs()))
return NULL;
+ if (Check_HR_FileSys_AutoFs())
+ return NULL;
if (store_idx <= NETSNMP_MEM_TYPE_MAX ) {
mem = (netsnmp_memory_info*)ptr;
}
@@ -508,7 +510,8 @@ Get_Next_HR_Store(void)
@@ -508,7 +509,8 @@ Get_Next_HR_Store(void)
if (HRS_index >= 0) {
if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) &&
@ -213,16 +160,40 @@ index 810766946..6f8ff6c53 100644
return HRS_index + NETSNMP_MEM_TYPE_MAX;
}
} else {
diff --git a/include/net-snmp/agent/hardware/fsys.h b/include/net-snmp/agent/hardware/fsys.h
index 3f2b28440..54ab9d806 100644
--- a/include/net-snmp/agent/hardware/fsys.h
+++ b/include/net-snmp/agent/hardware/fsys.h
@@ -41,6 +41,7 @@ typedef struct netsnmp_fsys_info_s netsnmp_fsys_info;
diff -urNp b/agent/mibgroup/host/hr_storage.c net-snmp-5.8/agent/mibgroup/host/hr_storage.c
--- b/agent/mibgroup/host/hr_storage.c 2018-07-18 16:12:20.670499644 +0200
+++ net-snmp-5.8/agent/mibgroup/host/hr_storage.c 2018-07-18 16:15:46.786859402 +0200
@@ -540,9 +540,10 @@ really_try_next:
store_idx = name[ HRSTORE_ENTRY_NAME_LENGTH ];
if (store_idx > NETSNMP_MEM_TYPE_MAX ) {
- if ( netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
+ if ( (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) &&
- Check_HR_FileSys_NFS())
+ Check_HR_FileSys_NFS()) ||
+ Check_HR_FileSys_AutoFs())
return NULL; /* or goto try_next; */
if (HRFS_statfs(HRFS_entry->HRFS_mount, &stat_buf) < 0) {
snmp_log_perror(HRFS_entry->HRFS_mount);
@@ -683,7 +684,8 @@ Get_Next_HR_Store(void)
if (HRS_index >= 0) {
if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) &&
- Check_HR_FileSys_NFS())) {
+ Check_HR_FileSys_NFS()) &&
+ !Check_HR_FileSys_AutoFs()) {
return HRS_index + NETSNMP_MEM_TYPE_MAX;
}
} else {
diff -urNp b/include/net-snmp/agent/hardware/fsys.h net-snmp-5.8/include/net-snmp/agent/hardware/fsys.h
--- b/include/net-snmp/agent/hardware/fsys.h 2018-07-18 16:12:20.649499726 +0200
+++ net-snmp-5.8/include/net-snmp/agent/hardware/fsys.h 2018-07-18 16:19:33.994918912 +0200
@@ -41,6 +41,7 @@ typedef struct netsnmp_fsys_info_s netsn
#define NETSNMP_FS_TYPE_SYSFS (4 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT)
#define NETSNMP_FS_TYPE_TMPFS (5 | _NETSNMP_FS_TYPE_LOCAL)
#define NETSNMP_FS_TYPE_USBFS (6 | _NETSNMP_FS_TYPE_LOCAL)
+#define NETSNMP_FS_TYPE_AUTOFS (7 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT)
+#define NETSNMP_FS_TYPE_AUTOFS (7 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT)
#define NETSNMP_FS_FLAG_ACTIVE 0x01
#define NETSNMP_FS_FLAG_REMOTE 0x02

View File

@ -508,6 +508,7 @@ LD_LIBRARY_PATH=%{buildroot}/%{_libdir} make test
%changelog
* Thu Apr 09 2020 Josef Ridky <jridky@redhat.com> -1:5.8-19
- update skip_autofs patch (#1810104)
- exit snmpd after snmpd -h command
- fix issues found by coverity scan
- fix issue with flood messages