- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitd0e7f95
committed
Avoid calling proc_exit() in processes forked by system().
The SIGTERM handler for the startup process immediately callsproc_exit() for the duration of the restore_command, i.e., a callto system(). This system() call forks a new process to execute theshell command, and this child process inherits the parent's signalhandlers. If both the parent and child processes receive SIGTERM,both will attempt to call proc_exit(). This can end badly. Forexample, both processes will try to remove themselves from thePGPROC shared array.To fix this problem, this commit adds a check inStartupProcShutdownHandler() to see whether MyProcPid == getpid().If they match, this is the parent process, and we can proc_exit()like before. If they do not match, this is a child process, and wejust emit a message to STDERR (in a signal safe manner) and_exit(), thereby skipping any problematic exit callbacks.This commit also adds checks in proc_exit(), ProcKill(), andAuxiliaryProcKill() that verify they are not being called withinsuch child processes.Suggested-by: Andres FreundReviewed-by: Thomas Munro, Andres FreundDiscussion:https://postgr.es/m/Y9nGDSgIm83FHcad%40paquier.xyzDiscussion:https://postgr.es/m/20230223231503.GA743455%40nathanxps13Backpatch-through: 111 parenta295684 commitd0e7f95
5 files changed
+60
-1
lines changedLines changed: 14 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
132 | 132 |
| |
133 | 133 |
| |
134 | 134 |
| |
135 |
| - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
136 | 149 |
| |
137 | 150 |
| |
138 | 151 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
106 | 110 |
| |
107 | 111 |
| |
108 | 112 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
805 | 805 |
| |
806 | 806 |
| |
807 | 807 |
| |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
808 | 812 |
| |
809 | 813 |
| |
810 | 814 |
| |
| |||
929 | 933 |
| |
930 | 934 |
| |
931 | 935 |
| |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
932 | 940 |
| |
933 | 941 |
| |
934 | 942 |
| |
|
Lines changed: 28 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3703 | 3703 |
| |
3704 | 3704 |
| |
3705 | 3705 |
| |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
| 3732 | + | |
| 3733 | + | |
3706 | 3734 |
| |
3707 | 3735 |
| |
3708 | 3736 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
413 | 413 |
| |
414 | 414 |
| |
415 | 415 |
| |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
416 | 422 |
|
0 commit comments
Comments
(0)