Git Product home page Git Product logo

jackeventcmd's People

Contributors

gentoo-root avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

hlandauf

jackeventcmd's Issues

Fork issue again

You missed

signal(SIGCHLD, SIG_IGN);

from main.c when applying the fork patch.

Patch - fork issue

jackeventcmd forks before launching commands and then calls system. This means that two processes are launched for each command; a jackeventcmd fork and sh -c. The process forked by jackeventcmd does not terminate properly. The following patch changes jackeventcmd to fork once and execute sh -c. The forked process exits correctly.

diff --git a/main.c b/main.c
index 99134aa..5a2ecab 100644
--- a/main.c
+++ b/main.c
@@ -19,6 +19,7 @@
 #include "dbus.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <signal.h>
 #include "run.h"

 int main(int argc, char *argv[])
@@ -31,6 +32,7 @@ int main(int argc, char *argv[])
        fprintf(stderr, "Unable to read config\n");
        exit(16);
    }
+   signal(SIGCHLD, SIG_IGN);
    if (!je_dbus_init()) {
        fprintf(stderr, "Unable to initialize D-Bus\n");
        exit(1);
diff --git a/run.c b/run.c
index b3e813c..a2f0b6b 100644
--- a/run.c
+++ b/run.c
@@ -106,16 +106,12 @@ int read_config()

 void run_cmds(int num)
 {
-   struct list_item_t *p;
-   switch (fork()) {
-   case -1:
-       return;
-   case 0:
-       p = head[num];
-       while (p) {
-           printf("Running \"%s\"\n", p->command);
-           if (system(p->command)) ;
-           p = p->next;
+   struct list_item_t *p = head[num];
+   for (; p; p=p->next) {
+       printf("Running \"%s\"\n", p->command);
+       if (!fork()) {
+           execl("/bin/sh", "/bin/sh", "-c", p->command, NULL);
+           exit(1); /* in case of error */
        }
    }
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.