executing sensor processes OK
authorOmar Tarabai <tarabai@devegypt.com>
Mon, 5 May 2014 15:46:28 +0000 (15:46 +0000)
committerOmar Tarabai <tarabai@devegypt.com>
Mon, 5 May 2014 15:46:28 +0000 (15:46 +0000)
src/sensor/Makefile.am
src/sensor/gnunet-service-sensor.c
src/sensor/sensors/averagepingrtt
src/sensor/sensors/gnunetversion

index fe461d1bca9918a64cafa763423203f4a4ee9032..e3d9bbe69673b9919ae65b6ffc127ee856f85e87 100644 (file)
@@ -64,7 +64,5 @@ install-data-local:
        $(mkinstalldirs) $(datadir)/$(PACKAGE)/$(pkgsensordir)
        @$(NORMAL_INSTALL)
        for sensor in $(pkgsensordir)/*; do \
-         if test -f $$sensor; then \
-           $(INSTALL_DATA) $$sensor $(datadir)/$(PACKAGE)/$(pkgsensordir)/ ; \
-         fi \
+         cp -a $$sensor $(datadir)/$(PACKAGE)/$(pkgsensordir)/ ; \
        done
index 7718fafee15d6869633b3dd6887ba03c5c960528..b831b2be7a6f46fca40a6394f7116d2f67560e6e 100644 (file)
@@ -776,6 +776,24 @@ void end_sensor_run_stat (void *cls, int success)
   sensorinfo->running = GNUNET_NO;
 }
 
+/**
+ * Callback for output of executed sensor process
+ *
+ * @param cls 'struct SensorInfo *'
+ * @param line line of output from a command, NULL for the end
+ */
+void sensor_process_callback (void *cls, const char *line)
+{
+  struct SensorInfo *sensorinfo = cls;
+
+  if(NULL == line)
+  {
+    sensorinfo->running = GNUNET_NO;
+    return;
+  }
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %s\n", sensorinfo->name, line);
+}
+
 /**
  * Actual execution of a sensor
  *
@@ -788,6 +806,8 @@ sensor_run (void *cls,
 {
   struct SensorInfo *sensorinfo = cls;
   int check_result;
+  char *sensors_dir;
+  char *process_path;
 
   sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &sensor_run, sensorinfo);
   if(GNUNET_YES == sensorinfo->running) //FIXME: should we try to kill?
@@ -815,13 +835,45 @@ sensor_run (void *cls,
   }
   else if(sources[1] == sensorinfo->source)
   {
+    /*GNUNET_OS_start_process_s(GNUNET_NO,
+        GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+        NULL,
+        "touch",
+        "touch /home/omar/hiii");*/
+    /*GNUNET_OS_start_process(GNUNET_NO,
+        GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+        NULL,
+        NULL,
+        NULL,
+        "/home/omar/workspace/gnunet/src/sensor/sensors/averagepingrtt-files/avgping.sh",
+        "avgping.sh",
+        NULL);
+    GNUNET_OS_start_process(GNUNET_NO,
+        GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+        NULL,
+        NULL,
+        NULL,
+        "whoami",
+        "whoami",
+        NULL);*/
+    //FIXME: break execution if process is a path
     //check if the process exists in $PATH
+    process_path = GNUNET_strdup(sensorinfo->ext_process);
     check_result =
         GNUNET_OS_check_helper_binary(sensorinfo->ext_process, GNUNET_NO, NULL); //search in $PATH
     if(GNUNET_SYSERR == check_result)
     {
       //search in sensor directory
-
+      sensors_dir = get_sensor_dir();
+      GNUNET_free(process_path);
+      GNUNET_asprintf(&process_path, "%s%s-files%s%s",
+          sensors_dir,
+          sensorinfo->name,
+          DIR_SEPARATOR_STR,
+          sensorinfo->ext_process);
+      GNUNET_free(sensors_dir);
+      check_result =
+        GNUNET_OS_check_helper_binary(process_path, GNUNET_NO, NULL);
     }
     if(GNUNET_SYSERR == check_result)
     {
@@ -830,12 +882,25 @@ sensor_run (void *cls,
           sensorinfo->ext_process);
       //FIXME: disable sensor here?
       sensorinfo->running = GNUNET_NO;
+      GNUNET_free(process_path);
       return;
     }
-    else if(GNUNET_NO == check_result)
-    {
-
-    }
+    /*GNUNET_OS_start_process(GNUNET_NO,
+        GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+        NULL,
+        NULL,
+        NULL,
+        process_path,
+        sensorinfo->ext_process,
+        sensorinfo->ext_args,
+        NULL)*/
+    GNUNET_OS_command_run(&sensor_process_callback,
+        sensorinfo,
+        GNUNET_TIME_UNIT_FOREVER_REL,
+        process_path,
+        sensorinfo->ext_process,
+        sensorinfo->ext_args,
+        NULL);
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Process started for sensor `%s'\n", sensorinfo->name);
   }
   else
index 2012f555e7f982508c02bdad4780266c72dfe126..b8880c69668467a9a834fb4a01eb05db54b67ee4 100644 (file)
@@ -3,13 +3,13 @@
 VERSION = 1.0
 DESCRIPTION = Calculate average ping latency to gnunet.org
 CATEGORY = Internet-Connectivity
-ENABLED = NO
+ENABLED = YES
 
 # Start and end time format: %Y-%m-%d %H:%M:%S
 #START_TIME = 
 #END_TIME = 
 #Interval in seconds
-INTERVAL = 3600
+INTERVAL = 30
 #LIFETIME = 
 
 #CAPABILITIES = 
index deb0e5f2dd52914b8c00e4b84a6a394fc8133695..dd213b605799371dc85325f69921d4b36306cb99 100644 (file)
@@ -9,8 +9,8 @@ ENABLED = YES
 #START_TIME = 
 #END_TIME = 
 #Interval in seconds
-INTERVAL = 86400
-LIFETIME = 86400
+INTERVAL = 30
+LIFETIME = 30
 
 #CAPABILITIES =