Commit 08ef174
committed
Fix signal handling - waiting for multiple processes
In tooldata_db.cc (line 67), the old code does:
1. waitpid(..., WNOHANG) in a while (...) ; loop with an empty body.
2. Then evaluates WIFSIGNALED(status) and WIFEXITED(status) once, after the loop.
The problem is:
1. waitpid only writes status when it returns > 0.
2. With WNOHANG, it can return 0 immediately (no state change yet), or -1 on error.
3. In those cases, status is not guaranteed to be written.
4. The code then reads status anyway via WIF* macros, so it can read stale/uninitialized data.
5. That can cause false logs and incorrectly set db_live = 0.
What the patch changes:
1. It moves WIFSIGNALED/WIFEXITED checks inside the while (waitpid(...) > 0) loop.
2. status is only inspected in iterations where waitpid definitely produced a valid child status.
3. If no child was reapable, the loop does not run, and nothing is logged or toggled.
4. If multiple children changed state, each valid status is handled, instead of only the last one.1 parent 8839d22 commit 08ef174
1 file changed
Lines changed: 20 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
80 | 81 | | |
81 | | - | |
| 82 | + | |
82 | 83 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
89 | 90 | | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
0 commit comments