- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit97550c0
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 parent2406c4e commit97550c0
5 files changed
+62
-1
lines changedLines changed: 16 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
| 22 | + | |
| 23 | + | |
22 | 24 |
| |
23 | 25 |
| |
24 | 26 |
| |
| |||
121 | 123 |
| |
122 | 124 |
| |
123 | 125 |
| |
124 |
| - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
125 | 140 |
| |
126 | 141 |
| |
127 | 142 |
| |
|
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 | |
---|---|---|---|
| |||
806 | 806 |
| |
807 | 807 |
| |
808 | 808 |
| |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
809 | 813 |
| |
810 | 814 |
| |
811 | 815 |
| |
| |||
926 | 930 |
| |
927 | 931 |
| |
928 | 932 |
| |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
929 | 937 |
| |
930 | 938 |
| |
931 | 939 |
| |
|
Lines changed: 28 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3733 | 3733 |
| |
3734 | 3734 |
| |
3735 | 3735 |
| |
| 3736 | + | |
| 3737 | + | |
| 3738 | + | |
| 3739 | + | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
3736 | 3764 |
| |
3737 | 3765 |
| |
3738 | 3766 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
536 | 536 |
| |
537 | 537 |
| |
538 | 538 |
| |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
539 | 545 |
|
0 commit comments
Comments
(0)