Show More
@@ -338,6 +338,7 b' static void killcmdserver(const struct c' | |||||
338 | } |
|
338 | } | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
|
341 | static pid_t pagerpid = 0; | |||
341 | static pid_t peerpid = 0; |
|
342 | static pid_t peerpid = 0; | |
342 |
|
343 | |||
343 | static void forwardsignal(int sig) |
|
344 | static void forwardsignal(int sig) | |
@@ -380,6 +381,17 b' error:' | |||||
380 | abortmsgerrno("failed to handle stop signal"); |
|
381 | abortmsgerrno("failed to handle stop signal"); | |
381 | } |
|
382 | } | |
382 |
|
383 | |||
|
384 | static void handlechildsignal(int sig) | |||
|
385 | { | |||
|
386 | if (peerpid == 0 || pagerpid == 0) | |||
|
387 | return; | |||
|
388 | /* if pager exits, notify the server with SIGPIPE immediately. | |||
|
389 | * otherwise the server won't get SIGPIPE if it does not write | |||
|
390 | * anything. (issue5278) */ | |||
|
391 | if (waitpid(pagerpid, NULL, WNOHANG) == pagerpid) | |||
|
392 | kill(peerpid, SIGPIPE); | |||
|
393 | } | |||
|
394 | ||||
383 | static void setupsignalhandler(pid_t pid) |
|
395 | static void setupsignalhandler(pid_t pid) | |
384 | { |
|
396 | { | |
385 | if (pid <= 0) |
|
397 | if (pid <= 0) | |
@@ -416,6 +428,11 b' static void setupsignalhandler(pid_t pid' | |||||
416 | sa.sa_flags = SA_RESTART; |
|
428 | sa.sa_flags = SA_RESTART; | |
417 | if (sigaction(SIGTSTP, &sa, NULL) < 0) |
|
429 | if (sigaction(SIGTSTP, &sa, NULL) < 0) | |
418 | goto error; |
|
430 | goto error; | |
|
431 | /* get notified when pager exits */ | |||
|
432 | sa.sa_handler = handlechildsignal; | |||
|
433 | sa.sa_flags = SA_RESTART; | |||
|
434 | if (sigaction(SIGCHLD, &sa, NULL) < 0) | |||
|
435 | goto error; | |||
419 |
|
436 | |||
420 | return; |
|
437 | return; | |
421 |
|
438 | |||
@@ -442,6 +459,8 b' static void restoresignalhandler()' | |||||
442 | goto error; |
|
459 | goto error; | |
443 | if (sigaction(SIGTSTP, &sa, NULL) < 0) |
|
460 | if (sigaction(SIGTSTP, &sa, NULL) < 0) | |
444 | goto error; |
|
461 | goto error; | |
|
462 | if (sigaction(SIGCHLD, &sa, NULL) < 0) | |||
|
463 | goto error; | |||
445 |
|
464 | |||
446 | /* ignore Ctrl+C while shutting down to make pager exits cleanly */ |
|
465 | /* ignore Ctrl+C while shutting down to make pager exits cleanly */ | |
447 | sa.sa_handler = SIG_IGN; |
|
466 | sa.sa_handler = SIG_IGN; | |
@@ -638,7 +657,7 b' int main(int argc, const char *argv[], c' | |||||
638 | } |
|
657 | } | |
639 |
|
658 | |||
640 | setupsignalhandler(hgc_peerpid(hgc)); |
|
659 | setupsignalhandler(hgc_peerpid(hgc)); | |
641 |
|
|
660 | pagerpid = setuppager(hgc, argv + 1, argc - 1); | |
642 | int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1); |
|
661 | int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1); | |
643 | restoresignalhandler(); |
|
662 | restoresignalhandler(); | |
644 | hgc_close(hgc); |
|
663 | hgc_close(hgc); |
General Comments 0
You need to be logged in to leave comments.
Login now