summaryrefslogtreecommitdiffstats
path: root/lib/utils_disk.c
diff options
context:
space:
mode:
authorKristian Schuster <116557017+KriSchu@users.noreply.github.com>2023-02-19 12:44:04 (GMT)
committerKristian Schuster <116557017+KriSchu@users.noreply.github.com>2023-02-19 12:44:04 (GMT)
commit9898a8ad7dabfabfe80785585a5bbc30b678bdb0 (patch)
tree8512df61b3ac3f8422ecf3ca1acd9f2907c64fe0 /lib/utils_disk.c
parentbacacd2cb38c7d7a695a6f75f699168d9df0132d (diff)
downloadmonitoring-plugins-9898a8ad7dabfabfe80785585a5bbc30b678bdb0.tar.gz
utils_disk: add name_prev pointer to struct parameter_list
Also added handling of name_prev in np_add_parameter and np_delete_parameter. This make calling the np_delete_parameter function easier, because it requires the previous element as second argument.
Diffstat (limited to 'lib/utils_disk.c')
-rw-r--r--lib/utils_disk.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index c7c9126..a1181d3 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -46,9 +46,10 @@ np_add_parameter(struct parameter_list **list, const char *name)
46 struct parameter_list *current = *list; 46 struct parameter_list *current = *list;
47 struct parameter_list *new_path; 47 struct parameter_list *new_path;
48 new_path = (struct parameter_list *) malloc (sizeof *new_path); 48 new_path = (struct parameter_list *) malloc (sizeof *new_path);
49 new_path->name = (char *) name; 49 new_path->name = (char *) malloc(strlen(name) + 1);
50 new_path->best_match = NULL; 50 new_path->best_match = NULL;
51 new_path->name_next = NULL; 51 new_path->name_next = NULL;
52 new_path->name_prev = NULL;
52 new_path->freespace_bytes = NULL; 53 new_path->freespace_bytes = NULL;
53 new_path->freespace_units = NULL; 54 new_path->freespace_units = NULL;
54 new_path->freespace_percent = NULL; 55 new_path->freespace_percent = NULL;
@@ -74,13 +75,17 @@ np_add_parameter(struct parameter_list **list, const char *name)
74 new_path->dused_inodes_percent = 0; 75 new_path->dused_inodes_percent = 0;
75 new_path->dfree_inodes_percent = 0; 76 new_path->dfree_inodes_percent = 0;
76 77
78 strcpy(new_path->name, name);
79
77 if (current == NULL) { 80 if (current == NULL) {
78 *list = new_path; 81 *list = new_path;
82 new_path->name_prev = NULL;
79 } else { 83 } else {
80 while (current->name_next) { 84 while (current->name_next) {
81 current = current->name_next; 85 current = current->name_next;
82 } 86 }
83 current->name_next = new_path; 87 current->name_next = new_path;
88 new_path->name_prev = current;
84 } 89 }
85 return new_path; 90 return new_path;
86} 91}
@@ -89,6 +94,9 @@ np_add_parameter(struct parameter_list **list, const char *name)
89struct parameter_list * 94struct parameter_list *
90np_del_parameter(struct parameter_list *item, struct parameter_list *prev) 95np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
91{ 96{
97 if (item == NULL) {
98 return NULL;
99 }
92 struct parameter_list *next; 100 struct parameter_list *next;
93 101
94 if (item->name_next) 102 if (item->name_next)
@@ -96,10 +104,17 @@ np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
96 else 104 else
97 next = NULL; 105 next = NULL;
98 106
99 free(item); 107 if (next)
108 next->name_prev = prev;
109
100 if (prev) 110 if (prev)
101 prev->name_next = next; 111 prev->name_next = next;
102 112
113 if (item->name) {
114 free(item->name);
115 }
116 free(item);
117
103 return next; 118 return next;
104} 119}
105 120