Commit d4a258d
committed
Make sure archive and restore comamnds do not leak files
As reported by Roman Leventov in
percona/postgres#582 we had an issue where we
easily could leak tmeporary files and directories when on failure,
especially when the wrapped restore or archive command fails.
The solution in this commit is to move the cleanup of temporary files
and directories to and atexit() callback plus add a signal handler for
SIGINT and SIGTERM. The signal handler makes sure to kill itself after
running cleanup so the parent process gets the right error.
We have a tiny race condition between creating the temporary directory
and registering the signal handler but that does not seem worth fixing
since it would just leak a directory, not the WAL file, the race
conditions being tiny.1 parent 2f0315d commit d4a258d
2 files changed
+54
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
137 | 160 | | |
138 | 161 | | |
139 | 162 | | |
| |||
143 | 166 | | |
144 | 167 | | |
145 | 168 | | |
146 | | - | |
147 | | - | |
148 | 169 | | |
149 | 170 | | |
150 | 171 | | |
| |||
199 | 220 | | |
200 | 221 | | |
201 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
202 | 227 | | |
203 | 228 | | |
204 | 229 | | |
| |||
228 | 253 | | |
229 | 254 | | |
230 | 255 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | 256 | | |
240 | 257 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
132 | 155 | | |
133 | 156 | | |
134 | 157 | | |
| |||
138 | 161 | | |
139 | 162 | | |
140 | 163 | | |
141 | | - | |
142 | | - | |
143 | 164 | | |
144 | 165 | | |
145 | 166 | | |
| |||
194 | 215 | | |
195 | 216 | | |
196 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
197 | 222 | | |
198 | 223 | | |
199 | 224 | | |
| |||
222 | 247 | | |
223 | 248 | | |
224 | 249 | | |
225 | | - | |
226 | 250 | | |
227 | 251 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | 252 | | |
235 | 253 | | |
0 commit comments