aboutsummaryrefslogtreecommitdiff
path: root/src/sysmon
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-11-26 12:47:02 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-11-26 12:47:02 +0000
commit8f649931a3e853af3cd1b0efbb588ff4f929575f (patch)
tree7ae4fdbdfa85a94055bf3603761ffa55a68eb79d /src/sysmon
parent30d71e5364d7df837cc42d8efb3ed430058c3050 (diff)
downloadgnunet-8f649931a3e853af3cd1b0efbb588ff4f929575f.tar.gz
gnunet-8f649931a3e853af3cd1b0efbb588ff4f929575f.zip
- more changeS
Diffstat (limited to 'src/sysmon')
-rw-r--r--src/sysmon/gnunet-daemon-sysmon.c97
1 files changed, 84 insertions, 13 deletions
diff --git a/src/sysmon/gnunet-daemon-sysmon.c b/src/sysmon/gnunet-daemon-sysmon.c
index 9939220fb..6a2168c40 100644
--- a/src/sysmon/gnunet-daemon-sysmon.c
+++ b/src/sysmon/gnunet-daemon-sysmon.c
@@ -49,6 +49,10 @@ struct SysmonProperty
49 int value_type; 49 int value_type;
50 struct GNUNET_TIME_Relative interval; 50 struct GNUNET_TIME_Relative interval;
51 51
52 char * cmd;
53 char * cmd_args;
54 void * cmd_exec_handle;
55
52 uint64_t num_val; 56 uint64_t num_val;
53 char * str_val; 57 char * str_val;
54 58
@@ -109,6 +113,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109 GNUNET_SCHEDULER_cancel (sp->task_id); 113 GNUNET_SCHEDULER_cancel (sp->task_id);
110 sp->task_id = GNUNET_SCHEDULER_NO_TASK; 114 sp->task_id = GNUNET_SCHEDULER_NO_TASK;
111 } 115 }
116 GNUNET_free_non_null (sp->cmd);
117 GNUNET_free_non_null (sp->cmd_args);
112 GNUNET_free (sp->desc); 118 GNUNET_free (sp->desc);
113 GNUNET_free (sp); 119 GNUNET_free (sp);
114 } 120 }
@@ -151,6 +157,54 @@ put_property (struct SysmonProperty *sp)
151} 157}
152 158
153static void 159static void
160update_uptime (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
161{
162 struct SysmonProperty *sp = cls;
163 sp->num_val ++;
164 put_property (sp);
165}
166
167static void
168exec_cmd_proc (void *cls, const char *line)
169{
170 struct SysmonProperty *sp = cls;
171 if (NULL == line)
172 {
173 GNUNET_OS_command_stop (sp->cmd_exec_handle);
174 sp->cmd_exec_handle = NULL;
175 return;
176 }
177
178
179
180 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property output: `%s'\n", line);
181}
182
183static void
184exec_cmd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
185{
186 struct SysmonProperty *sp = cls;
187 GNUNET_assert (NULL != sp->cmd);
188
189 if (NULL != sp->cmd_exec_handle)
190 {
191 GNUNET_OS_command_stop (sp->cmd_exec_handle);
192 sp->cmd_exec_handle = NULL;
193 GNUNET_break (0);
194 }
195
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Trying to exec : `%s'\n", sp->cmd);
197 if (NULL == (sp->cmd_exec_handle = GNUNET_OS_command_run (&exec_cmd_proc, sp,
198 GNUNET_TIME_UNIT_SECONDS,
199 sp->cmd, sp->cmd,
200 sp->cmd_args,
201 NULL)))
202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property `%s': command `%s' failed\n", sp->desc, sp->cmd);
203 else
204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property `%s': command `%s' DONE\n", sp->desc, sp->cmd);
205}
206
207static void
154load_property (void *cls, 208load_property (void *cls,
155 const char *section) 209 const char *section)
156{ 210{
@@ -181,11 +235,34 @@ load_property (void *cls,
181 "DESCRIPTION", section); 235 "DESCRIPTION", section);
182 return; 236 return;
183 } 237 }
238 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (properties, section,"CMD"))
239 {
240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing value %s in section `%s'\n",
241 "CMD", section);
242 return;
243 }
184 sp = GNUNET_malloc (sizeof (struct SysmonProperty)); 244 sp = GNUNET_malloc (sizeof (struct SysmonProperty));
185 245
186 /* description */ 246 /* description */
187 GNUNET_CONFIGURATION_get_value_string (properties, section, "DESCRIPTION", &sp->desc); 247 GNUNET_CONFIGURATION_get_value_string (properties, section, "DESCRIPTION", &sp->desc);
188 248
249 /* cmd */
250 GNUNET_CONFIGURATION_get_value_string (properties, section, "CMD", &tmp);
251 char *args = "";
252 if (NULL != strchr (tmp, ' '))
253 {
254 args = strchr (tmp, ' ');
255 if (strlen (args) > 1)
256 {
257 args[0] = '\0';
258 args++;
259 }
260 }
261 sp->cmd = GNUNET_strdup (tmp);
262 sp->cmd_args = GNUNET_strdup (args);
263 GNUNET_free (tmp);
264 sp->task = &exec_cmd;
265
189 /* type */ 266 /* type */
190 GNUNET_CONFIGURATION_get_value_string (properties, section, "TYPE", &tmp); 267 GNUNET_CONFIGURATION_get_value_string (properties, section, "TYPE", &tmp);
191 to_lower_str (tmp); 268 to_lower_str (tmp);
@@ -233,22 +310,16 @@ load_property (void *cls,
233 } 310 }
234 } 311 }
235 312
236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded property `%s': type %u, value %u, interval %llu\n", 313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded property `%s': %s, %s, interval %llu\n",
237 (NULL != sp->desc) ? sp->desc: "<undefined>", 314 (NULL != sp->desc) ? sp->desc: "<undefined>",
238 sp->type, sp->value_type, sp->interval.rel_value); 315 (t_continous == sp->type) ? "continious" : "static",
316 (v_numeric == sp->value_type) ? "numeric" : "string",
317 sp->interval.rel_value);
239 318
240 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp); 319 GNUNET_CONTAINER_DLL_insert (sp_head, sp_tail, sp);
241 320
242} 321}
243 322
244static void
245update_uptime (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
246{
247 struct SysmonProperty *sp = cls;
248 sp->num_val ++;
249 put_property (sp);
250}
251
252static int 323static int
253load_default_properties (void) 324load_default_properties (void)
254{ 325{
@@ -258,7 +329,7 @@ load_default_properties (void)
258 329
259 /* GNUnet vcs revision */ 330 /* GNUnet vcs revision */
260 unsigned int revision; 331 unsigned int revision;
261 332return GNUNET_OK;
262 /* version */ 333 /* version */
263#ifdef VERSION 334#ifdef VERSION
264 if (3 != sscanf (VERSION, "%u.%u.%u", &ver[0], &ver[1], &ver[2])) 335 if (3 != sscanf (VERSION, "%u.%u.%u", &ver[0], &ver[1], &ver[2]))
@@ -333,6 +404,7 @@ run_property (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
333{ 404{
334 struct SysmonProperty *sp = cls; 405 struct SysmonProperty *sp = cls;
335 sp->task_id = GNUNET_SCHEDULER_NO_TASK; 406 sp->task_id = GNUNET_SCHEDULER_NO_TASK;
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running continous property `%s' \n", sp->desc);
336 sp->task (cls, tc); 408 sp->task (cls, tc);
337 sp->task_id = GNUNET_SCHEDULER_add_delayed (sp->interval, &run_property, sp); 409 sp->task_id = GNUNET_SCHEDULER_add_delayed (sp->interval, &run_property, sp);
338} 410}
@@ -354,10 +426,9 @@ run_properties (void)
354 { 426 {
355 if (NULL == sp->task) 427 if (NULL == sp->task)
356 { 428 {
357 continue;
358 GNUNET_break (0); 429 GNUNET_break (0);
430 continue;
359 } 431 }
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running continous property `%s' \n", sp->desc);
361 sp->task_id = GNUNET_SCHEDULER_add_now (&run_property, sp); 432 sp->task_id = GNUNET_SCHEDULER_add_now (&run_property, sp);
362 } 433 }
363 } 434 }