summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorchristian-2 <49752982+christian-2@users.noreply.github.com>2022-12-13 22:48:36 (GMT)
committerGitHub <noreply@github.com>2022-12-13 22:48:36 (GMT)
commitdd249c5d4bbce1c1250322dab8c8d0d69b0dca34 (patch)
tree54424263b3aeba0e6483f7d75368dc07531774d7 /lib
parenta517c62c1b536c934c92e4ac0f75b49bab927dca (diff)
downloadmonitoring-plugins-dd249c5d4bbce1c1250322dab8c8d0d69b0dca34.tar.gz
check_disk: Find accessible mount path if multiple are available (#1820)
* fixes #1819 * mount entries also have to be accessible according to get_fs_usage()
Diffstat (limited to 'lib')
-rw-r--r--lib/utils_disk.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index c7c9126..4f16068 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -28,6 +28,7 @@
28 28
29#include "common.h" 29#include "common.h"
30#include "utils_disk.h" 30#include "utils_disk.h"
31#include "gl/fsusage.h"
31 32
32void 33void
33np_add_name (struct name_list **list, const char *name) 34np_add_name (struct name_list **list, const char *name)
@@ -127,9 +128,12 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
127 size_t name_len = strlen(d->name); 128 size_t name_len = strlen(d->name);
128 size_t best_match_len = 0; 129 size_t best_match_len = 0;
129 struct mount_entry *best_match = NULL; 130 struct mount_entry *best_match = NULL;
131 struct fs_usage fsp;
130 132
131 /* set best match if path name exactly matches a mounted device name */ 133 /* set best match if path name exactly matches a mounted device name */
132 for (me = mount_list; me; me = me->me_next) { 134 for (me = mount_list; me; me = me->me_next) {
135 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
136 continue; /* skip if permissions do not suffice for accessing device */
133 if (strcmp(me->me_devname, d->name)==0) 137 if (strcmp(me->me_devname, d->name)==0)
134 best_match = me; 138 best_match = me;
135 } 139 }
@@ -137,6 +141,8 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
137 /* set best match by directory name if no match was found by devname */ 141 /* set best match by directory name if no match was found by devname */
138 if (! best_match) { 142 if (! best_match) {
139 for (me = mount_list; me; me = me->me_next) { 143 for (me = mount_list; me; me = me->me_next) {
144 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
145 continue; /* skip if permissions do not suffice for accessing device */
140 size_t len = strlen (me->me_mountdir); 146 size_t len = strlen (me->me_mountdir);
141 if ((exact == FALSE && (best_match_len <= len && len <= name_len && 147 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
142 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 148 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))