Skip to content

Commit

Permalink
Merge branch 'PR/nsenter-pidfd' of https://github.com/karelzak/util-l…
Browse files Browse the repository at this point in the history
…inux-work

* 'PR/nsenter-pidfd' of https://github.com/karelzak/util-linux-work:
  nsenter: Rewrite --user-parent to use pidfd
  include/pidfd-utils: add namespaces ioctls
  nsenter: reuse pidfd for --net-socket
  nsenter: use macros to access the nsfiles array
  nsenter: use pidfd to enter target namespaces
  nsenter: use separate function to enter namespaces
  nsenter: add functions to enable/disable namespaces
  • Loading branch information
karelzak committed Nov 5, 2024
2 parents 4508f7a + 7e60554 commit 0e0fafc
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 127 deletions.
27 changes: 24 additions & 3 deletions include/pidfd-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,35 @@
#include <sys/types.h>
#include <sys/wait.h>

#ifdef HAVE_SYS_PIDFD_H
# include <sys/pidfd.h>
#endif

/*
* pidfd ioctls
*
* All added by commit to kernel 6.11, commit 5b08bd408534bfb3a7cf5778da5b27d4e4fffe12.
*/
#ifndef PIDFS_IOCTL_MAGIC
# define PIDFS_IOCTL_MAGIC 0xFF
# define PIDFD_GET_CGROUP_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 1)
# define PIDFD_GET_IPC_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 2)
# define PIDFD_GET_MNT_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 3)
# define PIDFD_GET_NET_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 4)
# define PIDFD_GET_PID_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 5)
# define PIDFD_GET_PID_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 6)
# define PIDFD_GET_TIME_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 7)
# define PIDFD_GET_TIME_FOR_CHILDREN_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 8)
# define PIDFD_GET_USER_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 9)
# define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10)
#endif


#ifdef HAVE_SYS_SYSCALL_H
# include <sys/syscall.h>
# include <unistd.h>

# if defined(SYS_pidfd_send_signal) && defined(SYS_pidfd_open)
# ifdef HAVE_SYS_PIDFD_H
# include <sys/pidfd.h>
# endif
# ifndef HAVE_PIDFD_SEND_SIGNAL
static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
unsigned int flags)
Expand Down
Loading

0 comments on commit 0e0fafc

Please sign in to comment.