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