X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=lib%2Futils_disk.c;h=3d20f4d4125c075e9dbc5762d79758564a4985d8;hb=4b2265d20c8651046b5e8b65000d93bbbbb481f3;hp=cfd6a97968edb716f26f1e69ecc29e91ea826e08;hpb=0f71b7d07a8badd9aa38ef8d847bd982ab2db72c;p=nagiosplug.git diff --git a/lib/utils_disk.c b/lib/utils_disk.c index cfd6a97..3d20f4d 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -1,32 +1,28 @@ -/**************************************************************************** -* Utils for check_disk -* +/***************************************************************************** +* +* Library for check_disk +* * License: GPL -* Copyright (c) 1999-2006 nagios-plugins team -* -* Last Modified: $Date$ -* +* Copyright (c) 1999-2007 Nagios Plugins Development Team +* * 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 +* +* +* 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 +* the Free Software Foundation, either version 3 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$ +* along with this program. If not, see . +* * *****************************************************************************/ @@ -74,6 +70,25 @@ np_add_parameter(struct parameter_list **list, const char *name) return new_path; } +/* Delete a given parameter from list and return pointer to next element*/ +struct parameter_list * +np_del_parameter(struct parameter_list *item, struct parameter_list *prev) +{ + struct parameter_list *next; + + if (item->name_next) + next = item->name_next; + else + next = NULL; + + free(item); + if (prev) + prev->name_next = next; + + return next; +} + + /* returns a pointer to the struct found in the list */ struct parameter_list * np_find_parameter(struct parameter_list *list, const char *name) @@ -83,7 +98,7 @@ np_find_parameter(struct parameter_list *list, const char *name) if (! strcmp(temp_list->name, name)) return temp_list; } - + return NULL; } @@ -98,25 +113,26 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list size_t best_match_len = 0; struct mount_entry *best_match = NULL; + /* set best match if path name exactly matches a mounted device name */ 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)) - { + if (strcmp(me->me_devname, d->name)==0) best_match = me; - best_match_len = len; - } else { - len = strlen (me->me_devname); + } + + /* set best match by directory name if no match was found by devname */ + if (! best_match) { + 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_devname, d->name, len) == 0))) - || (exact == TRUE && strcmp(me->me_devname, d->name)==0)) + (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; } } } + if (best_match) { d->best_match = best_match; } else { @@ -156,12 +172,13 @@ np_seen_name(struct name_list *list, const char *name) } int -np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) +np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) { if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 || regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) { - return true; + return TRUE; } else { - return false; + return FALSE; } } +