summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/extra_opts.c25
-rw-r--r--lib/maxfd.c26
-rw-r--r--lib/maxfd.h9
-rw-r--r--lib/parse_ini.c21
-rw-r--r--lib/tests/test_base64.c10
-rw-r--r--lib/tests/test_cmd.c10
-rw-r--r--lib/tests/test_disk.c38
-rw-r--r--lib/tests/test_ini1.c10
-rw-r--r--lib/tests/test_ini3.c10
-rw-r--r--lib/tests/test_opts2.c2
-rw-r--r--lib/tests/test_tcp.c14
-rw-r--r--lib/tests/test_utils.c97
-rw-r--r--lib/utils_base.c112
-rw-r--r--lib/utils_base.h12
-rw-r--r--lib/utils_cmd.c41
-rw-r--r--lib/utils_cmd.h17
-rw-r--r--lib/utils_disk.c119
-rw-r--r--lib/utils_disk.h18
-rw-r--r--lib/utils_tcp.c20
20 files changed, 360 insertions, 253 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 01d73a6..1a47395 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -7,7 +7,7 @@ noinst_LIBRARIES = libmonitoringplug.a
7AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \ 7AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \
8 -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins 8 -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
9 9
10libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c 10libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c maxfd.c
11EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h 11EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h
12 12
13if USE_PARSE_INI 13if USE_PARSE_INI
diff --git a/lib/extra_opts.c b/lib/extra_opts.c
index f4d5e66..771621d 100644
--- a/lib/extra_opts.c
+++ b/lib/extra_opts.c
@@ -1,23 +1,23 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring Plugins extra_opts library 3* Monitoring Plugins extra_opts library
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2007 Monitoring Plugins Development Team 6* Copyright (c) 2007 Monitoring Plugins Development Team
7* 7*
8* This program is free software: you can redistribute it and/or modify 8* This program is free software: you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by 9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation, either version 3 of the License, or 10* the Free Software Foundation, either version 3 of the License, or
11* (at your option) any later version. 11* (at your option) any later version.
12* 12*
13* This program is distributed in the hope that it will be useful, 13* This program is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of 14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16* GNU General Public License for more details. 16* GNU General Public License for more details.
17* 17*
18* You should have received a copy of the GNU General Public License 18* You should have received a copy of the GNU General Public License
19* along with this program. If not, see <http://www.gnu.org/licenses/>. 19* along with this program. If not, see <http://www.gnu.org/licenses/>.
20* 20*
21*****************************************************************************/ 21*****************************************************************************/
22 22
23#include "common.h" 23#include "common.h"
@@ -26,15 +26,14 @@
26#include "extra_opts.h" 26#include "extra_opts.h"
27 27
28/* FIXME: copied from utils.h; we should move a bunch of libs! */ 28/* FIXME: copied from utils.h; we should move a bunch of libs! */
29int 29bool is_option2 (char *str)
30is_option2 (char *str)
31{ 30{
32 if (!str) 31 if (!str)
33 return FALSE; 32 return false;
34 else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) 33 else if (strspn (str, "-") == 1 || strspn (str, "-") == 2)
35 return TRUE; 34 return true;
36 else 35 else
37 return FALSE; 36 return false;
38} 37}
39 38
40/* this is the externally visible function used by plugins */ 39/* this is the externally visible function used by plugins */
@@ -93,14 +92,14 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){
93 /* append the list to extra_args */ 92 /* append the list to extra_args */
94 if(extra_args==NULL){ 93 if(extra_args==NULL){
95 extra_args=ea1; 94 extra_args=ea1;
96 while(ea1=ea1->next) ea_num++; 95 while((ea1 = ea1->next)) ea_num++;
97 }else{ 96 }else{
98 ea_tmp=extra_args; 97 ea_tmp=extra_args;
99 while(ea_tmp->next) { 98 while(ea_tmp->next) {
100 ea_tmp=ea_tmp->next; 99 ea_tmp=ea_tmp->next;
101 } 100 }
102 ea_tmp->next=ea1; 101 ea_tmp->next=ea1;
103 while(ea1=ea1->next) ea_num++; 102 while((ea1 = ea1->next)) ea_num++;
104 } 103 }
105 ea1=ea_tmp=NULL; 104 ea1=ea_tmp=NULL;
106 } 105 }
diff --git a/lib/maxfd.c b/lib/maxfd.c
new file mode 100644
index 0000000..529b356
--- /dev/null
+++ b/lib/maxfd.c
@@ -0,0 +1,26 @@
1#include "./maxfd.h"
2#include <errno.h>
3
4long mp_open_max (void) {
5 long maxfd = 0L;
6 /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
7 * If that fails and the macro isn't defined, we fall back to an educated
8 * guess. There's no guarantee that our guess is adequate and the program
9 * will die with SIGSEGV if it isn't and the upper boundary is breached. */
10
11#ifdef _SC_OPEN_MAX
12 errno = 0;
13 if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) {
14 if (errno == 0)
15 maxfd = DEFAULT_MAXFD; /* it's indeterminate */
16 else
17 die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n"));
18 }
19#elif defined(OPEN_MAX)
20 return OPEN_MAX
21#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
22 return DEFAULT_MAXFD;
23#endif
24
25 return(maxfd);
26}
diff --git a/lib/maxfd.h b/lib/maxfd.h
new file mode 100644
index 0000000..45218d0
--- /dev/null
+++ b/lib/maxfd.h
@@ -0,0 +1,9 @@
1#ifndef _MAXFD_
2#define _MAXFD_
3
4#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */
5#define MAXFD_LIMIT 8192 /* upper limit of open files */
6
7long mp_open_max (void);
8
9#endif // _MAXFD_
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 547af43..0cc864a 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -1,24 +1,24 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring Plugins parse_ini library 3* Monitoring Plugins parse_ini library
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2007 Monitoring Plugins Development Team 6* Copyright (c) 2007 Monitoring Plugins Development Team
7* 7*
8* This program is free software: you can redistribute it and/or modify 8* This program is free software: you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by 9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation, either version 3 of the License, or 10* the Free Software Foundation, either version 3 of the License, or
11* (at your option) any later version. 11* (at your option) any later version.
12* 12*
13* This program is distributed in the hope that it will be useful, 13* This program is distributed in the hope that it will be useful,
14* but WITHOUT ANY WARRANTY; without even the implied warranty of 14* but WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16* GNU General Public License for more details. 16* GNU General Public License for more details.
17* 17*
18* You should have received a copy of the GNU General Public License 18* You should have received a copy of the GNU General Public License
19* along with this program. If not, see <http://www.gnu.org/licenses/>. 19* along with this program. If not, see <http://www.gnu.org/licenses/>.
20* 20*
21* 21*
22*****************************************************************************/ 22*****************************************************************************/
23 23
24#include "common.h" 24#include "common.h"
@@ -131,7 +131,7 @@ np_get_defaults(const char *locator, const char *default_section)
131 if (inifile == NULL) 131 if (inifile == NULL)
132 die(STATE_UNKNOWN, _("Can't read config file: %s\n"), 132 die(STATE_UNKNOWN, _("Can't read config file: %s\n"),
133 strerror(errno)); 133 strerror(errno));
134 if (read_defaults(inifile, i.stanza, &defaults) == FALSE) 134 if (!read_defaults(inifile, i.stanza, &defaults))
135 die(STATE_UNKNOWN, 135 die(STATE_UNKNOWN,
136 _("Invalid section '%s' in config file '%s'\n"), i.stanza, 136 _("Invalid section '%s' in config file '%s'\n"), i.stanza,
137 i.file); 137 i.file);
@@ -157,7 +157,8 @@ np_get_defaults(const char *locator, const char *default_section)
157static int 157static int
158read_defaults(FILE *f, const char *stanza, np_arg_list **opts) 158read_defaults(FILE *f, const char *stanza, np_arg_list **opts)
159{ 159{
160 int c, status = FALSE; 160 int c = 0;
161 bool status = false;
161 size_t i, stanza_len; 162 size_t i, stanza_len;
162 enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate = NOSTANZA; 163 enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate = NOSTANZA;
163 164
@@ -219,7 +220,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts)
219 die(STATE_UNKNOWN, "%s\n", 220 die(STATE_UNKNOWN, "%s\n",
220 _("Config file error")); 221 _("Config file error"));
221 } 222 }
222 status = TRUE; 223 status = true;
223 break; 224 break;
224 } 225 }
225 break; 226 break;
diff --git a/lib/tests/test_base64.c b/lib/tests/test_base64.c
index 5103d10..05dd794 100644
--- a/lib/tests/test_base64.c
+++ b/lib/tests/test_base64.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software: you can redistribute it and/or modify 3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6* (at your option) any later version.
7* 7*
8* This program is distributed in the hope that it will be useful, 8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "common.h" 19#include "common.h"
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c
index 4bb60aa..02ae11f 100644
--- a/lib/tests/test_cmd.c
+++ b/lib/tests/test_cmd.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software: you can redistribute it and/or modify 3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6* (at your option) any later version.
7* 7*
8* This program is distributed in the hope that it will be useful, 8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "common.h" 19#include "common.h"
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c
index 9bd68c7..e283fe2 100644
--- a/lib/tests/test_disk.c
+++ b/lib/tests/test_disk.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software: you can redistribute it and/or modify 3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6* (at your option) any later version.
7* 7*
8* This program is distributed in the hope that it will be useful, 8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "common.h" 19#include "common.h"
@@ -44,19 +44,19 @@ main (int argc, char **argv)
44 44
45 plan_tests(33); 45 plan_tests(33);
46 46
47 ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); 47 ok( np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list");
48 np_add_name(&exclude_filesystem, "/var/log"); 48 np_add_name(&exclude_filesystem, "/var/log");
49 ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "is in list now"); 49 ok( np_find_name(exclude_filesystem, "/var/log") == true, "is in list now");
50 ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list"); 50 ok( np_find_name(exclude_filesystem, "/home") == false, "/home not in list");
51 np_add_name(&exclude_filesystem, "/home"); 51 np_add_name(&exclude_filesystem, "/home");
52 ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now"); 52 ok( np_find_name(exclude_filesystem, "/home") == true, "is in list now");
53 ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "/var/log still in list"); 53 ok( np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list");
54 54
55 ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list"); 55 ok( np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list");
56 np_add_name(&exclude_fstype, "iso9660"); 56 np_add_name(&exclude_fstype, "iso9660");
57 ok( np_find_name(exclude_fstype, "iso9660") == TRUE, "is in list now"); 57 ok( np_find_name(exclude_fstype, "iso9660") == true, "is in list now");
58 58
59 ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables"); 59 ok( np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables");
60 60
61 /* 61 /*
62 for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { 62 for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) {
@@ -120,7 +120,7 @@ main (int argc, char **argv)
120 np_add_parameter(&paths, "/home/tonvoon"); 120 np_add_parameter(&paths, "/home/tonvoon");
121 np_add_parameter(&paths, "/dev/c2t0d0s0"); 121 np_add_parameter(&paths, "/dev/c2t0d0s0");
122 122
123 np_set_best_match(paths, dummy_mount_list, FALSE); 123 np_set_best_match(paths, dummy_mount_list, false);
124 for (p = paths; p; p = p->name_next) { 124 for (p = paths; p; p = p->name_next) {
125 struct mount_entry *temp_me; 125 struct mount_entry *temp_me;
126 temp_me = p->best_match; 126 temp_me = p->best_match;
@@ -144,7 +144,7 @@ main (int argc, char **argv)
144 np_add_parameter(&paths, "/home/tonvoon"); 144 np_add_parameter(&paths, "/home/tonvoon");
145 np_add_parameter(&paths, "/home"); 145 np_add_parameter(&paths, "/home");
146 146
147 np_set_best_match(paths, dummy_mount_list, TRUE); 147 np_set_best_match(paths, dummy_mount_list, true);
148 for (p = paths; p; p = p->name_next) { 148 for (p = paths; p; p = p->name_next) {
149 if (! strcmp(p->name, "/home/groups")) { 149 if (! strcmp(p->name, "/home/groups")) {
150 ok( ! p->best_match , "/home/groups correctly not found"); 150 ok( ! p->best_match , "/home/groups correctly not found");
@@ -167,7 +167,7 @@ main (int argc, char **argv)
167 } 167 }
168 ok(found == 0, "first element successfully deleted"); 168 ok(found == 0, "first element successfully deleted");
169 found = 0; 169 found = 0;
170 170
171 p=paths; 171 p=paths;
172 while (p) { 172 while (p) {
173 if (! strcmp(p->name, "/tmp")) 173 if (! strcmp(p->name, "/tmp"))
@@ -203,9 +203,9 @@ main (int argc, char **argv)
203} 203}
204 204
205 205
206void 206void
207np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) 207np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc)
208{ 208{
209 int matches = 0; 209 int matches = 0;
210 regex_t re; 210 regex_t re;
211 struct mount_entry *me; 211 struct mount_entry *me;
@@ -214,7 +214,7 @@ np_test_mount_entry_regex (struct mount_entry *dummy_mount_list, char *regstr, i
214 if(np_regex_match_mount_entry(me,&re)) 214 if(np_regex_match_mount_entry(me,&re))
215 matches++; 215 matches++;
216 } 216 }
217 ok( matches == expect, 217 ok( matches == expect,
218 "%s '%s' matched %i/3 entries. ok: %i/3", 218 "%s '%s' matched %i/3 entries. ok: %i/3",
219 desc, regstr, expect, matches); 219 desc, regstr, expect, matches);
220 220
diff --git a/lib/tests/test_ini1.c b/lib/tests/test_ini1.c
index 77f8854..6843bac 100644
--- a/lib/tests/test_ini1.c
+++ b/lib/tests/test_ini1.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software: you can redistribute it and/or modify 3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6* (at your option) any later version.
7* 7*
8* This program is distributed in the hope that it will be useful, 8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "common.h" 19#include "common.h"
diff --git a/lib/tests/test_ini3.c b/lib/tests/test_ini3.c
index 814b3ec..8a2a041 100644
--- a/lib/tests/test_ini3.c
+++ b/lib/tests/test_ini3.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software: you can redistribute it and/or modify 3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6* (at your option) any later version.
7* 7*
8* This program is distributed in the hope that it will be useful, 8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "parse_ini.h" 19#include "parse_ini.h"
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c
index c3d2067..780220e 100644
--- a/lib/tests/test_opts2.c
+++ b/lib/tests/test_opts2.c
@@ -12,7 +12,7 @@
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16*****************************************************************************/ 16*****************************************************************************/
17 17
18#include "common.h" 18#include "common.h"
diff --git a/lib/tests/test_tcp.c b/lib/tests/test_tcp.c
index 114252b..1954b0f 100644
--- a/lib/tests/test_tcp.c
+++ b/lib/tests/test_tcp.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software: you can redistribute it and/or modify 3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6* (at your option) any later version.
7* 7*
8* This program is distributed in the hope that it will be useful, 8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "common.h" 19#include "common.h"
@@ -33,7 +33,7 @@ main(void)
33 server_expect[0] = strdup("AA"); 33 server_expect[0] = strdup("AA");
34 server_expect[1] = strdup("bb"); 34 server_expect[1] = strdup("bb");
35 server_expect[2] = strdup("CC"); 35 server_expect[2] = strdup("CC");
36 36
37 ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS, 37 ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
38 "Test matching any string at the beginning (first expect string)"); 38 "Test matching any string at the beginning (first expect string)");
39 ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS, 39 ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
@@ -52,7 +52,7 @@ main(void)
52 "Test not matching all strings"); 52 "Test not matching all strings");
53 ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, 53 ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY,
54 "Test not matching any string (testing all)"); 54 "Test not matching any string (testing all)");
55 55
56 56
57 return exit_status(); 57 return exit_status();
58} 58}
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 7b10494..01afacd 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software: you can redistribute it and/or modify 3* This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4* it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5* the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6* (at your option) any later version.
7* 7*
8* This program is distributed in the hope that it will be useful, 8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11* GNU General Public License for more details.
12* 12*
13* You should have received a copy of the GNU General Public License 13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15*
16* 16*
17*****************************************************************************/ 17*****************************************************************************/
18 18
19#include "common.h" 19#include "common.h"
@@ -62,99 +62,99 @@ main (int argc, char **argv)
62 range = parse_range_string("6"); 62 range = parse_range_string("6");
63 ok( range != NULL, "'6' is valid range"); 63 ok( range != NULL, "'6' is valid range");
64 ok( range->start == 0, "Start correct"); 64 ok( range->start == 0, "Start correct");
65 ok( range->start_infinity == FALSE, "Not using negative infinity"); 65 ok( range->start_infinity == false, "Not using negative infinity");
66 ok( range->end == 6, "End correct"); 66 ok( range->end == 6, "End correct");
67 ok( range->end_infinity == FALSE, "Not using infinity"); 67 ok( range->end_infinity == false, "Not using infinity");
68 free(range); 68 free(range);
69 69
70 range = parse_range_string("1:12%%"); 70 range = parse_range_string("1:12%%");
71 ok( range != NULL, "'1:12%%' is valid - percentages are ignored"); 71 ok( range != NULL, "'1:12%%' is valid - percentages are ignored");
72 ok( range->start == 1, "Start correct"); 72 ok( range->start == 1, "Start correct");
73 ok( range->start_infinity == FALSE, "Not using negative infinity"); 73 ok( range->start_infinity == false, "Not using negative infinity");
74 ok( range->end == 12, "End correct"); 74 ok( range->end == 12, "End correct");
75 ok( range->end_infinity == FALSE, "Not using infinity"); 75 ok( range->end_infinity == false, "Not using infinity");
76 free(range); 76 free(range);
77 77
78 range = parse_range_string("-7:23"); 78 range = parse_range_string("-7:23");
79 ok( range != NULL, "'-7:23' is valid range"); 79 ok( range != NULL, "'-7:23' is valid range");
80 ok( range->start == -7, "Start correct"); 80 ok( range->start == -7, "Start correct");
81 ok( range->start_infinity == FALSE, "Not using negative infinity"); 81 ok( range->start_infinity == false, "Not using negative infinity");
82 ok( range->end == 23, "End correct"); 82 ok( range->end == 23, "End correct");
83 ok( range->end_infinity == FALSE, "Not using infinity"); 83 ok( range->end_infinity == false, "Not using infinity");
84 free(range); 84 free(range);
85 85
86 range = parse_range_string(":5.75"); 86 range = parse_range_string(":5.75");
87 ok( range != NULL, "':5.75' is valid range"); 87 ok( range != NULL, "':5.75' is valid range");
88 ok( range->start == 0, "Start correct"); 88 ok( range->start == 0, "Start correct");
89 ok( range->start_infinity == FALSE, "Not using negative infinity"); 89 ok( range->start_infinity == false, "Not using negative infinity");
90 ok( range->end == 5.75, "End correct"); 90 ok( range->end == 5.75, "End correct");
91 ok( range->end_infinity == FALSE, "Not using infinity"); 91 ok( range->end_infinity == false, "Not using infinity");
92 free(range); 92 free(range);
93 93
94 range = parse_range_string("~:-95.99"); 94 range = parse_range_string("~:-95.99");
95 ok( range != NULL, "~:-95.99' is valid range"); 95 ok( range != NULL, "~:-95.99' is valid range");
96 ok( range->start_infinity == TRUE, "Using negative infinity"); 96 ok( range->start_infinity == true, "Using negative infinity");
97 ok( range->end == -95.99, "End correct (with rounding errors)"); 97 ok( range->end == -95.99, "End correct (with rounding errors)");
98 ok( range->end_infinity == FALSE, "Not using infinity"); 98 ok( range->end_infinity == false, "Not using infinity");
99 free(range); 99 free(range);
100 100
101 range = parse_range_string("12345678901234567890:"); 101 range = parse_range_string("12345678901234567890:");
102 temp = atof("12345678901234567890"); /* Can't just use this because number too large */ 102 temp = atof("12345678901234567890"); /* Can't just use this because number too large */
103 ok( range != NULL, "'12345678901234567890:' is valid range"); 103 ok( range != NULL, "'12345678901234567890:' is valid range");
104 ok( range->start == temp, "Start correct"); 104 ok( range->start == temp, "Start correct");
105 ok( range->start_infinity == FALSE, "Not using negative infinity"); 105 ok( range->start_infinity == false, "Not using negative infinity");
106 ok( range->end_infinity == TRUE, "Using infinity"); 106 ok( range->end_infinity == true, "Using infinity");
107 /* Cannot do a "-1" on temp, as it appears to be same value */ 107 /* Cannot do a "-1" on temp, as it appears to be same value */
108 ok( check_range(temp/1.1, range) == TRUE, "12345678901234567890/1.1 - alert"); 108 ok( check_range(temp/1.1, range) == true, "12345678901234567890/1.1 - alert");
109 ok( check_range(temp, range) == FALSE, "12345678901234567890 - no alert"); 109 ok( check_range(temp, range) == false, "12345678901234567890 - no alert");
110 ok( check_range(temp*2, range) == FALSE, "12345678901234567890*2 - no alert"); 110 ok( check_range(temp*2, range) == false, "12345678901234567890*2 - no alert");
111 free(range); 111 free(range);
112 112
113 range = parse_range_string("~:0"); 113 range = parse_range_string("~:0");
114 ok( range != NULL, "'~:0' is valid range"); 114 ok( range != NULL, "'~:0' is valid range");
115 ok( range->start_infinity == TRUE, "Using negative infinity"); 115 ok( range->start_infinity == true, "Using negative infinity");
116 ok( range->end == 0, "End correct"); 116 ok( range->end == 0, "End correct");
117 ok( range->end_infinity == FALSE, "Not using infinity"); 117 ok( range->end_infinity == false, "Not using infinity");
118 ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); 118 ok( range->alert_on == OUTSIDE, "Will alert on outside of this range");
119 ok( check_range(0.5, range) == TRUE, "0.5 - alert"); 119 ok( check_range(0.5, range) == true, "0.5 - alert");
120 ok( check_range(-10, range) == FALSE, "-10 - no alert"); 120 ok( check_range(-10, range) == false, "-10 - no alert");
121 ok( check_range(0, range) == FALSE, "0 - no alert"); 121 ok( check_range(0, range) == false, "0 - no alert");
122 free(range); 122 free(range);
123 123
124 range = parse_range_string("@0:657.8210567"); 124 range = parse_range_string("@0:657.8210567");
125 ok( range != 0, "@0:657.8210567' is a valid range"); 125 ok( range != 0, "@0:657.8210567' is a valid range");
126 ok( range->start == 0, "Start correct"); 126 ok( range->start == 0, "Start correct");
127 ok( range->start_infinity == FALSE, "Not using negative infinity"); 127 ok( range->start_infinity == false, "Not using negative infinity");
128 ok( range->end == 657.8210567, "End correct"); 128 ok( range->end == 657.8210567, "End correct");
129 ok( range->end_infinity == FALSE, "Not using infinity"); 129 ok( range->end_infinity == false, "Not using infinity");
130 ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); 130 ok( range->alert_on == INSIDE, "Will alert on inside of this range" );
131 ok( check_range(32.88, range) == TRUE, "32.88 - alert"); 131 ok( check_range(32.88, range) == true, "32.88 - alert");
132 ok( check_range(-2, range) == FALSE, "-2 - no alert"); 132 ok( check_range(-2, range) == false, "-2 - no alert");
133 ok( check_range(657.8210567, range) == TRUE, "657.8210567 - alert"); 133 ok( check_range(657.8210567, range) == true, "657.8210567 - alert");
134 ok( check_range(0, range) == TRUE, "0 - alert"); 134 ok( check_range(0, range) == true, "0 - alert");
135 free(range); 135 free(range);
136 136
137 range = parse_range_string("@1:1"); 137 range = parse_range_string("@1:1");
138 ok( range != NULL, "'@1:1' is a valid range"); 138 ok( range != NULL, "'@1:1' is a valid range");
139 ok( range->start == 1, "Start correct"); 139 ok( range->start == 1, "Start correct");
140 ok( range->start_infinity == FALSE, "Not using negative infinity"); 140 ok( range->start_infinity == false, "Not using negative infinity");
141 ok( range->end == 1, "End correct"); 141 ok( range->end == 1, "End correct");
142 ok( range->end_infinity == FALSE, "Not using infinity"); 142 ok( range->end_infinity == false, "Not using infinity");
143 ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); 143 ok( range->alert_on == INSIDE, "Will alert on inside of this range" );
144 ok( check_range(0.5, range) == FALSE, "0.5 - no alert"); 144 ok( check_range(0.5, range) == false, "0.5 - no alert");
145 ok( check_range(1, range) == TRUE, "1 - alert"); 145 ok( check_range(1, range) == true, "1 - alert");
146 ok( check_range(5.2, range) == FALSE, "5.2 - no alert"); 146 ok( check_range(5.2, range) == false, "5.2 - no alert");
147 free(range); 147 free(range);
148 148
149 range = parse_range_string("1:1"); 149 range = parse_range_string("1:1");
150 ok( range != NULL, "'1:1' is a valid range"); 150 ok( range != NULL, "'1:1' is a valid range");
151 ok( range->start == 1, "Start correct"); 151 ok( range->start == 1, "Start correct");
152 ok( range->start_infinity == FALSE, "Not using negative infinity"); 152 ok( range->start_infinity == false, "Not using negative infinity");
153 ok( range->end == 1, "End correct"); 153 ok( range->end == 1, "End correct");
154 ok( range->end_infinity == FALSE, "Not using infinity"); 154 ok( range->end_infinity == false, "Not using infinity");
155 ok( check_range(0.5, range) == TRUE, "0.5 - alert"); 155 ok( check_range(0.5, range) == true, "0.5 - alert");
156 ok( check_range(1, range) == FALSE, "1 - no alert"); 156 ok( check_range(1, range) == false, "1 - no alert");
157 ok( check_range(5.2, range) == TRUE, "5.2 - alert"); 157 ok( check_range(5.2, range) == true, "5.2 - alert");
158 free(range); 158 free(range);
159 159
160 range = parse_range_string("2:1"); 160 range = parse_range_string("2:1");
@@ -377,13 +377,13 @@ main (int argc, char **argv)
377 377
378/* 378/*
379 temp_fp = fopen("var/statefile", "r"); 379 temp_fp = fopen("var/statefile", "r");
380 if (temp_fp==NULL) 380 if (temp_fp==NULL)
381 printf("Error opening. errno=%d\n", errno); 381 printf("Error opening. errno=%d\n", errno);
382 printf("temp_fp=%s\n", temp_fp); 382 printf("temp_fp=%s\n", temp_fp);
383 ok( _np_state_read_file(temp_fp) == TRUE, "Can read state file" ); 383 ok( _np_state_read_file(temp_fp) == true, "Can read state file" );
384 fclose(temp_fp); 384 fclose(temp_fp);
385*/ 385*/
386 386
387 temp_state_key->_filename="var/statefile"; 387 temp_state_key->_filename="var/statefile";
388 temp_state_data = np_state_read(); 388 temp_state_data = np_state_read();
389 ok( this_monitoring_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not"); 389 ok( this_monitoring_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not");
@@ -446,20 +446,20 @@ main (int argc, char **argv)
446 /* Check time is set to current_time */ 446 /* Check time is set to current_time */
447 ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); 447 ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time");
448 ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); 448 ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time");
449 449
450 450
451 /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ 451 /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */
452 /* 452 /*
453 temp_state_key->_filename="/dev/do/not/expect/to/be/able/to/write"; 453 temp_state_key->_filename="/dev/do/not/expect/to/be/able/to/write";
454 np_state_write_string(0, "Bad file"); 454 np_state_write_string(0, "Bad file");
455 */ 455 */
456 456
457 457
458 np_cleanup(); 458 np_cleanup();
459 459
460 ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin"); 460 ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin");
461 461
462 ok(mp_suid() == FALSE, "Test aren't suid"); 462 ok(mp_suid() == false, "Test aren't suid");
463 463
464 /* base states with random case */ 464 /* base states with random case */
465 char *states[] = { 465 char *states[] = {
@@ -508,4 +508,3 @@ main (int argc, char **argv)
508 508
509 return exit_status(); 509 return exit_status();
510} 510}
511
diff --git a/lib/utils_base.c b/lib/utils_base.c
index c458cf6..f86efbe 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -6,21 +6,21 @@
6* Copyright (c) 2006 Monitoring Plugins Development Team 6* Copyright (c) 2006 Monitoring Plugins Development Team
7* 7*
8* Library of useful functions for plugins 8* Library of useful functions for plugins
9* 9*
10* 10*
11* This program is free software: you can redistribute it and/or modify 11* This program is free software: you can redistribute it and/or modify
12* it under the terms of the GNU General Public License as published by 12* it under the terms of the GNU General Public License as published by
13* the Free Software Foundation, either version 3 of the License, or 13* the Free Software Foundation, either version 3 of the License, or
14* (at your option) any later version. 14* (at your option) any later version.
15* 15*
16* This program is distributed in the hope that it will be useful, 16* This program is distributed in the hope that it will be useful,
17* but WITHOUT ANY WARRANTY; without even the implied warranty of 17* but WITHOUT ANY WARRANTY; without even the implied warranty of
18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19* GNU General Public License for more details. 19* GNU General Public License for more details.
20* 20*
21* You should have received a copy of the GNU General Public License 21* You should have received a copy of the GNU General Public License
22* along with this program. If not, see <http://www.gnu.org/licenses/>. 22* along with this program. If not, see <http://www.gnu.org/licenses/>.
23* 23*
24* 24*
25*****************************************************************************/ 25*****************************************************************************/
26 26
@@ -40,7 +40,7 @@ monitoring_plugin *this_monitoring_plugin=NULL;
40unsigned int timeout_state = STATE_CRITICAL; 40unsigned int timeout_state = STATE_CRITICAL;
41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; 41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
42 42
43int _np_state_read_file(FILE *); 43bool _np_state_read_file(FILE *);
44 44
45void np_init( char *plugin_name, int argc, char **argv ) { 45void np_init( char *plugin_name, int argc, char **argv ) {
46 if (this_monitoring_plugin==NULL) { 46 if (this_monitoring_plugin==NULL) {
@@ -105,12 +105,12 @@ die (int result, const char *fmt, ...)
105 105
106void set_range_start (range *this, double value) { 106void set_range_start (range *this, double value) {
107 this->start = value; 107 this->start = value;
108 this->start_infinity = FALSE; 108 this->start_infinity = false;
109} 109}
110 110
111void set_range_end (range *this, double value) { 111void set_range_end (range *this, double value) {
112 this->end = value; 112 this->end = value;
113 this->end_infinity = FALSE; 113 this->end_infinity = false;
114} 114}
115 115
116range 116range
@@ -124,9 +124,9 @@ range
124 124
125 /* Set defaults */ 125 /* Set defaults */
126 temp_range->start = 0; 126 temp_range->start = 0;
127 temp_range->start_infinity = FALSE; 127 temp_range->start_infinity = false;
128 temp_range->end = 0; 128 temp_range->end = 0;
129 temp_range->end_infinity = TRUE; 129 temp_range->end_infinity = true;
130 temp_range->alert_on = OUTSIDE; 130 temp_range->alert_on = OUTSIDE;
131 temp_range->text = strdup(str); 131 temp_range->text = strdup(str);
132 132
@@ -138,7 +138,7 @@ range
138 end_str = index(str, ':'); 138 end_str = index(str, ':');
139 if (end_str != NULL) { 139 if (end_str != NULL) {
140 if (str[0] == '~') { 140 if (str[0] == '~') {
141 temp_range->start_infinity = TRUE; 141 temp_range->start_infinity = true;
142 } else { 142 } else {
143 start = strtod(str, NULL); /* Will stop at the ':' */ 143 start = strtod(str, NULL); /* Will stop at the ':' */
144 set_range_start(temp_range, start); 144 set_range_start(temp_range, start);
@@ -152,8 +152,8 @@ range
152 set_range_end(temp_range, end); 152 set_range_end(temp_range, end);
153 } 153 }
154 154
155 if (temp_range->start_infinity == TRUE || 155 if (temp_range->start_infinity == true ||
156 temp_range->end_infinity == TRUE || 156 temp_range->end_infinity == true ||
157 temp_range->start <= temp_range->end) { 157 temp_range->start <= temp_range->end) {
158 return temp_range; 158 return temp_range;
159 } 159 }
@@ -223,31 +223,30 @@ void print_thresholds(const char *threshold_name, thresholds *my_threshold) {
223 printf("\n"); 223 printf("\n");
224} 224}
225 225
226/* Returns TRUE if alert should be raised based on the range */ 226/* Returns true if alert should be raised based on the range */
227int 227bool check_range(double value, range *my_range)
228check_range(double value, range *my_range)
229{ 228{
230 int no = FALSE; 229 bool no = false;
231 int yes = TRUE; 230 bool yes = true;
232 231
233 if (my_range->alert_on == INSIDE) { 232 if (my_range->alert_on == INSIDE) {
234 no = TRUE; 233 no = true;
235 yes = FALSE; 234 yes = false;
236 } 235 }
237 236
238 if (my_range->end_infinity == FALSE && my_range->start_infinity == FALSE) { 237 if (my_range->end_infinity == false && my_range->start_infinity == false) {
239 if ((my_range->start <= value) && (value <= my_range->end)) { 238 if ((my_range->start <= value) && (value <= my_range->end)) {
240 return no; 239 return no;
241 } else { 240 } else {
242 return yes; 241 return yes;
243 } 242 }
244 } else if (my_range->start_infinity == FALSE && my_range->end_infinity == TRUE) { 243 } else if (my_range->start_infinity == false && my_range->end_infinity == true) {
245 if (my_range->start <= value) { 244 if (my_range->start <= value) {
246 return no; 245 return no;
247 } else { 246 } else {
248 return yes; 247 return yes;
249 } 248 }
250 } else if (my_range->start_infinity == TRUE && my_range->end_infinity == FALSE) { 249 } else if (my_range->start_infinity == true && my_range->end_infinity == false) {
251 if (value <= my_range->end) { 250 if (value <= my_range->end) {
252 return no; 251 return no;
253 } else { 252 } else {
@@ -263,12 +262,12 @@ int
263get_status(double value, thresholds *my_thresholds) 262get_status(double value, thresholds *my_thresholds)
264{ 263{
265 if (my_thresholds->critical != NULL) { 264 if (my_thresholds->critical != NULL) {
266 if (check_range(value, my_thresholds->critical) == TRUE) { 265 if (check_range(value, my_thresholds->critical) == true) {
267 return STATE_CRITICAL; 266 return STATE_CRITICAL;
268 } 267 }
269 } 268 }
270 if (my_thresholds->warning != NULL) { 269 if (my_thresholds->warning != NULL) {
271 if (check_range(value, my_thresholds->warning) == TRUE) { 270 if (check_range(value, my_thresholds->warning) == true) {
272 return STATE_WARNING; 271 return STATE_WARNING;
273 } 272 }
274 } 273 }
@@ -332,7 +331,7 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
332 /* strip leading spaces */ 331 /* strip leading spaces */
333 for (; isspace(varlist[0]); varlist++); 332 for (; isspace(varlist[0]); varlist++);
334 333
335 if (tmp = index(varlist, sep)) { 334 if ((tmp = index(varlist, sep))) {
336 /* Value is delimited by a comma */ 335 /* Value is delimited by a comma */
337 if (tmp-varlist == 0) continue; 336 if (tmp-varlist == 0) continue;
338 value = (char *)calloc(1, tmp-varlist+1); 337 value = (char *)calloc(1, tmp-varlist+1);
@@ -348,7 +347,7 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
348 break; 347 break;
349 } 348 }
350 } 349 }
351 if (tmp = index(varlist, sep)) { 350 if ((tmp = index(varlist, sep))) {
352 /* More keys, keep going... */ 351 /* More keys, keep going... */
353 varlist = tmp + 1; 352 varlist = tmp + 1;
354 } else { 353 } else {
@@ -402,26 +401,45 @@ int mp_translate_state (char *state_text) {
402 * parse of argv, so that uniqueness in parameters are reflected there. 401 * parse of argv, so that uniqueness in parameters are reflected there.
403 */ 402 */
404char *_np_state_generate_key() { 403char *_np_state_generate_key() {
405 struct sha256_ctx ctx;
406 int i; 404 int i;
407 char **argv = this_monitoring_plugin->argv; 405 char **argv = this_monitoring_plugin->argv;
408 unsigned char result[20];
409 char keyname[41]; 406 char keyname[41];
410 char *p=NULL; 407 char *p=NULL;
411 408
412 sha256_init_ctx(&ctx); 409 unsigned char result[256];
413 410
411#ifdef USE_OPENSSL
412 /*
413 * This code path is chosen if openssl is available (which should be the most common
414 * scenario). Alternatively, the gnulib implementation/
415 *
416 */
417 EVP_MD_CTX *ctx = EVP_MD_CTX_new();
418
419 EVP_DigestInit(ctx, EVP_sha256());
420
421 for(i=0; i<this_monitoring_plugin->argc; i++) {
422 EVP_DigestUpdate(ctx, argv[i], strlen(argv[i]));
423 }
424
425 EVP_DigestFinal(ctx, result, NULL);
426#else
427
428 struct sha256_ctx ctx;
429
414 for(i=0; i<this_monitoring_plugin->argc; i++) { 430 for(i=0; i<this_monitoring_plugin->argc; i++) {
415 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx); 431 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx);
416 } 432 }
417 433
418 sha256_finish_ctx(&ctx, &result); 434 sha256_finish_ctx(&ctx, result);
419 435#endif // FOUNDOPENSSL
436
420 for (i=0; i<20; ++i) { 437 for (i=0; i<20; ++i) {
421 sprintf(&keyname[2*i], "%02x", result[i]); 438 sprintf(&keyname[2*i], "%02x", result[i]);
422 } 439 }
440
423 keyname[40]='\0'; 441 keyname[40]='\0';
424 442
425 p = strdup(keyname); 443 p = strdup(keyname);
426 if(p==NULL) { 444 if(p==NULL) {
427 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); 445 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
@@ -446,7 +464,7 @@ char* _np_state_calculate_location_prefix(){
446 464
447 /* Do not allow passing MP_STATE_PATH in setuid plugins 465 /* Do not allow passing MP_STATE_PATH in setuid plugins
448 * for security reasons */ 466 * for security reasons */
449 if (mp_suid() == FALSE) { 467 if (!mp_suid()) {
450 env_dir = getenv("MP_STATE_PATH"); 468 env_dir = getenv("MP_STATE_PATH");
451 if(env_dir && env_dir[0] != '\0') 469 if(env_dir && env_dir[0] != '\0')
452 return env_dir; 470 return env_dir;
@@ -522,7 +540,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
522state_data *np_state_read() { 540state_data *np_state_read() {
523 state_data *this_state_data=NULL; 541 state_data *this_state_data=NULL;
524 FILE *statefile; 542 FILE *statefile;
525 int rc = FALSE; 543 bool rc = false;
526 544
527 if(this_monitoring_plugin==NULL) 545 if(this_monitoring_plugin==NULL)
528 die(STATE_UNKNOWN, _("This requires np_init to be called")); 546 die(STATE_UNKNOWN, _("This requires np_init to be called"));
@@ -544,7 +562,7 @@ state_data *np_state_read() {
544 fclose(statefile); 562 fclose(statefile);
545 } 563 }
546 564
547 if(rc==FALSE) { 565 if(!rc) {
548 _cleanup_state_data(); 566 _cleanup_state_data();
549 } 567 }
550 568
@@ -554,8 +572,8 @@ state_data *np_state_read() {
554/* 572/*
555 * Read the state file 573 * Read the state file
556 */ 574 */
557int _np_state_read_file(FILE *f) { 575bool _np_state_read_file(FILE *f) {
558 int status=FALSE; 576 bool status = false;
559 size_t pos; 577 size_t pos;
560 char *line; 578 char *line;
561 int i; 579 int i;
@@ -609,7 +627,7 @@ int _np_state_read_file(FILE *f) {
609 if(this_monitoring_plugin->state->state_data->data==NULL) 627 if(this_monitoring_plugin->state->state_data->data==NULL)
610 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); 628 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
611 expected=STATE_DATA_END; 629 expected=STATE_DATA_END;
612 status=TRUE; 630 status=true;
613 break; 631 break;
614 case STATE_DATA_END: 632 case STATE_DATA_END:
615 ; 633 ;
@@ -621,10 +639,10 @@ int _np_state_read_file(FILE *f) {
621} 639}
622 640
623/* 641/*
624 * If time=NULL, use current time. Create state file, with state format 642 * If time=NULL, use current time. Create state file, with state format
625 * version, default text. Writes version, time, and data. Avoid locking 643 * version, default text. Writes version, time, and data. Avoid locking
626 * problems - use mv to write and then swap. Possible loss of state data if 644 * problems - use mv to write and then swap. Possible loss of state data if
627 * two things writing to same key at same time. 645 * two things writing to same key at same time.
628 * Will die with UNKNOWN if errors 646 * Will die with UNKNOWN if errors
629 */ 647 */
630void np_state_write_string(time_t data_time, char *data_string) { 648void np_state_write_string(time_t data_time, char *data_string) {
@@ -639,7 +657,7 @@ void np_state_write_string(time_t data_time, char *data_string) {
639 time(&current_time); 657 time(&current_time);
640 else 658 else
641 current_time=data_time; 659 current_time=data_time;
642 660
643 /* If file doesn't currently exist, create directories */ 661 /* If file doesn't currently exist, create directories */
644 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) { 662 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) {
645 result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); 663 result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
@@ -678,15 +696,15 @@ void np_state_write_string(time_t data_time, char *data_string) {
678 np_free(temp_file); 696 np_free(temp_file);
679 die(STATE_UNKNOWN, _("Unable to open temporary state file")); 697 die(STATE_UNKNOWN, _("Unable to open temporary state file"));
680 } 698 }
681 699
682 fprintf(fp,"# NP State file\n"); 700 fprintf(fp,"# NP State file\n");
683 fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION); 701 fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION);
684 fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version); 702 fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version);
685 fprintf(fp,"%lu\n",current_time); 703 fprintf(fp,"%lu\n",current_time);
686 fprintf(fp,"%s\n",data_string); 704 fprintf(fp,"%s\n",data_string);
687 705
688 fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP); 706 fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP);
689 707
690 fflush(fp); 708 fflush(fp);
691 709
692 result=fclose(fp); 710 result=fclose(fp);
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 5906550..80b8743 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -2,9 +2,11 @@
2#define _UTILS_BASE_ 2#define _UTILS_BASE_
3/* Header file for Monitoring Plugins utils_base.c */ 3/* Header file for Monitoring Plugins utils_base.c */
4 4
5#include "sha256.h" 5#ifndef USE_OPENSSL
6# include "sha256.h"
7#endif
6 8
7/* This file holds header information for thresholds - use this in preference to 9/* This file holds header information for thresholds - use this in preference to
8 individual plugin logic */ 10 individual plugin logic */
9 11
10/* This has not been merged with utils.h because of problems with 12/* This has not been merged with utils.h because of problems with
@@ -19,7 +21,7 @@
19 21
20typedef struct range_struct { 22typedef struct range_struct {
21 double start; 23 double start;
22 int start_infinity; /* FALSE (default) or TRUE */ 24 bool start_infinity;
23 double end; 25 double end;
24 int end_infinity; 26 int end_infinity;
25 int alert_on; /* OUTSIDE (default) or INSIDE */ 27 int alert_on; /* OUTSIDE (default) or INSIDE */
@@ -59,7 +61,7 @@ range *parse_range_string (char *);
59int _set_thresholds(thresholds **, char *, char *); 61int _set_thresholds(thresholds **, char *, char *);
60void set_thresholds(thresholds **, char *, char *); 62void set_thresholds(thresholds **, char *, char *);
61void print_thresholds(const char *, thresholds *); 63void print_thresholds(const char *, thresholds *);
62int check_range(double, range *); 64bool check_range(double, range *);
63int get_status(double, thresholds *); 65int get_status(double, thresholds *);
64 66
65/* Handle timeouts */ 67/* Handle timeouts */
@@ -77,7 +79,7 @@ void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)))
77#define NP_RANGE_UNPARSEABLE 1 79#define NP_RANGE_UNPARSEABLE 1
78#define NP_WARN_WITHIN_CRIT 2 80#define NP_WARN_WITHIN_CRIT 2
79 81
80/* a simple check to see if we're running as root. 82/* a simple check to see if we're running as root.
81 * returns zero on failure, nonzero on success */ 83 * returns zero on failure, nonzero on success */
82int np_check_if_root(void); 84int np_check_if_root(void);
83 85
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index 8b8e570..cfb2073 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -18,18 +18,18 @@
18* Care has been taken to make sure the functions are async-safe. The one 18* Care has been taken to make sure the functions are async-safe. The one
19* function which isn't is cmd_init() which it doesn't make sense to 19* function which isn't is cmd_init() which it doesn't make sense to
20* call twice anyway, so the api as a whole should be considered async-safe. 20* call twice anyway, so the api as a whole should be considered async-safe.
21* 21*
22* 22*
23* This program is free software: you can redistribute it and/or modify 23* This program is free software: you can redistribute it and/or modify
24* it under the terms of the GNU General Public License as published by 24* it under the terms of the GNU General Public License as published by
25* the Free Software Foundation, either version 3 of the License, or 25* the Free Software Foundation, either version 3 of the License, or
26* (at your option) any later version. 26* (at your option) any later version.
27* 27*
28* This program is distributed in the hope that it will be useful, 28* This program is distributed in the hope that it will be useful,
29* but WITHOUT ANY WARRANTY; without even the implied warranty of 29* but WITHOUT ANY WARRANTY; without even the implied warranty of
30* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31* GNU General Public License for more details. 31* GNU General Public License for more details.
32* 32*
33* You should have received a copy of the GNU General Public License 33* You should have received a copy of the GNU General Public License
34* along with this program. If not, see <http://www.gnu.org/licenses/>. 34* along with this program. If not, see <http://www.gnu.org/licenses/>.
35* 35*
@@ -42,7 +42,20 @@
42#include "common.h" 42#include "common.h"
43#include "utils.h" 43#include "utils.h"
44#include "utils_cmd.h" 44#include "utils_cmd.h"
45/* This variable must be global, since there's no way the caller
46 * can forcibly slay a dead or ungainly running program otherwise.
47 * Multithreading apps and plugins can initialize it (via CMD_INIT)
48 * in an async safe manner PRIOR to calling cmd_run() or cmd_run_array()
49 * for the first time.
50 *
51 * The check for initialized values is atomic and can
52 * occur in any number of threads simultaneously. */
53static pid_t *_cmd_pids = NULL;
54
45#include "utils_base.h" 55#include "utils_base.h"
56
57#include "./maxfd.h"
58
46#include <fcntl.h> 59#include <fcntl.h>
47 60
48#ifdef HAVE_SYS_WAIT_H 61#ifdef HAVE_SYS_WAIT_H
@@ -86,13 +99,7 @@ extern void die (int, const char *, ...)
86void 99void
87cmd_init (void) 100cmd_init (void)
88{ 101{
89#ifndef maxfd 102 long maxfd = mp_open_max();
90 if (!maxfd && (maxfd = sysconf (_SC_OPEN_MAX)) < 0) {
91 /* possibly log or emit a warning here, since there's no
92 * guarantee that our guess at maxfd will be adequate */
93 maxfd = DEFAULT_MAXFD;
94 }
95#endif
96 103
97 /* if maxfd is unnaturally high, we force it to a lower value 104 /* if maxfd is unnaturally high, we force it to a lower value
98 * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause 105 * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause
@@ -118,10 +125,6 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
118 125
119 int i = 0; 126 int i = 0;
120 127
121 /* if no command was passed, return with no error */
122 if (argv == NULL)
123 return -1;
124
125 if (!_cmd_pids) 128 if (!_cmd_pids)
126 CMD_INIT; 129 CMD_INIT;
127 130
@@ -152,6 +155,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr)
152 /* close all descriptors in _cmd_pids[] 155 /* close all descriptors in _cmd_pids[]
153 * This is executed in a separate address space (pure child), 156 * This is executed in a separate address space (pure child),
154 * so we don't have to worry about async safety */ 157 * so we don't have to worry about async safety */
158 long maxfd = mp_open_max();
155 for (i = 0; i < maxfd; i++) 159 for (i = 0; i < maxfd; i++)
156 if (_cmd_pids[i] > 0) 160 if (_cmd_pids[i] > 0)
157 close (i); 161 close (i);
@@ -178,6 +182,7 @@ _cmd_close (int fd)
178 pid_t pid; 182 pid_t pid;
179 183
180 /* make sure the provided fd was opened */ 184 /* make sure the provided fd was opened */
185 long maxfd = mp_open_max();
181 if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0) 186 if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0)
182 return -1; 187 return -1;
183 188
@@ -269,7 +274,6 @@ _cmd_fetch_output (int fd, output * op, int flags)
269int 274int
270cmd_run (const char *cmdstring, output * out, output * err, int flags) 275cmd_run (const char *cmdstring, output * out, output * err, int flags)
271{ 276{
272 int fd, pfd_out[2], pfd_err[2];
273 int i = 0, argc; 277 int i = 0, argc;
274 size_t cmdlen; 278 size_t cmdlen;
275 char **argv = NULL; 279 char **argv = NULL;
@@ -373,10 +377,10 @@ cmd_file_read ( char *filename, output *out, int flags)
373 if ((fd = open(filename, O_RDONLY)) == -1) { 377 if ((fd = open(filename, O_RDONLY)) == -1) {
374 die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) ); 378 die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) );
375 } 379 }
376 380
377 if(out) 381 if(out)
378 out->lines = _cmd_fetch_output (fd, out, flags); 382 out->lines = _cmd_fetch_output (fd, out, flags);
379 383
380 if (close(fd) == -1) 384 if (close(fd) == -1)
381 die( STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno) ); 385 die( STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno) );
382 386
@@ -391,6 +395,7 @@ timeout_alarm_handler (int signo)
391 printf (_("%s - Plugin timed out after %d seconds\n"), 395 printf (_("%s - Plugin timed out after %d seconds\n"),
392 state_text(timeout_state), timeout_interval); 396 state_text(timeout_state), timeout_interval);
393 397
398 long maxfd = mp_open_max();
394 if(_cmd_pids) for(i = 0; i < maxfd; i++) { 399 if(_cmd_pids) for(i = 0; i < maxfd; i++) {
395 if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); 400 if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL);
396 } 401 }
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h
index 6f3aeb8..061f5d4 100644
--- a/lib/utils_cmd.h
+++ b/lib/utils_cmd.h
@@ -1,10 +1,10 @@
1#ifndef _UTILS_CMD_ 1#ifndef _UTILS_CMD_
2#define _UTILS_CMD_ 2#define _UTILS_CMD_
3 3
4/* 4/*
5 * Header file for Monitoring Plugins utils_cmd.c 5 * Header file for Monitoring Plugins utils_cmd.c
6 * 6 *
7 * 7 *
8 */ 8 */
9 9
10/** types **/ 10/** types **/
@@ -32,17 +32,8 @@ void cmd_init (void);
32#define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */ 32#define CMD_NO_ARRAYS 0x01 /* don't populate arrays at all */
33#define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */ 33#define CMD_NO_ASSOC 0x02 /* output.line won't point to buf */
34 34
35/* This variable must be global, since there's no way the caller
36 * can forcibly slay a dead or ungainly running program otherwise.
37 * Multithreading apps and plugins can initialize it (via CMD_INIT)
38 * in an async safe manner PRIOR to calling cmd_run() or cmd_run_array()
39 * for the first time.
40 *
41 * The check for initialized values is atomic and can
42 * occur in any number of threads simultaneously. */
43static pid_t *_cmd_pids = NULL;
44 35
45RETSIGTYPE timeout_alarm_handler (int); 36void timeout_alarm_handler (int);
46 37
47 38
48#endif /* _UTILS_CMD_ */ 39#endif /* _UTILS_CMD_ */
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 582d3ea..483be06 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -1,34 +1,35 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Library for check_disk 3* Library for check_disk
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2007 Monitoring Plugins Development Team 6* Copyright (c) 1999-2007 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains utilities for check_disk. These are tested by libtap 10* This file contains utilities for check_disk. These are tested by libtap
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* 26*
27*****************************************************************************/ 27*****************************************************************************/
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#include "gl/fsusage.h"
32#include <string.h>
32 33
33void 34void
34np_add_name (struct name_list **list, const char *name) 35np_add_name (struct name_list **list, const char *name)
@@ -40,6 +41,42 @@ np_add_name (struct name_list **list, const char *name)
40 *list = new_entry; 41 *list = new_entry;
41} 42}
42 43
44/* @brief Initialises a new regex at the begin of list via regcomp(3)
45 *
46 * @details if the regex fails to compile the error code of regcomp(3) is returned
47 * and list is not modified, otherwise list is modified to point to the new
48 * element
49 * @param list Pointer to a linked list of regex_list elements
50 * @param regex the string containing the regex which should be inserted into the list
51 * @param clags the cflags parameter for regcomp(3)
52 */
53int
54np_add_regex (struct regex_list **list, const char *regex, int cflags)
55{
56 struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry);
57
58 if (new_entry == NULL) {
59 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
60 strerror(errno));
61 }
62
63 int regcomp_result = regcomp(&new_entry->regex, regex, cflags);
64
65 if (!regcomp_result) {
66 // regcomp succeeded
67 new_entry->next = *list;
68 *list = new_entry;
69
70 return 0;
71 } else {
72 // regcomp failed
73 free(new_entry);
74
75 return regcomp_result;
76 }
77
78}
79
43/* Initialises a new parameter at the end of list */ 80/* Initialises a new parameter at the end of list */
44struct parameter_list * 81struct parameter_list *
45np_add_parameter(struct parameter_list **list, const char *name) 82np_add_parameter(struct parameter_list **list, const char *name)
@@ -61,7 +98,7 @@ np_add_parameter(struct parameter_list **list, const char *name)
61 new_path->freeinodes_percent = NULL; 98 new_path->freeinodes_percent = NULL;
62 new_path->group = NULL; 99 new_path->group = NULL;
63 new_path->dfree_pct = -1; 100 new_path->dfree_pct = -1;
64 new_path->dused_pct = -1; 101 new_path->dused_pct = -1;
65 new_path->total = 0; 102 new_path->total = 0;
66 new_path->available = 0; 103 new_path->available = 0;
67 new_path->available_to_root = 0; 104 new_path->available_to_root = 0;
@@ -133,9 +170,7 @@ np_find_parameter(struct parameter_list *list, const char *name)
133 return NULL; 170 return NULL;
134} 171}
135 172
136void 173void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) {
137np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
138{
139 struct parameter_list *d; 174 struct parameter_list *d;
140 for (d = desired; d; d= d->name_next) { 175 for (d = desired; d; d= d->name_next) {
141 if (! d->best_match) { 176 if (! d->best_match) {
@@ -158,9 +193,9 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
158 if (! best_match) { 193 if (! best_match) {
159 for (me = mount_list; me; me = me->me_next) { 194 for (me = mount_list; me; me = me->me_next) {
160 size_t len = strlen (me->me_mountdir); 195 size_t len = strlen (me->me_mountdir);
161 if ((exact == FALSE && (best_match_len <= len && len <= name_len && 196 if ((!exact && (best_match_len <= len && len <= name_len &&
162 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 197 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
163 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) 198 || (exact && strcmp(me->me_mountdir, d->name)==0))
164 { 199 {
165 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { 200 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
166 best_match = me; 201 best_match = me;
@@ -179,43 +214,57 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
179 } 214 }
180} 215}
181 216
182/* Returns TRUE if name is in list */ 217/* Returns true if name is in list */
183int 218bool np_find_name (struct name_list *list, const char *name) {
184np_find_name (struct name_list *list, const char *name)
185{
186 const struct name_list *n; 219 const struct name_list *n;
187 220
188 if (list == NULL || name == NULL) { 221 if (list == NULL || name == NULL) {
189 return FALSE; 222 return false;
190 } 223 }
191 for (n = list; n; n = n->next) { 224 for (n = list; n; n = n->next) {
192 if (!strcmp(name, n->name)) { 225 if (!strcmp(name, n->name)) {
193 return TRUE; 226 return true;
194 } 227 }
195 } 228 }
196 return FALSE; 229 return false;
197} 230}
198 231
199int 232/* Returns true if name is in list */
200np_seen_name(struct name_list *list, const char *name) 233bool np_find_regmatch (struct regex_list *list, const char *name) {
201{ 234 int len;
235 regmatch_t m;
236
237 if (name == NULL) {
238 return false;
239 }
240
241 len = strlen(name);
242
243 for (; list; list = list->next) {
244 /* Emulate a full match as if surrounded with ^( )$
245 by checking whether the match spans the whole name */
246 if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) {
247 return true;
248 }
249 }
250
251 return false;
252}
253
254bool np_seen_name(struct name_list *list, const char *name) {
202 const struct name_list *s; 255 const struct name_list *s;
203 for (s = list; s; s=s->next) { 256 for (s = list; s; s=s->next) {
204 if (!strcmp(s->name, name)) { 257 if (!strcmp(s->name, name)) {
205 return TRUE; 258 return true;
206 } 259 }
207 } 260 }
208 return FALSE; 261 return false;
209} 262}
210 263
211int 264bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) {
212np_regex_match_mount_entry (struct mount_entry* me, regex_t* re)
213{
214 if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 || 265 if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 ||
215 regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) { 266 regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) {
216 return TRUE; 267 return true;
217 } else {
218 return FALSE;
219 } 268 }
269 return false;
220} 270}
221
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 3b5a45f..5b2caf2 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -10,6 +10,12 @@ struct name_list
10 struct name_list *next; 10 struct name_list *next;
11}; 11};
12 12
13struct regex_list
14{
15 regex_t regex;
16 struct regex_list *next;
17};
18
13struct parameter_list 19struct parameter_list
14{ 20{
15 char *name; 21 char *name;
@@ -33,12 +39,14 @@ struct parameter_list
33}; 39};
34 40
35void np_add_name (struct name_list **list, const char *name); 41void np_add_name (struct name_list **list, const char *name);
36int np_find_name (struct name_list *list, const char *name); 42bool np_find_name (struct name_list *list, const char *name);
37int np_seen_name (struct name_list *list, const char *name); 43bool np_seen_name (struct name_list *list, const char *name);
44int np_add_regex (struct regex_list **list, const char *regex, int cflags);
45bool np_find_regmatch (struct regex_list *list, const char *name);
38struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); 46struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
39struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); 47struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
40struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); 48struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev);
41 49
42int search_parameter_list (struct parameter_list *list, const char *name); 50int search_parameter_list (struct parameter_list *list, const char *name);
43void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); 51void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact);
44int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); 52bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re);
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c
index b37c446..23ee4a9 100644
--- a/lib/utils_tcp.c
+++ b/lib/utils_tcp.c
@@ -1,29 +1,29 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Library for check_tcp 3* Library for check_tcp
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2013 Monitoring Plugins Development Team 6* Copyright (c) 1999-2013 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains utilities for check_tcp. These are tested by libtap 10* This file contains utilities for check_tcp. These are tested by libtap
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* 26*
27*****************************************************************************/ 27*****************************************************************************/
28 28
29#include "common.h" 29#include "common.h"