summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2021-03-29 11:44:41 +0200
committerMatthew Heon <mheon@redhat.com>2021-04-16 13:46:39 -0400
commitc042b4c82014c7a3841969c3bfab70203e7cecd6 (patch)
tree9b3480b3b55b3df8fdd3f52d91c50745606cdc2c
parentb76cc706ad8b8991f741fc12704f535a79769a7b (diff)
downloadpodman-c042b4c82014c7a3841969c3bfab70203e7cecd6.tar.gz
podman-c042b4c82014c7a3841969c3bfab70203e7cecd6.tar.bz2
podman-c042b4c82014c7a3841969c3bfab70203e7cecd6.zip
rootless: use is_fd_inherited
since we already have an exported function that does the check, refactor the code to use it instead of duplicating the logic. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
-rw-r--r--pkg/rootless/rootless_linux.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c
index d93e4c10c..7a2bf0377 100644
--- a/pkg/rootless/rootless_linux.c
+++ b/pkg/rootless/rootless_linux.c
@@ -233,9 +233,8 @@ int
is_fd_inherited(int fd)
{
if (open_files_set == NULL || fd > open_files_max_fd || fd < 0)
- {
return 0;
- }
+
return FD_ISSET(fd % FD_SETSIZE, &(open_files_set[fd / FD_SETSIZE])) ? 1 : 0;
}
@@ -633,9 +632,10 @@ reexec_userns_join (int pid_to_join, char *pause_pid_file_path)
close (user_ns);
close (mnt_ns);
- for (f = 3; f < open_files_max_fd; f++)
- if (open_files_set == NULL || FD_ISSET (f % FD_SETSIZE, &(open_files_set[f / FD_SETSIZE])))
+ for (f = 3; f <= open_files_max_fd; f++)
+ if (is_fd_inherited (f))
close (f);
+
return pid;
}
@@ -813,13 +813,14 @@ reexec_in_user_namespace (int ready, char *pause_pid_file_path, char *file_to_re
if (do_socket_activation)
{
long num_fds;
+
num_fds = strtol (listen_fds, NULL, 10);
if (num_fds != LONG_MIN && num_fds != LONG_MAX)
{
int f;
for (f = 3; f < num_fds + 3; f++)
- if (open_files_set == NULL || FD_ISSET (f % FD_SETSIZE, &(open_files_set[f / FD_SETSIZE])))
+ if (is_fd_inherited (f))
close (f);
}
unsetenv ("LISTEN_PID");