spawn_next_command: make process group creation optional

Create process group only in wizard - where we originally
needed it.
he "sync" event running functions, OTOH, won't create
a new process group after this. This means that abrt-handle-event,
report-cli and similar CLI tools will not run events in a separate
process group and thus will be killable as a unit via ^C, SIGTERM etc.

Fixes libreport/issues/132.

-- 
vda

diff -x '*.po' -d -urpN libreport.6/src/gui-wizard-gtk/wizard.c 
libreport.7/src/gui-wizard-gtk/wizard.c
--- libreport.6/src/gui-wizard-gtk/wizard.c     2013-02-07 14:31:32.000000000 
+0100
+++ libreport.7/src/gui-wizard-gtk/wizard.c     2013-02-13 14:10:20.234346678 
+0100
@@ -1400,7 +1400,7 @@ static void set_excluded_envvar(void)
 static int spawn_next_command_in_evd(struct analyze_event_data *evd)
 {
     evd->env_list = export_event_config(evd->event_name);
-    int r = spawn_next_command(evd->run_state, g_dump_dir_name, 
evd->event_name);
+    int r = spawn_next_command(evd->run_state, g_dump_dir_name, 
evd->event_name, EXECFLG_SETPGID);
     if (r >= 0)
     {
         g_event_child_pid = evd->run_state->command_pid;
@@ -1864,7 +1864,7 @@ static void start_event_run(const char *
     set_excluded_envvar();
     GList *env_list = export_event_config(event_name);

-    if (spawn_next_command(state, g_dump_dir_name, event_name) < 0)
+    if (spawn_next_command(state, g_dump_dir_name, event_name, 
EXECFLG_SETPGID) < 0)
     {
         unexport_event_config(env_list);
         goto no_cmds;
diff -x '*.po' -d -urpN libreport.6/src/include/run_event.h 
libreport.7/src/include/run_event.h
--- libreport.6/src/include/run_event.h 2013-02-07 14:31:32.000000000 +0100
+++ libreport.7/src/include/run_event.h 2013-02-13 14:13:09.530231446 +0100
@@ -143,10 +143,16 @@ void make_run_event_state_forwarding(str

 /* Returns 0 if no commands found for this dump_dir_name+event, else >0 */
 int prepare_commands(struct run_event_state *state, const char *dump_dir_name, 
const char *event);
-/* Returns -1 is no more commands needs to be executed,
- * else sets state->command_pid and state->command_out_fd and returns >=0
+/*
+ * Returns -1 if no more commands needs to be executed,
+ * else sets state->command_pid and state->command_out_fd and returns >=0.
+ * execflags can be e.g. EXECFLG_SETPGID to put the event handling process
+ * into a new process group, EXECFLG_SETSID to put it in a new session, etc.
  */
-int spawn_next_command(struct run_event_state *state, const char 
*dump_dir_name, const char *event);
+int spawn_next_command(struct run_event_state *state,
+                const char *dump_dir_name,
+                const char *event,
+                unsigned execflags);
 /* Cleans up internal state created in prepare_commands */
 void free_commands(struct run_event_state *state);

diff -x '*.po' -d -urpN libreport.6/src/lib/run_event.c 
libreport.7/src/lib/run_event.c
--- libreport.6/src/lib/run_event.c     2013-02-07 14:31:32.000000000 +0100
+++ libreport.7/src/lib/run_event.c     2013-02-13 14:14:22.436181525 +0100
@@ -110,7 +110,7 @@ void make_run_event_state_forwarding(str
  * List of commands machinery is encapsulated in struct run_event_state,
  * and public async API:
  *      prepare_commands(state, dir, event);
- *      spawn_next_command(state, dir, event);
+ *      spawn_next_command(state, dir, event, 0);
  *      free_commands(state);
  * does not expose the way we select rules to execute.
  */
@@ -416,11 +416,12 @@ int prepare_commands(struct run_event_st

 int spawn_next_command(struct run_event_state *state,
                 const char *dump_dir_name,
-                const char *event
+                const char *event,
+                unsigned execflags
 ) {
     char *cmd = pop_next_command(&state->rule_list,
                 NULL,          /* don't return event_name */
-                NULL,          /* NULL &dd: we match by... */
+                NULL,          /* NULL dd: we match by... */
                 dump_dir_name, /* ...dirname */
                 event, strlen(event)+1 /* for this event name exactly (not 
prefix) */
     );
@@ -456,7 +457,7 @@ int spawn_next_command(struct run_event_

     int pipefds[2];
     state->command_pid = fork_execv_on_steroids(
-                EXECFLG_INPUT + EXECFLG_OUTPUT + EXECFLG_ERR2OUT + 
EXECFLG_SETPGID,
+                EXECFLG_INPUT | EXECFLG_OUTPUT | EXECFLG_ERR2OUT | execflags,
                 argv,
                 pipefds,
                 /* env_vec: */ env_vec,
@@ -611,7 +612,7 @@ int run_event_on_dir_name(struct run_eve
     /* Execute every command in shell */

     int retval = 0;
-    while (spawn_next_command(state, dump_dir_name, event) >= 0)
+    while (spawn_next_command(state, dump_dir_name, event, /*execflags:*/ 0) 
>= 0)
     {
         retval = consume_event_command_output(state, dump_dir_name);
         if (retval != 0)

Reply via email to