summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-15 19:01:25 +0200
committerGitHub <noreply@github.com>2023-10-15 19:01:25 +0200
commitfff1014d1323980d5e969f31a5a17132482422ac (patch)
tree0d0980d41f95385cc0137ec86e7a1cea0065e04c
parentb1801c10846283176622db21974fe5003602630d (diff)
parentddbabaa3b659bed9dcf5c5a2bfc430fb816277c7 (diff)
downloadmonitoring-plugins-fff1014.tar.gz
Merge pull request #1937 from RincewindsHat/replace_booleans_in_lib
Replace old school booleans in lib
-rw-r--r--lib/extra_opts.c21
-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.c75
-rw-r--r--lib/utils_base.h8
-rw-r--r--lib/utils_cmd.c12
-rw-r--r--lib/utils_cmd.h6
-rw-r--r--lib/utils_disk.c66
-rw-r--r--lib/utils_disk.h10
-rw-r--r--lib/utils_tcp.c20
17 files changed, 208 insertions, 222 deletions
diff --git a/lib/extra_opts.c b/lib/extra_opts.c
index f4d5e66a..b9843eba 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 */
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 547af433..0cc864ae 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 5103d10d..05dd7943 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 4bb60aac..02ae11f5 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 9bd68c7a..e283fe2e 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 77f88549..6843bac2 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 814b3ec0..8a2a0414 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 c3d2067f..780220ee 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 114252b4..1954b0fb 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 7b10494c..01afacdc 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 0f521263..3c7221c8 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 }
@@ -465,7 +464,7 @@ char* _np_state_calculate_location_prefix(){
465 464
466 /* Do not allow passing MP_STATE_PATH in setuid plugins 465 /* Do not allow passing MP_STATE_PATH in setuid plugins
467 * for security reasons */ 466 * for security reasons */
468 if (mp_suid() == FALSE) { 467 if (!mp_suid()) {
469 env_dir = getenv("MP_STATE_PATH"); 468 env_dir = getenv("MP_STATE_PATH");
470 if(env_dir && env_dir[0] != '\0') 469 if(env_dir && env_dir[0] != '\0')
471 return env_dir; 470 return env_dir;
@@ -541,7 +540,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
541state_data *np_state_read() { 540state_data *np_state_read() {
542 state_data *this_state_data=NULL; 541 state_data *this_state_data=NULL;
543 FILE *statefile; 542 FILE *statefile;
544 int rc = FALSE; 543 bool rc = false;
545 544
546 if(this_monitoring_plugin==NULL) 545 if(this_monitoring_plugin==NULL)
547 die(STATE_UNKNOWN, _("This requires np_init to be called")); 546 die(STATE_UNKNOWN, _("This requires np_init to be called"));
@@ -563,7 +562,7 @@ state_data *np_state_read() {
563 fclose(statefile); 562 fclose(statefile);
564 } 563 }
565 564
566 if(rc==FALSE) { 565 if(!rc) {
567 _cleanup_state_data(); 566 _cleanup_state_data();
568 } 567 }
569 568
@@ -573,8 +572,8 @@ state_data *np_state_read() {
573/* 572/*
574 * Read the state file 573 * Read the state file
575 */ 574 */
576int _np_state_read_file(FILE *f) { 575bool _np_state_read_file(FILE *f) {
577 int status=FALSE; 576 bool status = false;
578 size_t pos; 577 size_t pos;
579 char *line; 578 char *line;
580 int i; 579 int i;
@@ -628,7 +627,7 @@ int _np_state_read_file(FILE *f) {
628 if(this_monitoring_plugin->state->state_data->data==NULL) 627 if(this_monitoring_plugin->state->state_data->data==NULL)
629 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); 628 die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
630 expected=STATE_DATA_END; 629 expected=STATE_DATA_END;
631 status=TRUE; 630 status=true;
632 break; 631 break;
633 case STATE_DATA_END: 632 case STATE_DATA_END:
634 ; 633 ;
@@ -640,10 +639,10 @@ int _np_state_read_file(FILE *f) {
640} 639}
641 640
642/* 641/*
643 * 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
644 * version, default text. Writes version, time, and data. Avoid locking 643 * version, default text. Writes version, time, and data. Avoid locking
645 * 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
646 * two things writing to same key at same time. 645 * two things writing to same key at same time.
647 * Will die with UNKNOWN if errors 646 * Will die with UNKNOWN if errors
648 */ 647 */
649void np_state_write_string(time_t data_time, char *data_string) { 648void np_state_write_string(time_t data_time, char *data_string) {
@@ -658,7 +657,7 @@ void np_state_write_string(time_t data_time, char *data_string) {
658 time(&current_time); 657 time(&current_time);
659 else 658 else
660 current_time=data_time; 659 current_time=data_time;
661 660
662 /* If file doesn't currently exist, create directories */ 661 /* If file doesn't currently exist, create directories */
663 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) { 662 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) {
664 result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); 663 result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
@@ -697,15 +696,15 @@ void np_state_write_string(time_t data_time, char *data_string) {
697 np_free(temp_file); 696 np_free(temp_file);
698 die(STATE_UNKNOWN, _("Unable to open temporary state file")); 697 die(STATE_UNKNOWN, _("Unable to open temporary state file"));
699 } 698 }
700 699
701 fprintf(fp,"# NP State file\n"); 700 fprintf(fp,"# NP State file\n");
702 fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION); 701 fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION);
703 fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version); 702 fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version);
704 fprintf(fp,"%lu\n",current_time); 703 fprintf(fp,"%lu\n",current_time);
705 fprintf(fp,"%s\n",data_string); 704 fprintf(fp,"%s\n",data_string);
706 705
707 fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP); 706 fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP);
708 707
709 fflush(fp); 708 fflush(fp);
710 709
711 result=fclose(fp); 710 result=fclose(fp);
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 9cb42767..80b87435 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -6,7 +6,7 @@
6# include "sha256.h" 6# include "sha256.h"
7#endif 7#endif
8 8
9/* 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
10 individual plugin logic */ 10 individual plugin logic */
11 11
12/* 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
@@ -21,7 +21,7 @@
21 21
22typedef struct range_struct { 22typedef struct range_struct {
23 double start; 23 double start;
24 int start_infinity; /* FALSE (default) or TRUE */ 24 bool start_infinity;
25 double end; 25 double end;
26 int end_infinity; 26 int end_infinity;
27 int alert_on; /* OUTSIDE (default) or INSIDE */ 27 int alert_on; /* OUTSIDE (default) or INSIDE */
@@ -61,7 +61,7 @@ range *parse_range_string (char *);
61int _set_thresholds(thresholds **, char *, char *); 61int _set_thresholds(thresholds **, char *, char *);
62void set_thresholds(thresholds **, char *, char *); 62void set_thresholds(thresholds **, char *, char *);
63void print_thresholds(const char *, thresholds *); 63void print_thresholds(const char *, thresholds *);
64int check_range(double, range *); 64bool check_range(double, range *);
65int get_status(double, thresholds *); 65int get_status(double, thresholds *);
66 66
67/* Handle timeouts */ 67/* Handle timeouts */
@@ -79,7 +79,7 @@ void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)))
79#define NP_RANGE_UNPARSEABLE 1 79#define NP_RANGE_UNPARSEABLE 1
80#define NP_WARN_WITHIN_CRIT 2 80#define NP_WARN_WITHIN_CRIT 2
81 81
82/* a simple check to see if we're running as root. 82/* a simple check to see if we're running as root.
83 * returns zero on failure, nonzero on success */ 83 * returns zero on failure, nonzero on success */
84int np_check_if_root(void); 84int np_check_if_root(void);
85 85
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index f66fd573..cfb2073c 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*
@@ -377,10 +377,10 @@ cmd_file_read ( char *filename, output *out, int flags)
377 if ((fd = open(filename, O_RDONLY)) == -1) { 377 if ((fd = open(filename, O_RDONLY)) == -1) {
378 die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) ); 378 die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) );
379 } 379 }
380 380
381 if(out) 381 if(out)
382 out->lines = _cmd_fetch_output (fd, out, flags); 382 out->lines = _cmd_fetch_output (fd, out, flags);
383 383
384 if (close(fd) == -1) 384 if (close(fd) == -1)
385 die( STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno) ); 385 die( STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno) );
386 386
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h
index f1b06c82..061f5d4f 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 **/
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index f5ac0b30..483be06d 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -1,29 +1,29 @@
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"
@@ -98,7 +98,7 @@ np_add_parameter(struct parameter_list **list, const char *name)
98 new_path->freeinodes_percent = NULL; 98 new_path->freeinodes_percent = NULL;
99 new_path->group = NULL; 99 new_path->group = NULL;
100 new_path->dfree_pct = -1; 100 new_path->dfree_pct = -1;
101 new_path->dused_pct = -1; 101 new_path->dused_pct = -1;
102 new_path->total = 0; 102 new_path->total = 0;
103 new_path->available = 0; 103 new_path->available = 0;
104 new_path->available_to_root = 0; 104 new_path->available_to_root = 0;
@@ -170,9 +170,7 @@ np_find_parameter(struct parameter_list *list, const char *name)
170 return NULL; 170 return NULL;
171} 171}
172 172
173void 173void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) {
174np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
175{
176 struct parameter_list *d; 174 struct parameter_list *d;
177 for (d = desired; d; d= d->name_next) { 175 for (d = desired; d; d= d->name_next) {
178 if (! d->best_match) { 176 if (! d->best_match) {
@@ -195,9 +193,9 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
195 if (! best_match) { 193 if (! best_match) {
196 for (me = mount_list; me; me = me->me_next) { 194 for (me = mount_list; me; me = me->me_next) {
197 size_t len = strlen (me->me_mountdir); 195 size_t len = strlen (me->me_mountdir);
198 if ((exact == FALSE && (best_match_len <= len && len <= name_len && 196 if ((!exact && (best_match_len <= len && len <= name_len &&
199 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 197 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
200 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) 198 || (exact && strcmp(me->me_mountdir, d->name)==0))
201 { 199 {
202 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) {
203 best_match = me; 201 best_match = me;
@@ -216,27 +214,23 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
216 } 214 }
217} 215}
218 216
219/* Returns TRUE if name is in list */ 217/* Returns true if name is in list */
220int 218bool np_find_name (struct name_list *list, const char *name) {
221np_find_name (struct name_list *list, const char *name)
222{
223 const struct name_list *n; 219 const struct name_list *n;
224 220
225 if (list == NULL || name == NULL) { 221 if (list == NULL || name == NULL) {
226 return FALSE; 222 return false;
227 } 223 }
228 for (n = list; n; n = n->next) { 224 for (n = list; n; n = n->next) {
229 if (!strcmp(name, n->name)) { 225 if (!strcmp(name, n->name)) {
230 return TRUE; 226 return true;
231 } 227 }
232 } 228 }
233 return FALSE; 229 return false;
234} 230}
235 231
236/* Returns TRUE if name is in list */ 232/* Returns true if name is in list */
237bool 233bool np_find_regmatch (struct regex_list *list, const char *name) {
238np_find_regmatch (struct regex_list *list, const char *name)
239{
240 int len; 234 int len;
241 regmatch_t m; 235 regmatch_t m;
242 236
@@ -257,26 +251,20 @@ np_find_regmatch (struct regex_list *list, const char *name)
257 return false; 251 return false;
258} 252}
259 253
260int 254bool np_seen_name(struct name_list *list, const char *name) {
261np_seen_name(struct name_list *list, const char *name)
262{
263 const struct name_list *s; 255 const struct name_list *s;
264 for (s = list; s; s=s->next) { 256 for (s = list; s; s=s->next) {
265 if (!strcmp(s->name, name)) { 257 if (!strcmp(s->name, name)) {
266 return TRUE; 258 return true;
267 } 259 }
268 } 260 }
269 return FALSE; 261 return false;
270} 262}
271 263
272int 264bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) {
273np_regex_match_mount_entry (struct mount_entry* me, regex_t* re)
274{
275 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 ||
276 regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) { 266 regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) {
277 return TRUE; 267 return true;
278 } else {
279 return FALSE;
280 } 268 }
269 return false;
281} 270}
282
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 6b83ac74..5b2caf23 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -39,14 +39,14 @@ struct parameter_list
39}; 39};
40 40
41void np_add_name (struct name_list **list, const char *name); 41void np_add_name (struct name_list **list, const char *name);
42int np_find_name (struct name_list *list, const char *name); 42bool np_find_name (struct name_list *list, const char *name);
43int 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); 44int np_add_regex (struct regex_list **list, const char *regex, int cflags);
45bool np_find_regmatch (struct regex_list *list, const char *name); 45bool np_find_regmatch (struct regex_list *list, const char *name);
46struct 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);
47struct 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);
48struct 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);
49 49
50int search_parameter_list (struct parameter_list *list, const char *name); 50int search_parameter_list (struct parameter_list *list, const char *name);
51void 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);
52int 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 b37c446f..23ee4a95 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"