Forráskód Böngészése

Merge branch 'master' into maint

abrist 12 éve
szülő
commit
50ff12a7a8
3 módosított fájl, 34 hozzáadás és 16 törlés
  1. 1 1
      NPTest.pm
  2. 7 8
      lib/parse_ini.c
  3. 26 7
      plugins/check_disk.c

+ 1 - 1
NPTest.pm

@@ -438,7 +438,7 @@ sub LoadCache
 
     chomp($fileContents);
     my( $contentsRef ) = eval $fileContents;
-    %CACHE = %{$contentsRef};
+    %CACHE = %{$contentsRef} if (defined($contentsRef));
 
   }
 

+ 7 - 8
lib/parse_ini.c

@@ -49,7 +49,7 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts);
 static int add_option(FILE *f, np_arg_list **optlst);
 /* internal function to find default file */
 static char* default_file(void);
-/* internal function to stat() files */
+/* internal function to test files access */
 static int test_file(const char* env, int len, const char* file, char* temp_file);
 
 /* parse_locator decomposes a string of the form
@@ -101,7 +101,7 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){
 		} else {
 			inifile=fopen(i.file, "r");
 		}
-		if(inifile==NULL) die(STATE_UNKNOWN, _("Can't read config file"));
+		if(inifile==NULL) die(STATE_UNKNOWN, "%s\n", _("Can't read config file"));
 		if(read_defaults(inifile, i.stanza, &defaults)==FALSE)
 			die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file);
 
@@ -163,7 +163,7 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts){
 					 * we're dealing with a config error
 					 */
 					case NOSTANZA:
-						die(STATE_UNKNOWN, _("Config file error"));
+						die(STATE_UNKNOWN, "%s\n", _("Config file error"));
 						break;
 					/* we're in a stanza, but for a different plugin */
 					case WRONGSTANZA:
@@ -173,7 +173,7 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts){
 					case RIGHTSTANZA:
 						ungetc(c, f);
 						if(add_option(f, opts)){
-							die(STATE_UNKNOWN, _("Config file error"));
+							die(STATE_UNKNOWN, "%s\n", _("Config file error"));
 						}
 						status=TRUE;
 						break;
@@ -229,7 +229,7 @@ static int add_option(FILE *f, np_arg_list **optlst){
 	if(optend==NULL) optend=eqptr;
 	--optend;
 	/* ^[[:space:]]*=foo is a syntax error */
-	if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n"));
+	if(optptr==eqptr) die(STATE_UNKNOWN, "%s\n", _("Config file error"));
 	/* continue from '=' to start of value or EOL */
 	for(valptr=eqptr+1; valptr<lineend && isspace(*valptr); valptr++);
 	/* continue to the end of value */
@@ -256,7 +256,7 @@ static int add_option(FILE *f, np_arg_list **optlst){
 		cfg_len+=1;
 	}
 	/* A line with no equal sign isn't valid */
-	if(equals==0) die(STATE_UNKNOWN, _("Config file error\n"));
+	if(equals==0) die(STATE_UNKNOWN, "%s\n", _("Config file error"));
 
 	/* okay, now we have all the info we need, so we create a new np_arg_list
 	 * element and set the argument...
@@ -350,7 +350,6 @@ static char* default_file(void){
  * existence. Returns 1 if found, 0 if not and -1 if test wasn't performed.
  */
 static int test_file(const char* env, int len, const char* file, char* temp_file){
-	struct stat sb;
 
 	/* test if len + filelen + '/' + '\0' fits in temp_file */
 	if((len+strlen(file)+2)>MAX_INPUT_BUFFER)	return -1;
@@ -360,7 +359,7 @@ static int test_file(const char* env, int len, const char* file, char* temp_file
 	strncat(temp_file,"/",len+1);
 	strncat(temp_file,file,len+strlen(file)+1);
 
-	if(stat(temp_file, &sb) != -1) return 1;
+	if(access(temp_file, F_OK) == 0) return 1;
 	return 0;
 }
 

+ 26 - 7
plugins/check_disk.c

@@ -135,6 +135,7 @@ char *exclude_device;
 char *units;
 uintmax_t mult = 1024 * 1024;
 int verbose = 0;
+int newlines = FALSE;
 int erronly = FALSE;
 int display_mntp = FALSE;
 int exact_match = FALSE;
@@ -344,10 +345,19 @@ main (int argc, char **argv)
                 path->dfree_units,
                 units,
                 path->dfree_pct);
-      if (path->dused_inodes_percent < 0) {
-        xasprintf(&output, "%s inode=-);", output);
+      /* Whether or not to put all disks on new line */
+      if (newlines) {
+        if (path->dused_inodes_percent < 0) {
+          xasprintf(&output, "%s inode=-);\n", output);
+        } else {
+          xasprintf(&output, "%s inode=%.0f%%);\n", output, path->dfree_inodes_percent );
+        }
       } else {
-        xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent );
+        if (path->dused_inodes_percent < 0) {
+          xasprintf(&output, "%s inode=-);", output);
+        } else {
+          xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent );
+        }
       }
 
       /* TODO: Need to do a similar debug line
@@ -365,8 +375,11 @@ main (int argc, char **argv)
   if (verbose >= 2)
     xasprintf (&output, "%s%s", output, details);
 
-
-  printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
+  if (newlines) {
+    printf ("DISK %s%s\n%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
+  } else {
+    printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
+  }
   return result;
 }
 
@@ -427,6 +440,7 @@ process_arguments (int argc, char **argv)
     {"exclude_device", required_argument, 0, 'x'},
     {"exclude-type", required_argument, 0, 'X'},
     {"include-type", required_argument, 0, 'N'},
+    {"newlines", no_argument, 0, 'n'},
     {"group", required_argument, 0, 'g'},
     {"eregi-path", required_argument, 0, 'R'},
     {"eregi-partition", required_argument, 0, 'R'},
@@ -461,7 +475,7 @@ process_arguments (int argc, char **argv)
       strcpy (argv[c], "-t");
 
   while (1) {
-    c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option);
+    c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEAn", longopts, &option);
 
     if (c == -1 || c == EOF)
       break;
@@ -603,6 +617,9 @@ process_arguments (int argc, char **argv)
     case 'N':                 /* include file system type */
       np_add_name(&fs_include_list, optarg);
       break;
+    case 'n':                 /* show each disk on a new line */
+      newlines = TRUE;
+      break;
     case 'v':                 /* verbose */
       verbose++;
       break;
@@ -919,6 +936,8 @@ print_help (void)
   printf ("    %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
   printf (" %s\n", "-N, --include-type=TYPE");
   printf ("    %s\n", _("Check only filesystems of indicated type (may be repeated)"));
+  printf (" %s\n", "-n, --newlines");
+  printf ("    %s\n", _("Multi-line output of each disk's status information on a new line"));
 
   printf ("\n");
   printf ("%s\n", _("Examples:"));
@@ -941,7 +960,7 @@ print_usage (void)
   printf ("%s\n", _("Usage:"));
   printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname);
   printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
-  printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n");
+  printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type] [-n]\n");
 }
 
 void