GDBserver
Classes | Macros | Enumerations | Functions | Variables
linux-namespaces.c File Reference
#include "common-defs.h"
#include "nat/linux-namespaces.h"
#include "filestuff.h"
#include <fcntl.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include "gdb_wait.h"
#include <signal.h>
#include <sched.h>

Go to the source code of this file.

Classes

struct  linux_ns
 
struct  linux_mnsh
 

Macros

#define MSG_CMSG_CLOEXEC   0
 
#define mnsh_return_int(sock, result, error)   mnsh_send_message (sock, MNSH_RET_INT, -1, result, error, NULL, 0)
 
#define mnsh_return_fd(sock, fd, error)
 
#define mnsh_return_intstr(sock, result, buf, bufsiz, error)
 
#define mnsh_send_setns(helper, fd, nstype)
 
#define mnsh_send_open(helper, filename, flags, mode)
 
#define mnsh_send_unlink(helper, filename)
 
#define mnsh_send_readlink(helper, filename)
 

Enumerations

enum  mnsh_msg_type {
  MNSH_MSG_ERROR, MNSH_REQ_SETNS, MNSH_REQ_OPEN, MNSH_REQ_UNLINK,
  MNSH_REQ_READLINK, MNSH_RET_INT, MNSH_RET_FD, MNSH_RET_INTSTR
}
 
enum  mnsh_fs_code { MNSH_FS_ERROR = -1, MNSH_FS_DIRECT, MNSH_FS_HELPER }
 

Functions

static int setns (int fd, int nstype)
 
static const char * linux_ns_filename (struct linux_ns *ns, int pid)
 
static struct linux_nslinux_ns_get_namespace (enum linux_ns_type type)
 
int linux_ns_same (pid_t pid, enum linux_ns_type type)
 
static void mnsh_debug_print_message (enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)
 
static void mnsh_maybe_mourn_peer (void)
 
static ssize_t mnsh_send_message (int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)
 
static ssize_t mnsh_recv_message (int sock, enum mnsh_msg_type *type, int *fd, int *int1, int *int2, void *buf, int bufsiz)
 
static ssize_t mnsh_handle_setns (int sock, int fd, int nstype)
 
static ssize_t mnsh_handle_open (int sock, const char *filename, int flags, mode_t mode)
 
static ssize_t mnsh_handle_unlink (int sock, const char *filename)
 
static ssize_t mnsh_handle_readlink (int sock, const char *filename)
 
static void mnsh_main (int sock) ATTRIBUTE_NORETURN
 
static struct linux_mnshlinux_mntns_get_helper (void)
 
static int mnsh_recv_int (struct linux_mnsh *helper, int *result, int *error)
 
static int mnsh_recv_fd (struct linux_mnsh *helper, int *fd, int *error)
 
static ssize_t mnsh_recv_intstr (struct linux_mnsh *helper, int *result, int *error, void *buf, int bufsiz)
 
static enum mnsh_fs_code linux_mntns_access_fs (pid_t pid)
 
int linux_mntns_open_cloexec (pid_t pid, const char *filename, int flags, mode_t mode)
 
int linux_mntns_unlink (pid_t pid, const char *filename)
 
ssize_t linux_mntns_readlink (pid_t pid, const char *filename, char *buf, size_t bufsiz)
 

Variables

int debug_linux_namespaces
 
static int mnsh_creator_pid = 0
 

Macro Definition Documentation

#define mnsh_return_fd (   sock,
  fd,
  error 
)
Value:
(fd) < 0 ? -1 : (fd), \
(fd) < 0 ? (fd) : 0, \
error, NULL, 0)
static ssize_t mnsh_send_message(int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)
void error(const char *fmt,...)
Definition: errors.c:38

Definition at line 483 of file linux-namespaces.c.

Referenced by mnsh_handle_open().

#define mnsh_return_int (   sock,
  result,
  error 
)    mnsh_send_message (sock, MNSH_RET_INT, -1, result, error, NULL, 0)

Definition at line 480 of file linux-namespaces.c.

Referenced by mnsh_handle_setns(), and mnsh_handle_unlink().

#define mnsh_return_intstr (   sock,
  result,
  buf,
  bufsiz,
  error 
)
Value:
mnsh_send_message (sock, MNSH_RET_INTSTR, -1, result, error, \
buf, bufsiz)
static ssize_t mnsh_send_message(int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)
void error(const char *fmt,...)
Definition: errors.c:38

Definition at line 489 of file linux-namespaces.c.

Referenced by mnsh_handle_readlink().

#define mnsh_send_open (   helper,
  filename,
  flags,
  mode 
)
Value:
mnsh_send_message (helper->sock, MNSH_REQ_OPEN, -1, flags, mode, \
filename, strlen (filename) + 1)
static ssize_t mnsh_send_message(int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)

Definition at line 758 of file linux-namespaces.c.

Referenced by linux_mntns_open_cloexec().

#define mnsh_send_readlink (   helper,
  filename 
)
Value:
mnsh_send_message (helper->sock, MNSH_REQ_READLINK, -1, 0, 0, \
filename, strlen (filename) + 1)
static ssize_t mnsh_send_message(int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)

Definition at line 766 of file linux-namespaces.c.

