diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-26 10:48:21 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-26 10:48:21 +0000 |
commit | 30d71e5364d7df837cc42d8efb3ed430058c3050 (patch) | |
tree | 59b90b77a7b67ea25d51a5aeee5158ec16803cd7 /src/sysmon | |
parent | 8185d4b875012cfa58d71f326da37e047ba52dd9 (diff) | |
download | gnunet-30d71e5364d7df837cc42d8efb3ed430058c3050.tar.gz gnunet-30d71e5364d7df837cc42d8efb3ed430058c3050.zip |
changes
Diffstat (limited to 'src/sysmon')
-rw-r--r-- | src/sysmon/gnunet-daemon-sysmon.c | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/src/sysmon/gnunet-daemon-sysmon.c b/src/sysmon/gnunet-daemon-sysmon.c index cfd075deb..9939220fb 100644 --- a/src/sysmon/gnunet-daemon-sysmon.c +++ b/src/sysmon/gnunet-daemon-sysmon.c | |||
@@ -101,6 +101,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
101 | next = sp_head; | 101 | next = sp_head; |
102 | while (NULL != (sp = next)) | 102 | while (NULL != (sp = next)) |
103 | { | 103 | { |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping `%s' \n", sp->desc); | ||
104 | GNUNET_CONTAINER_DLL_remove (sp_head, sp_tail, sp); | 105 | GNUNET_CONTAINER_DLL_remove (sp_head, sp_tail, sp); |
105 | next = sp->next; | 106 | next = sp->next; |
106 | if (GNUNET_SCHEDULER_NO_TASK != sp->task_id) | 107 | if (GNUNET_SCHEDULER_NO_TASK != sp->task_id) |
@@ -108,7 +109,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
108 | GNUNET_SCHEDULER_cancel (sp->task_id); | 109 | GNUNET_SCHEDULER_cancel (sp->task_id); |
109 | sp->task_id = GNUNET_SCHEDULER_NO_TASK; | 110 | sp->task_id = GNUNET_SCHEDULER_NO_TASK; |
110 | } | 111 | } |
111 | GNUNET_free_non_null (sp->desc); | 112 | GNUNET_free (sp->desc); |
112 | GNUNET_free (sp); | 113 | GNUNET_free (sp); |
113 | } | 114 | } |
114 | 115 | ||
@@ -162,25 +163,31 @@ load_property (void *cls, | |||
162 | 163 | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading section `%s'\n", section); | 164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading section `%s'\n", section); |
164 | 165 | ||
165 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(properties, section, "TYPE")) | 166 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (properties, section, "TYPE")) |
166 | { | 167 | { |
167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n", | 168 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n", |
168 | "TYPE", section); | 169 | "TYPE", section); |
169 | return; | 170 | return; |
170 | } | 171 | } |
171 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(properties, section,"VALUE")) | 172 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (properties, section,"VALUE")) |
172 | { | 173 | { |
173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n", | 174 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n", |
174 | "VALUE", section); | 175 | "VALUE", section); |
175 | return; | 176 | return; |
176 | } | 177 | } |
178 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (properties, section,"DESCRIPTION")) | ||
179 | { | ||
180 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n", | ||
181 | "DESCRIPTION", section); | ||
182 | return; | ||
183 | } | ||
177 | sp = GNUNET_malloc (sizeof (struct SysmonProperty)); | 184 | sp = GNUNET_malloc (sizeof (struct SysmonProperty)); |
178 | 185 | ||
179 | /* description */ | 186 | /* description */ |
180 | GNUNET_CONFIGURATION_get_value_string(properties, section, "DESCRIPTION", &sp->desc); | 187 | GNUNET_CONFIGURATION_get_value_string (properties, section, "DESCRIPTION", &sp->desc); |
181 | 188 | ||
182 | /* type */ | 189 | /* type */ |
183 | GNUNET_CONFIGURATION_get_value_string(properties, section, "TYPE", &tmp); | 190 | GNUNET_CONFIGURATION_get_value_string (properties, section, "TYPE", &tmp); |
184 | to_lower_str (tmp); | 191 | to_lower_str (tmp); |
185 | if (0 == strcasecmp(tmp, "static")) | 192 | if (0 == strcasecmp(tmp, "static")) |
186 | sp->type = t_static; | 193 | sp->type = t_static; |
@@ -197,7 +204,7 @@ load_property (void *cls, | |||
197 | GNUNET_free (tmp); | 204 | GNUNET_free (tmp); |
198 | 205 | ||
199 | /* value */ | 206 | /* value */ |
200 | GNUNET_CONFIGURATION_get_value_string(properties, section, "VALUE", &tmp); | 207 | GNUNET_CONFIGURATION_get_value_string (properties, section, "VALUE", &tmp); |
201 | to_lower_str (tmp); | 208 | to_lower_str (tmp); |
202 | if (0 == strcasecmp(tmp, "numeric")) | 209 | if (0 == strcasecmp(tmp, "numeric")) |
203 | sp->value_type = v_numeric; | 210 | sp->value_type = v_numeric; |
@@ -214,10 +221,21 @@ load_property (void *cls, | |||
214 | GNUNET_free (tmp); | 221 | GNUNET_free (tmp); |
215 | 222 | ||
216 | /* interval */ | 223 | /* interval */ |
224 | if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (properties, section,"INTERVAL")) | ||
225 | sp->interval = GNUNET_TIME_UNIT_MINUTES; | ||
226 | else | ||
227 | { | ||
228 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (properties, section, "INTERVAL", &sp->interval)) | ||
229 | { | ||
230 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
231 | _("Could not parse execution interval for `%s', set to default 60 sec.\n"), section); | ||
232 | sp->interval = GNUNET_TIME_UNIT_MINUTES; | ||
233 | } | ||
234 | } | ||
217 | 235 | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded property `%s': type %u, value %u,\n", | 236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded property `%s': type %u, value %u, interval %llu\n", |
219 | (NULL != sp->desc) ? sp->desc: "<undefined>", | 237 | (NULL != sp->desc) ? sp->desc: "<undefined>", |
220 | sp->type, sp->value_type); | 238 | sp->type, sp->value_type, sp->interval.rel_value); |
221 | 239 | ||
222 | GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp); | 240 | GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp); |
223 | 241 | ||
@@ -227,10 +245,8 @@ static void | |||
227 | update_uptime (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 245 | update_uptime (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
228 | { | 246 | { |
229 | struct SysmonProperty *sp = cls; | 247 | struct SysmonProperty *sp = cls; |
230 | sp->task_id = GNUNET_SCHEDULER_NO_TASK; | ||
231 | sp->num_val ++; | 248 | sp->num_val ++; |
232 | put_property (sp); | 249 | put_property (sp); |
233 | sp->task_id = GNUNET_SCHEDULER_add_delayed (sp->interval, sp->task, sp); | ||
234 | } | 250 | } |
235 | 251 | ||
236 | static int | 252 | static int |
@@ -311,6 +327,17 @@ load_default_properties (void) | |||
311 | return GNUNET_OK; | 327 | return GNUNET_OK; |
312 | } | 328 | } |
313 | 329 | ||
330 | |||
331 | static void | ||
332 | run_property (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
333 | { | ||
334 | struct SysmonProperty *sp = cls; | ||
335 | sp->task_id = GNUNET_SCHEDULER_NO_TASK; | ||
336 | sp->task (cls, tc); | ||
337 | sp->task_id = GNUNET_SCHEDULER_add_delayed (sp->interval, &run_property, sp); | ||
338 | } | ||
339 | |||
340 | |||
314 | static int | 341 | static int |
315 | run_properties (void) | 342 | run_properties (void) |
316 | { | 343 | { |
@@ -331,7 +358,7 @@ run_properties (void) | |||
331 | GNUNET_break (0); | 358 | GNUNET_break (0); |
332 | } | 359 | } |
333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running continous property `%s' \n", sp->desc); | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running continous property `%s' \n", sp->desc); |
334 | sp->task_id = GNUNET_SCHEDULER_add_now (&update_uptime, sp); | 361 | sp->task_id = GNUNET_SCHEDULER_add_now (&run_property, sp); |
335 | } | 362 | } |
336 | } | 363 | } |
337 | return GNUNET_OK; | 364 | return GNUNET_OK; |