Skip to content

Commit c8b5401

Browse files
committed
fix: ignore SIGTERM in gravity child to survive systemd cgroup-level kill
setsid() was already added to detach the child from the parent's process group, but systemd's default KillMode=control-group sends SIGTERM to ALL processes in the cgroup, not just the process group. After execv(), custom signal handlers are reset to SIG_DFL, so the gravity child was still killed immediately. Set SIG_IGN for SIGTERM before execv() since SIG_IGN (unlike custom handlers) is preserved across exec. This lets gravity run to completion even when FTL receives SIGTERM from systemd. Signed-off-by: Dominik <[email protected]>
1 parent 459881c commit c8b5401

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/api/action.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ static int run_and_stream_command(struct ftl_conn *api, const char *path, const
6464
// propagate to this child.
6565
(void)setsid();
6666

67+
// Ignore SIGTERM so systemd's cgroup-level kill (the
68+
// default KillMode=control-group sends SIGTERM to ALL
69+
// processes in the cgroup) doesn't terminate gravity
70+
// mid-run. SIG_IGN is preserved across execv(), unlike
71+
// custom handlers which are reset to SIG_DFL.
72+
signal(SIGTERM, SIG_IGN);
73+
6774
// Run pihole -g
6875
execv(path, (char *const *)args);
6976

0 commit comments

Comments
 (0)