[Nagiosplug-checkins] nagiosplug/plugins utils_disk.c, NONE, 1.1 utils_disk.h, NONE, 1.1 Makefile.am, 1.67, 1.68 check_disk.c, 1.68, 1.69

Ton Voon tonvoon at users.sourceforge.net
Wed Jul 12 14:15:44 CEST 2006


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv29569

Modified Files:
	Makefile.am check_disk.c 
Added Files:
	utils_disk.c utils_disk.h 
Log Message:
Moving check_disk functions into utils_disk.c and testing them


--- NEW FILE: utils_disk.c ---
/****************************************************************************
* Utils for check_disk
*
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2006/07/12 12:15:42 $
*
* Description:
*
* This file contains utilities for check_disk. These are tested by libtap
*
* License Information:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: utils_disk.c,v 1.1 2006/07/12 12:15:42 tonvoon Exp $
* 
*****************************************************************************/

#include "common.h"
#include "utils_disk.h"

void
np_add_name (struct name_list **list, const char *name)
{
  struct name_list *new_entry;
  new_entry = (struct name_list *) malloc (sizeof *new_entry);
  new_entry->name = (char *) name;
  new_entry->next = *list;
  *list = new_entry;
}

/* Returns TRUE if name is in list */
int
np_find_name (struct name_list *list, const char *name)
{
  const struct name_list *n;

  if (list == NULL || name == NULL) {
    return FALSE;
  }
  for (n = list; n; n = n->next) {
    if (!strcmp(name, n->name)) {
      return TRUE;
    }
  }
  return FALSE;
}


Index: check_disk.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_disk.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- check_disk.c	18 Jun 2006 19:36:48 -0000	1.68
+++ check_disk.c	12 Jul 2006 12:15:42 -0000	1.69
@@ -37,10 +37,6 @@
 const char *copyright = "1999-2006";
 const char *email = "nagiosplug-devel at lists.sourceforge.net";
 
- /*
-  * Additional inode code by Jorgen Lundman <lundman at lundman.net>
-  */
-
 
 #include "common.h"
 #if HAVE_INTTYPES_H
@@ -50,12 +46,14 @@
 #include "popen.h"
 #include "utils.h"
 #include <stdarg.h>
-#include "../lib/fsusage.h"
-#include "../lib/mountlist.h"
+#include "fsusage.h"
+#include "mountlist.h"
 #if HAVE_LIMITS_H
 # include <limits.h>
 #endif
 
+#include "utils_disk.h"
+
 /* If nonzero, show inode information. */
 static int inode_format;
 
@@ -77,8 +75,7 @@
 /* static int require_sync = 0; */
 
 /* A filesystem type to display. */
-
-struct name_list
+struct parameter_list
 {
   char *name;
   int found;
@@ -89,7 +86,7 @@
   double c_dfp;
   double w_idfp;
   double c_idfp;
-  struct name_list *name_next;
+  struct parameter_list *name_next;
 };
 
 /* Linked list of filesystem types to display.
@@ -103,7 +100,7 @@
    Some filesystem types:
    4.2 4.3 ufs nfs swap ignore io vm efs dbg */
 
-/* static struct name_list *fs_select_list; */
+/* static struct parameter_list *fs_select_list; */
 
 /* Linked list of filesystem types to omit.
    If the list is empty, don't exclude any types.  */
@@ -112,9 +109,7 @@
 
 static struct name_list *dp_exclude_list;
 
-static struct name_list *path_select_list;
-
-static struct name_list *dev_select_list;
+static struct parameter_list *path_select_list;
 
 /* Linked list of mounted filesystems. */
 static struct mount_entry *mount_list;
@@ -132,11 +127,14 @@
  #pragma alloca
 #endif
 
+/* Linked list of mounted filesystems. */
+static struct mount_entry *mount_list;
+
 int process_arguments (int, char **);
 void print_path (const char *mypath);
 int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
 int check_disk (double usp, uintmax_t free_disk, double uisp);