Referenced by linux_mntns_readlink().

#define mnsh_send_setns (   helper,
  fd,
  nstype 
)
Value:
mnsh_send_message (helper->sock, MNSH_REQ_SETNS, fd, nstype, 0, \
NULL, 0)
static ssize_t mnsh_send_message(int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)

Definition at line 754 of file linux-namespaces.c.

Referenced by linux_mntns_access_fs().

#define mnsh_send_unlink (   helper,
  filename 
)
Value:
mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, \
filename, strlen (filename) + 1)
static ssize_t mnsh_send_message(int sock, enum mnsh_msg_type type, int fd, int int1, int int2, const void *buf, int bufsiz)

Definition at line 762 of file linux-namespaces.c.

Referenced by linux_mntns_unlink().

#define MSG_CMSG_CLOEXEC   0

Definition at line 53 of file linux-namespaces.c.

Referenced by mnsh_recv_message().

Enumeration Type Documentation

Enumerator
MNSH_FS_ERROR 
MNSH_FS_DIRECT 
MNSH_FS_HELPER 

Definition at line 857 of file linux-namespaces.c.

Enumerator
MNSH_MSG_ERROR 
MNSH_REQ_SETNS 
MNSH_REQ_OPEN 
MNSH_REQ_UNLINK 
MNSH_REQ_READLINK 
MNSH_RET_INT 
MNSH_RET_FD 
MNSH_RET_INTSTR 

Definition at line 208 of file linux-namespaces.c.

Function Documentation

static enum mnsh_fs_code linux_mntns_access_fs ( pid_t  pid)
static
static struct linux_mnsh* linux_mntns_get_helper ( void  )
static
int linux_mntns_open_cloexec ( pid_t  pid,
const char *  filename,
int  flags,
mode_t  mode 
)
ssize_t linux_mntns_readlink ( pid_t  pid,
const char *  filename,
char *  buf,
size_t  bufsiz 
)
int linux_mntns_unlink ( pid_t  pid,
const char *  filename 
)
static const char* linux_ns_filename ( struct linux_ns ns,
int  pid 
)
static
static struct linux_ns* linux_ns_get_namespace ( enum linux_ns_type  type)
static
int linux_ns_same ( pid_t  pid,
enum linux_ns_type  type 
)
static void mnsh_debug_print_message ( enum mnsh_msg_type  type,
int  fd,
int  int1,
int  int2,
const void *  buf,
int  bufsiz 
)
static
static ssize_t mnsh_handle_open ( int  sock,
const char *  filename,
int  flags,
mode_t  mode 
)
static

Definition at line 506 of file linux-namespaces.c.

References errno, gdb_open_cloexec(), and mnsh_return_fd.

Referenced by mnsh_main().

static ssize_t mnsh_handle_readlink ( int  sock,
const char *  filename 
)
static

Definition at line 531 of file linux-namespaces.c.

References errno, and mnsh_return_intstr.

Referenced by mnsh_main().

static ssize_t mnsh_handle_setns ( int  sock,
int  fd,
int  nstype 
)
static

Definition at line 496 of file linux-namespaces.c.

References errno, mnsh_return_int, and setns().

Referenced by mnsh_main().

static ssize_t mnsh_handle_unlink ( int  sock,
const char *  filename 
)
static

Definition at line 521 of file linux-namespaces.c.

References errno, and mnsh_return_int.

Referenced by mnsh_main().

static void mnsh_main ( int  sock)
static
static void mnsh_maybe_mourn_peer ( void  )
static
static int mnsh_recv_fd ( struct linux_mnsh helper,
int *  fd,
int *  error 
)
static

Definition at line 802 of file linux-namespaces.c.

References gdb_assert, mnsh_recv_message(), MNSH_RET_FD, and linux_mnsh::sock.

Referenced by linux_mntns_open_cloexec().

static int mnsh_recv_int ( struct linux_mnsh helper,
int *  result,
int *  error 
)
static
static ssize_t mnsh_recv_intstr ( struct linux_mnsh helper,
int *  result,
int *  error,
void *  buf,
int  bufsiz 
)
static

Definition at line 834 of file linux-namespaces.c.

References gdb_assert, mnsh_recv_message(), MNSH_RET_INTSTR, and linux_mnsh::sock.

Referenced by linux_mntns_readlink().

static ssize_t mnsh_recv_message ( int  sock,
enum mnsh_msg_type type,
int *  fd,
int *  int1,
int *  int2,
void *  buf,
int  bufsiz 
)
static
static ssize_t mnsh_send_message ( int  sock,
enum mnsh_msg_type  type,
int  fd,
int  int1,
int  int2,
const void *  buf,
int  bufsiz 
)
static
static int setns ( int  fd,
int  nstype 
)
static

Definition at line 39 of file linux-namespaces.c.

References errno.

Referenced by mnsh_handle_setns().

Variable Documentation

int debug_linux_namespaces

Definition at line 33 of file linux-namespaces.c.

Referenced by linux_mntns_get_helper(), mnsh_recv_message(), and mnsh_send_message().

int mnsh_creator_pid = 0
static

Definition at line 621 of file linux-namespaces.c.

Referenced by linux_mntns_get_helper(), and mnsh_maybe_mourn_peer().