Prelim success with xsetroot working.
authorTom Balzer <niebieskitrociny@gmail.com>
Tue, 26 Jun 2018 13:54:58 +0000 (08:54 -0500)
committerTom Balzer <niebieskitrociny@gmail.com>
Tue, 26 Jun 2018 13:54:58 +0000 (08:54 -0500)
include/manifest.h
src/common/guile_helpers.c
src/tomd/main.c

index 17c6dba..4ed5ad7 100644 (file)
@@ -18,3 +18,7 @@
 /* SUMMARY: */
 /* Load jobs from config file into tomd main memory. */
 void load_jobs(void);
+
+/* SUMMARY: */
+/* Run each job in sequence via fork + execv */
+void run_jobs(void);
index c40faaf..1b57dfa 100644 (file)
@@ -61,12 +61,13 @@ static struct job load_job(SCM job_list, int index)
 
   ret.cmd = job_cmd;
   
-  for(int j = 0;
-      j < jlen;
+  for(int j = 1;
+      j <= jlen;
       j++){
-    ret.args[j] = real_args[j];
+    ret.args[j] = real_args[j - 1];
   }
-  ret.args[jlen] = NULL;
+  ret.args[jlen + 1] = NULL;
+  ret.args[0] = ret.cmd;
 
   return ret;
 }
@@ -126,7 +127,6 @@ void load_jobs(void)
   char *manifest = lookup_user_folder();
   tomd_p("Loading jobs from '%s'", manifest);
   
-  /* get into the manifest.scm file */
   void *res =
     scm_with_guile(load_manifest,
                    (void *) manifest);
@@ -141,7 +141,7 @@ void load_jobs(void)
     }
     tomd_p("JOB <%d>:", i);
     tomd_p("     cmd:'%s'", jobs[i].cmd);
-    int j = 0;
+    int j = 1;
     while(1){
       if(i >= 10 ||
          jobs[i].args[j] == NULL){
@@ -153,3 +153,45 @@ void load_jobs(void)
     i++;
   }
 }
+
+void run_job(int index)
+{
+  struct job *job = &jobs[index];
+
+  pid_t pid = fork();
+  if(pid == 0){                 /* child */
+    int i = 0;
+    while(1){
+      tomd_p("hallo");
+      if(job->args[i] == NULL){
+        tomd_p("arg [%d] is NULL", i);
+        break;
+      }else{
+        tomd_p("arg [%d] is '%s'", i, job->args[i]);
+      }
+      i++;
+    }
+    execvp(job->cmd, job->args);
+    tomd_p("execvp for '%s' failed", job->cmd);
+    perror("");
+    exit(EXIT_FAILURE);
+  }else{                        /* parent */
+    tomd_p("forked [%d] to run '%s'", pid, job->cmd);
+  }
+}
+
+void run_jobs(void)
+{
+  int i;
+  for(i = 0;
+      i < MAX_JOBS;
+      i++){
+    if(jobs[i].cmd == NULL){
+      tomd_p("out of jobs");
+      return;
+    }else{
+      tomd_p("running job [%d] '%s'", i, jobs[i].cmd);
+      run_job(i);
+    }
+  }        
+}
index a8cd25b..1ce9465 100644 (file)
@@ -183,6 +183,7 @@ int main(int argc, char **argv)
   init();
   /* daemonize(); */
   /* run(); */
+  run_jobs();
   cleanup();
   
   return EXIT_SUCCESS;