Skip to content

Commit

Permalink
start-stop-daemon: set fds to CLOEXEC instead of closing
Browse files Browse the repository at this point in the history
Set file descriptors to CLOEXEC instead of closing them before exec,
similar to what we do in supervise-daemon.

Use the share cloexec_fds_from() helper for this.

closefrom() is no longer used so remove the test.
  • Loading branch information
ncopa committed Aug 30, 2023
1 parent 9bfc50b commit cbd9f2c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
3 changes: 0 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ if cc.compiles(malloc_attribute_test, name : 'malloc attribute with arguments')
add_project_arguments('-DHAVE_MALLOC_EXTENDED_ATTRIBUTE', language: 'c')
endif

if cc.has_function('closefrom', prefix: '#define _GNU_SOURCE\n#include <unistd.h>')
add_project_arguments('-DHAVE_CLOSEFROM', language: 'c')
endif
if cc.has_function('close_range', prefix: '#define _GNU_SOURCE\n#include <unistd.h>') and \
cc.has_header_symbol('unistd.h', 'CLOSE_RANGE_CLOEXEC', prefix: '#define _GNU_SOURCE')
add_project_arguments('-DHAVE_CLOSE_RANGE', language: 'c')
Expand Down
7 changes: 1 addition & 6 deletions src/start-stop-daemon/start-stop-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,7 @@ int main(int argc, char **argv)
|| rc_yesno(getenv("EINFO_QUIET")))
dup2(stderr_fd, STDERR_FILENO);

#ifdef HAVE_CLOSEFROM
closefrom(3);
#else
for (i = getdtablesize() - 1; i >= 3; --i)
close(i);
#endif
cloexec_fds_from(3);

if (scheduler != NULL) {
int scheduler_index;
Expand Down

0 comments on commit cbd9f2c

Please sign in to comment.