2ddc1570fff00356f526736663e674525f71d073 — Simon Ser 16 days ago 3a47450
Broadcast SIGHUP on exit

Closes: https://github.com/emersion/mrsh/issues/123
3 files changed, 18 insertions(+), 0 deletions(-)

M include/shell/process.h
M shell/process.c
M shell/shell.c
M include/shell/process.h => include/shell/process.h +4 -0
@@ 38,5 38,9 @@ int process_poll(struct mrsh_process *process);
  * Update the shell's state with a child process status.
  */
 void update_process(struct mrsh_state *state, pid_t pid, int stat);
+/**
+ * Send SIGHUP to all child processes.
+ */
+void broadcast_sighup(struct mrsh_state *state);
 
 #endif

M shell/process.c => shell/process.c +13 -0
@@ 1,5 1,7 @@
+#define _POSIX_C_SOURCE 1
 #include <assert.h>
 #include <mrsh/array.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>


@@ 78,3 80,14 @@ void update_process(struct mrsh_state *state, pid_t pid, int stat) {
 		assert(false);
 	}
 }
+
+void broadcast_sighup(struct mrsh_state *state) {
+	struct mrsh_state_priv *priv = state_get_priv(state);
+
+	for (size_t i = 0; i < priv->processes.len; ++i) {
+		struct mrsh_process *proc = priv->processes.data[i];
+		if (kill(proc->pid, SIGHUP) != 0) {
+			perror("kill");
+		}
+	}
+}

M shell/shell.c => shell/shell.c +1 -0
@@ 85,6 85,7 @@ static void call_frame_destroy(struct mrsh_call_frame *frame) {
 
 void mrsh_state_destroy(struct mrsh_state *state) {
 	struct mrsh_state_priv *priv = state_get_priv(state);
+	broadcast_sighup(state);
 	mrsh_hashtable_for_each(&priv->variables, state_var_finish_iterator, NULL);
 	mrsh_hashtable_finish(&priv->variables);
 	mrsh_hashtable_for_each(&priv->functions, state_fn_finish_iterator, NULL);