mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-22 22:03:43 +03:00
fd-util: special case invocation of close_all_fds() with single exception fd
Add special case optimization for a single exception fd. It's a pretty common case in our codebase, and the optimization is simple and means we don't need to copy/sort the exception array, so do it.
This commit is contained in:
parent
11966552a8
commit
f498720a34
@ -268,6 +268,21 @@ int close_all_fds(const int except[], size_t n_except) {
|
||||
return -errno;
|
||||
|
||||
have_close_range = false;
|
||||
|
||||
} else if (n_except == 1) {
|
||||
|
||||
/* Close all but exactly one, then we don't need no sorting. This is a pretty common
|
||||
* case, hence let's handle it specially. */
|
||||
|
||||
if ((except[0] <= 3 || close_range(3, except[0]-1, 0) >= 0) &&
|
||||
(except[0] >= INT_MAX || close_range(MAX(3, except[0]+1), -1, 0) >= 0))
|
||||
return 0;
|
||||
|
||||
if (!ERRNO_IS_NOT_SUPPORTED(errno) && !ERRNO_IS_PRIVILEGE(errno))
|
||||
return -errno;
|
||||
|
||||
have_close_range = false;
|
||||
|
||||
} else {
|
||||
_cleanup_free_ int *sorted_malloc = NULL;
|
||||
size_t n_sorted;
|
||||
|
Loading…
x
Reference in New Issue
Block a user