-int walk_name_list (struct name_list *list, const char *name);
+int walk_parameter_list (struct parameter_list *list, const char *name);
 void print_help (void);
 void print_usage (void);
 
@@ -154,9 +152,6 @@
 int erronly = FALSE;
 int display_mntp = FALSE;
 
-/* Linked list of mounted filesystems. */
-static struct mount_entry *mount_list;
-
 
 
 int
@@ -174,7 +169,7 @@
 
   struct mount_entry *me;
   struct fs_usage fsp;
-  struct name_list *temp_list;
+  struct parameter_list *temp_list;
 
   output = strdup (" - free space:");
   details = strdup ("");
@@ -199,8 +194,8 @@
    */
   if(path_select_list){
     for (me = mount_list; me; me = me->me_next) {
-      walk_name_list(path_select_list, me->me_mountdir);
-      walk_name_list(path_select_list, me->me_devname);
+      walk_parameter_list(path_select_list, me->me_mountdir);
+      walk_parameter_list(path_select_list, me->me_devname);
     }
     /* now pretend we never saw anything, but keep found_len.
      * thus future searches will only match the best match */
@@ -214,12 +209,12 @@
     /* if there's a list of paths to select, the current mount
      * entry matches in path or device name, get fs usage */
     if (path_select_list &&
-         (walk_name_list (path_select_list, me->me_mountdir) ||
-          walk_name_list (path_select_list, me->me_devname) ) ) {
+         (walk_parameter_list (path_select_list, me->me_mountdir) ||
+          walk_parameter_list (path_select_list, me->me_devname) ) ) {
       get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
     /* else if there's a list of paths/devices to select (but
      * we didn't match above) skip to the next mount entry */
-    } else if (dev_select_list || path_select_list) {
+    } else if (path_select_list) {
       continue;
     /* skip remote filesystems if we're not interested in them */
     } else if (me->me_remote && show_local_fs) {
@@ -228,12 +223,12 @@
     } else if (me->me_dummy && !show_all_fs) {
       continue;
     /* skip excluded fstypes */
-    } else if (fs_exclude_list && walk_name_list (fs_exclude_list, me->me_type)) {
+    } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
       continue;
     /* skip excluded fs's */  
     } else if (dp_exclude_list && 
-             (walk_name_list (dp_exclude_list, me->me_devname) ||
-              walk_name_list (dp_exclude_list, me->me_mountdir))) {
+             (np_find_name (dp_exclude_list, me->me_devname) ||
+              np_find_name (dp_exclude_list, me->me_mountdir))) {
       continue;
     /* otherwise, get fs usage */
     } else {
@@ -312,11 +307,9 @@
 process_arguments (int argc, char **argv)
 {
   int c;
-  struct name_list *se;
-  struct name_list **pathtail = &path_select_list;
-  struct name_list **fstail = &fs_exclude_list;
-  struct name_list **dptail = &dp_exclude_list;
-  struct name_list *temp_list;
+  struct parameter_list *se;
+  struct parameter_list **pathtail = &path_select_list;
+  struct parameter_list *temp_list;
   int result = OK;
   struct stat *stat_buf;
 
@@ -351,13 +344,7 @@
   if (argc < 2)
     return ERROR;
 
-  se = (struct name_list *) malloc (sizeof (struct name_list));
-  se->name = strdup ("iso9660");
-  se->name_next = NULL;
-  se->found = 0;
-  se->found_len = 0;
-  *fstail = se;
-  fstail = &se->name_next;
+  np_add_name(&fs_exclude_list, "iso9660");
 
   for (c = 1; c < argc; c++)
     if (strcmp ("-to", argv[c]) == 0)
@@ -468,7 +455,7 @@
       show_local_fs = 1;      
       break;
     case 'p':                 /* select path */
-      se = (struct name_list *) malloc (sizeof (struct name_list));
+      se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
       se->name = optarg;
       se->name_next = NULL;
       se->w_df = w_df;
@@ -483,43 +470,10 @@
       pathtail = &se->name_next;
       break;
     case 'x':                 /* exclude path or partition */
-      se = (struct name_list *) malloc (sizeof (struct name_list));
-      se->name = optarg;
-      se->name_next = NULL;
-
-                        /* If you don't clear the w_fd etc values here, they
-                         * get processed when you walk the list and assigned
-                         * to the global w_df!
-                         */
-                        se->w_df = 0;
-                        se->c_df = 0;
-                        se->w_dfp = 0;
-                        se->c_dfp = 0;
-			se->w_idfp = 0;
-			se->c_idfp = 0;
-      se->found = 0;
-      se->found_len = 0;
-      *dptail = se;
-      dptail = &se->name_next;
+      np_add_name(&dp_exclude_list, optarg);
       break;
     case 'X':                 /* exclude file system type */
-      se = (struct name_list *) malloc (sizeof (struct name_list));
-      se->name = optarg;
-      se->name_next = NULL;
-                        /* If you don't clear the w_fd etc values here, they
-                         * get processed when you walk the list and assigned
-                         * to the global w_df!
-                         */
-                        se->w_df = 0;
-                        se->c_df = 0;
-                        se->w_dfp = 0;
-                        se->c_dfp = 0;
-			se->w_idfp = 0;
-			se->c_idfp = 0;
-      se->found = 0;
-      se->found_len = 0;
-      *fstail = se;
-      fstail = &se->name_next;
+      np_add_name(&fs_exclude_list, optarg);
       break;
     case 'v':                 /* verbose */
       verbose++;
@@ -561,7 +515,7 @@
     c_dfp = (100.0 - atof (argv[c++]));
 
   if (argc > c && path == NULL) {
-    se = (struct name_list *) malloc (sizeof (struct name_list));
+    se = (struct parameter_list *) malloc (sizeof (struct parameter_list));
     se->name = strdup (argv[c++]);
     se->name_next = NULL;
     se->w_df = w_df;
@@ -683,7 +637,7 @@
 
 
 int
-walk_name_list (struct name_list *list, const char *name)
+walk_parameter_list (struct parameter_list *list, const char *name)
 {
   int name_len;
   name_len = strlen(name);
@@ -695,7 +649,7 @@
         ! strncmp(list->name, name, name_len)) {
       list->found = 1;
       list->found_len = name_len;
-      /* if required for name_lists that have not saved w_df, etc (eg exclude lists) */
+      /* if required for parameter_lists that have not saved w_df, etc (eg exclude lists) */
       if (list->w_df) w_df = list->w_df;
       if (list->c_df) c_df = list->c_df;
       if (list->w_dfp>=0.0) w_dfp = list->w_dfp;

--- NEW FILE: utils_disk.h ---
/* Header file for utils_disk */


struct name_list
{
  char *name;
  struct name_list *next;
};

void np_add_name (struct name_list **list, const char *name);
int np_find_name (struct name_list *list, const char *name);


Index: Makefile.am
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/Makefile.am,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- Makefile.am	3 Jul 2006 07:55:52 -0000	1.67
+++ Makefile.am	12 Jul 2006 12:15:42 -0000	1.68
@@ -55,7 +55,7 @@
 
 check_apt_LDADD = $(BASEOBJS) runcmd.o
 check_dig_LDADD = $(NETLIBS) runcmd.o 
-check_disk_LDADD = $(BASEOBJS) popen.o
+check_disk_LDADD = $(BASEOBJS) popen.o utils_disk.o
 check_dns_LDADD = $(NETLIBS) runcmd.o
 check_dummy_LDADD = $(BASEOBJS)
 check_fping_LDADD = $(NETLIBS) popen.o
@@ -98,7 +98,7 @@
 
 check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS)
 check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS)
-check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS)
+check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o utils_disk.o $(DEPLIBS) 
 check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS)
 check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS)
 check_fping_DEPENDENCIES = check_fping.c $(NETOBJS) popen.o $(DEPLIBS)





More information about the Commits mailing list