From 5912398b9723545ecd061650667cbb238be85743 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 13 Jul 2006 23:58:00 +0000 Subject: Major fixes to check_disk. Now should return same data as df git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1452 f882894a-f735-0410-b71e-b25c423dba1c --- lib/utils_disk.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 lib/utils_disk.c (limited to 'lib/utils_disk.c') diff --git a/lib/utils_disk.c b/lib/utils_disk.c new file mode 100644 index 00000000..fdbeaf1e --- /dev/null +++ b/lib/utils_disk.c @@ -0,0 +1,140 @@ +/**************************************************************************** +* Utils for check_disk +* +* License: GPL +* Copyright (c) 1999-2006 nagios-plugins team +* +* Last Modified: $Date$ +* +* 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$ +* +*****************************************************************************/ + +#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; +} + +/* Initialises a new parameter at the end of list */ +struct parameter_list * +np_add_parameter(struct parameter_list **list, const char *name) +{ + struct parameter_list *current = *list; + struct parameter_list *new_path; + new_path = (struct parameter_list *) malloc (sizeof *new_path); + new_path->name = (char *) name; + new_path->best_match = NULL; + new_path->name_next = NULL; + new_path->freespace_bytes = NULL; + new_path->freespace_units = NULL; + new_path->freespace_percent = NULL; + new_path->usedspace_bytes = NULL; + new_path->usedspace_units = NULL; + new_path->usedspace_percent = NULL; + new_path->usedinodes_percent = NULL; + + if (current == NULL) { + *list = new_path; + } else { + while (current->name_next) { + current = current->name_next; + } + current->name_next = new_path; + } + return new_path; +} + +void +np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact) +{ + struct parameter_list *d; + for (d = desired; d; d= d->name_next) { + struct mount_entry *me; + size_t name_len = strlen(d->name); + size_t best_match_len = 0; + struct mount_entry *best_match = NULL; + + for (me = mount_list; me; me = me->me_next) { + size_t len = strlen (me->me_mountdir); + if ((exact == FALSE && (best_match_len <= len && len <= name_len && + (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) + || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) + { + best_match = me; + best_match_len = len; + } else { + len = strlen (me->me_devname); + if ((exact == FALSE && (best_match_len <= len && len <= name_len && + (len == 1 || strncmp (me->me_devname, d->name, len) == 0))) + || (exact == TRUE && strcmp(me->me_devname, d->name)==0)) + { + best_match = me; + best_match_len = len; + } + } + } + if (best_match) { + d->best_match = best_match; + } else { + d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ + } + } +} + +/* 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; +} + +int +np_seen_name(struct name_list *list, const char *name) +{ + const struct name_list *s; + for (s = list; s; s=s->next) { + if (!strcmp(s->name, name)) { + return TRUE; + } + } + return FALSE; +} + -- cgit v1.2.3