Show More
@@ -339,6 +339,7 b' static void killcmdserver(const struct c' | |||||
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | static pid_t pagerpid = 0; |
|
341 | static pid_t pagerpid = 0; | |
|
342 | static pid_t peerpgid = 0; | |||
342 | static pid_t peerpid = 0; |
|
343 | static pid_t peerpid = 0; | |
343 |
|
344 | |||
344 | static void forwardsignal(int sig) |
|
345 | static void forwardsignal(int sig) | |
@@ -349,6 +350,15 b' static void forwardsignal(int sig)' | |||||
349 | debugmsg("forward signal %d", sig); |
|
350 | debugmsg("forward signal %d", sig); | |
350 | } |
|
351 | } | |
351 |
|
352 | |||
|
353 | static void forwardsignaltogroup(int sig) | |||
|
354 | { | |||
|
355 | /* prefer kill(-pgid, sig), fallback to pid if pgid is invalid */ | |||
|
356 | pid_t killpid = peerpgid > 1 ? -peerpgid : peerpid; | |||
|
357 | if (kill(killpid, sig) < 0) | |||
|
358 | abortmsgerrno("cannot kill %d", killpid); | |||
|
359 | debugmsg("forward signal %d to %d", sig, killpid); | |||
|
360 | } | |||
|
361 | ||||
352 | static void handlestopsignal(int sig) |
|
362 | static void handlestopsignal(int sig) | |
353 | { |
|
363 | { | |
354 | sigset_t unblockset, oldset; |
|
364 | sigset_t unblockset, oldset; | |
@@ -392,15 +402,19 b' static void handlechildsignal(int sig UN' | |||||
392 | kill(peerpid, SIGPIPE); |
|
402 | kill(peerpid, SIGPIPE); | |
393 | } |
|
403 | } | |
394 |
|
404 | |||
395 |
static void setupsignalhandler( |
|
405 | static void setupsignalhandler(const hgclient_t *hgc) | |
396 | { |
|
406 | { | |
|
407 | pid_t pid = hgc_peerpid(hgc); | |||
397 | if (pid <= 0) |
|
408 | if (pid <= 0) | |
398 | return; |
|
409 | return; | |
399 | peerpid = pid; |
|
410 | peerpid = pid; | |
400 |
|
411 | |||
|
412 | pid_t pgid = hgc_peerpgid(hgc); | |||
|
413 | peerpgid = (pgid <= 1 ? 0 : pgid); | |||
|
414 | ||||
401 | struct sigaction sa; |
|
415 | struct sigaction sa; | |
402 | memset(&sa, 0, sizeof(sa)); |
|
416 | memset(&sa, 0, sizeof(sa)); | |
403 | sa.sa_handler = forwardsignal; |
|
417 | sa.sa_handler = forwardsignaltogroup; | |
404 | sa.sa_flags = SA_RESTART; |
|
418 | sa.sa_flags = SA_RESTART; | |
405 | if (sigemptyset(&sa.sa_mask) < 0) |
|
419 | if (sigemptyset(&sa.sa_mask) < 0) | |
406 | goto error; |
|
420 | goto error; | |
@@ -411,6 +425,7 b' static void setupsignalhandler(pid_t pid' | |||||
411 | goto error; |
|
425 | goto error; | |
412 |
|
426 | |||
413 | /* terminate frontend by double SIGTERM in case of server freeze */ |
|
427 | /* terminate frontend by double SIGTERM in case of server freeze */ | |
|
428 | sa.sa_handler = forwardsignal; | |||
414 | sa.sa_flags |= SA_RESETHAND; |
|
429 | sa.sa_flags |= SA_RESETHAND; | |
415 | if (sigaction(SIGTERM, &sa, NULL) < 0) |
|
430 | if (sigaction(SIGTERM, &sa, NULL) < 0) | |
416 | goto error; |
|
431 | goto error; | |
@@ -656,7 +671,7 b' int main(int argc, const char *argv[], c' | |||||
656 | gethgcmd()); |
|
671 | gethgcmd()); | |
657 | } |
|
672 | } | |
658 |
|
673 | |||
659 |
setupsignalhandler( |
|
674 | setupsignalhandler(hgc); | |
660 | pagerpid = setuppager(hgc, argv + 1, argc - 1); |
|
675 | pagerpid = setuppager(hgc, argv + 1, argc - 1); | |
661 | int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1); |
|
676 | int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1); | |
662 | restoresignalhandler(); |
|
677 | restoresignalhandler(); |
General Comments 0
You need to be logged in to leave comments.
Login now