summaryrefslogtreecommitdiffstats
path: root/web/attachments/37375-check_vsz.c.patch
blob: 6a0488a1e7ffa0230fa33f4372e2931d8111b86f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--- check_vsz.c.original	Sat Dec  7 17:21:29 2002
+++ check_vsz.c	Sat Dec  7 17:20:44 2002
@@ -63,7 +63,7 @@
 	char proc_name[MAX_INPUT_BUFFER];
 	char *message = "";
 
-	if (!process_arguments (argc, argv)) {
+	if (process_arguments (argc, argv) == ERROR ) {
 		printf ("%s: failure parsing arguments\n", my_basename (argv[0]));
 		print_help (my_basename (argv[0]));
 		return STATE_UNKNOWN;
@@ -94,7 +94,7 @@
 					asprintf (&message, "%s %s(%d)", message, proc_name, proc_size);
 					result = max_state (result, STATE_WARNING);
 				}
-				if (proc_size > crit) {
+				if (crit != -1 && proc_size > crit) {
 					result = STATE_CRITICAL;
 				}
 			}
@@ -103,7 +103,7 @@
 				if (proc_size > warn) {
 					result = max_state (result, STATE_WARNING);
 				}
-				if (proc_size > crit) {
+				if (crit != -1 && proc_size > crit) {
 					result = STATE_CRITICAL;
 				}
 			}
@@ -121,7 +121,7 @@
 		result = max_state (result, STATE_WARNING);
 
 	if (result == STATE_OK)
-		printf ("ok (all VSZ<%d): %s\n", warn, message);
+		printf ("OK (all VSZ<%d): %s\n", warn, message);
 	else if (result == STATE_UNKNOWN)
 		printf ("Unable to read output\n");
 	else if (result == STATE_WARNING)
@@ -166,7 +166,6 @@
 
 		switch (c) {
 		case '?':									/* help */
-			printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg);
 			print_usage (my_basename (argv[0]));
 			exit (STATE_UNKNOWN);
 		case 'h':									/* help */
@@ -200,7 +199,7 @@
 	}
 
 	c = optind;
-	if (warn == -1) {
+	if (warn == -1 && argv[c]) {
 		if (!is_intnonneg (argv[c])) {
 			printf ("%s: critical threshold must be an integer: %s\n",
 							PROGNAME, argv[c]);
@@ -210,7 +209,7 @@
 		warn = atoi (argv[c++]);
 	}
 
-	if (crit == -1) {
+	if (crit == -1 && argv[c]) {
 		if (!is_intnonneg (argv[c])) {
 			printf ("%s: critical threshold must be an integer: %s\n",
 							PROGNAME, argv[c]);
@@ -222,6 +221,17 @@
 
 	if (proc == NULL)
 		proc = argv[c];
+
+	// Validate arguments
+	if (warn == -1) {
+		if (crit != -1)
+			warn = crit;
+		else {
+			printf ("%s: Must specify a critical or warning threshold\n", PROGNAME);
+			print_usage (PROGNAME);
+			exit (STATE_UNKNOWN);
+		}
+	}
 
 	return c;
 }