Skip to content

Commit

Permalink
Merge pull request #1265 from giuseppe/simplify-setns-with-pidfd
Browse files Browse the repository at this point in the history
linux: simplify setns with pidfd
  • Loading branch information
flouthoc authored Aug 8, 2023
2 parents 727fd28 + 88441d9 commit 203c5e1
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -4849,28 +4849,9 @@ try_setns_with_pidfd (pid_t pid_to_join, libcrun_container_t *container, libcrun
for (i = 0; namespaces[i].ns_file; i++)
all_flags |= namespaces[i].value;

if (all_flags & CLONE_NEWUSER)
{
ret = setns (pidfd_pid_to_join, CLONE_NEWUSER);
if (UNLIKELY (ret < 0))
{
/* Ignore the EINVAL error code. The kernel might not support setns + pidfd. */
if (errno == EINVAL)
return 0;

return crun_make_error (err, errno, "setns(pid=%d, CLONE_NEWUSER)", pid_to_join);
}
}

ret = setns (pidfd_pid_to_join, all_flags);
if (UNLIKELY (ret < 0))
{
/* Ignore the EINVAL error code. The kernel might not support setns + pidfd. */
if (errno == EINVAL)
return 0;

return crun_make_error (err, errno, "setns(pid=%d, CLONE_*)", pid_to_join);
}
return 0;

return 1;
}
Expand All @@ -4896,7 +4877,7 @@ join_process_namespaces (libcrun_container_t *container, pid_t pid_to_join, libc
if (LIKELY (ret > 0))
return 0;

/* If setns with the target pidfd, fall-back to join each namespace individually. */
/* If setns fails with the target pidfd, fall-back to join each namespace individually. */

if (def->linux->namespaces_len >= MAX_NAMESPACES)
return crun_make_error (err, 0, "invalid configuration");
Expand Down

0 comments on commit 203c5e1

Please sign in to comment.