Commit 31fa1fb
committed
run-command: add pre-exec callback for child processes
Add a pre_exec_cb function pointer to struct child_process that is
invoked in the child between fork and exec. This gives callers a
place to perform setup that must happen in the child's context,
such as closing inherited file descriptors.
Provide close_fd_above_stderr() as a ready-made callback that
closes file descriptors 3 and above (skipping the child-notifier
pipe), capped at sysconf(_SC_OPEN_MAX) or 4096, whichever is
smaller.
Signed-off-by: Paul Tarjan <github@paulisageek.com>1 parent 03cf12d commit 31fa1fb
2 files changed
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
677 | 689 | | |
678 | 690 | | |
679 | 691 | | |
| |||
832 | 844 | | |
833 | 845 | | |
834 | 846 | | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
835 | 850 | | |
836 | 851 | | |
837 | 852 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
144 | 152 | | |
145 | 153 | | |
146 | 154 | | |
| |||
149 | 157 | | |
150 | 158 | | |
151 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
152 | 167 | | |
153 | 168 | | |
154 | 169 | | |
| |||
0 commit comments