network test
[oweals/gnunet.git] / src / sysmon / gnunet-daemon-sysmon.c
index 6a2168c407be02190ac78f87072cb0b1aea192d3..387c4bd2e5202296d4e1eee9758014a056cc990a 100644 (file)
 #include "gnunet_util_lib.h"
 #include "gnunet_statistics_service.h"
 
+enum operation
+{
+  o_internal,
+  o_command
+};
+
+
 enum type
 {
   t_static,
@@ -39,25 +46,75 @@ enum value
   v_string
 };
 
+/**
+ * A system property to monitor
+ */
 struct SysmonProperty
 {
+  /**
+   * Next element in in the DLL
+   */
   struct SysmonProperty *next;
-  struct SysmonProperty *prev;
-
- char * desc;
- int type;
- int value_type;
- struct GNUNET_TIME_Relative interval;
-
- char * cmd;
- char * cmd_args;
- void * cmd_exec_handle;
 
- uint64_t num_val;
- char * str_val;
+  /**
+   * Previous element in in the DLL
+   */
+  struct SysmonProperty *prev;
 
- GNUNET_SCHEDULER_TaskIdentifier task_id;
- GNUNET_SCHEDULER_Task task;
+  /**
+   * Description used for statistics valuesd
+   */
+  char * desc;
+
+  /**
+   * Type
+   */
+  int type;
+
+  /**
+   * Value type
+   */
+  int value_type;
+
+  /**
+   * Execution interval
+   */
+  struct GNUNET_TIME_Relative interval;
+
+  /**
+   * Command
+   */
+  char * cmd;
+
+  /**
+   * Command arguments
+   */
+  char * cmd_args;
+
+  /**
+   * Command execution handle
+   */
+  void * cmd_exec_handle;
+
+  /**
+   * Numerical value
+   */
+  uint64_t num_val;
+
+  /**
+   * String value
+   */
+  char * str_val;
+
+  /**
+   * Task id
+   */
+  GNUNET_SCHEDULER_TaskIdentifier task_id;
+
+  /**
+   * Task handle
+   */
+  GNUNET_SCHEDULER_Task task;
 
 };
 
@@ -80,7 +137,6 @@ struct GNUNET_STATISTICS_Handle *stats;
 /**
  * Shutdown task
  */
-
 GNUNET_SCHEDULER_TaskIdentifier end_task;
 
 struct SysmonProperty *sp_head;
@@ -168,6 +224,7 @@ static void
 exec_cmd_proc (void *cls, const char *line)
 {
   struct SysmonProperty *sp = cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property output: `%s'\n", line);
   if (NULL == line)
   {
       GNUNET_OS_command_stop (sp->cmd_exec_handle);
@@ -175,9 +232,25 @@ exec_cmd_proc (void *cls, const char *line)
       return;
   }
 
-
+  switch (sp->value_type) {
+    case v_numeric:
+      if (1 != sscanf (line, "%lu", &sp->num_val))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Command output was not a numerical value: `%s'\n", line);
+        return;
+      }
+      break;
+    case v_string:
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "NOT IMPLEMENTED\n");
+      break;
+    default:
+      break;
+  }
 
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property output: `%s'\n", line);
+  put_property (sp);
+
+
 }
 
 static void
@@ -192,16 +265,13 @@ exec_cmd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     sp->cmd_exec_handle = NULL;
     GNUNET_break (0);
   }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Trying to exec : `%s'\n", sp->cmd);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property `%s': command `%s' `%s'\n", sp->desc, sp->cmd, sp->cmd_args);
   if (NULL == (sp->cmd_exec_handle = GNUNET_OS_command_run (&exec_cmd_proc, sp,
       GNUNET_TIME_UNIT_SECONDS,
       sp->cmd, sp->cmd,
       sp->cmd_args,
       NULL)))
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property `%s': command `%s' failed\n", sp->desc, sp->cmd);
-  else
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Property `%s': command `%s' DONE\n", sp->desc, sp->cmd);
 }
 
 static void