|
|
0b42f8 |
Introduce nat/linux-namespaces.[ch]
|
|
|
0b42f8 |
|
|
|
0b42f8 |
From: Gary Benson <gbenson@redhat.com>
|
|
|
0b42f8 |
|
|
|
0b42f8 |
This commit introduces new shared files nat/linux-namespaces.[ch]
|
|
|
0b42f8 |
containing code to support Linux namespaces that will be used by
|
|
|
0b42f8 |
both GDB and gdbserver.
|
|
|
0b42f8 |
|
|
|
0b42f8 |
gdb/ChangeLog:
|
|
|
0b42f8 |
|
|
|
0b42f8 |
* configure.ac (AC_CHECK_FUNCS): Add setns.
|
|
|
0b42f8 |
* config.in: Regenerate.
|
|
|
0b42f8 |
* configure: Likewise.
|
|
|
0b42f8 |
* nat/linux-namespaces.h: New file.
|
|
|
0b42f8 |
* nat/linux-namespaces.c: Likewise.
|
|
|
0b42f8 |
* Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-namespaces.h.
|
|
|
0b42f8 |
(linux-namespaces.o): New rule.
|
|
|
0b42f8 |
* config/aarch64/linux.mh (NATDEPFILES): Add linux-namespaces.o.
|
|
|
0b42f8 |
* config/alpha/alpha-linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/arm/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/i386/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/i386/linux64.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/ia64/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/m32r/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/m68k/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/mips/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/pa/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/powerpc/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/powerpc/spu-linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/s390/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/sparc/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/sparc/linux64.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/tilegx/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
* config/xtensa/linux.mh (NATDEPFILES): Likewise.
|
|
|
0b42f8 |
|
|
|
0b42f8 |
gdb/gdbserver/ChangeLog:
|
|
|
0b42f8 |
|
|
|
0b42f8 |
* configure.ac (AC_CHECK_FUNCS): Add setns.
|
|
|
0b42f8 |
* config.in: Regenerate.
|
|
|
0b42f8 |
* configure: Likewise.
|
|
|
0b42f8 |
* Makefile.in (SFILES): Add nat/linux-namespaces.c.
|
|
|
0b42f8 |
(linux-namespaces.o): New rule.
|
|
|
0b42f8 |
* configure.srv (srv_linux_obj): Add linux-namespaces.o.
|
|
|
0b42f8 |
---
|
|
|
0b42f8 |
gdb/Makefile.in | 7
|
|
|
0b42f8 |
gdb/gdbserver/Makefile.in | 6
|
|
|
0b42f8 |
gdb/gdbserver/config.in | 3
|
|
|
0b42f8 |
gdb/gdbserver/configure | 2
|
|
|
0b42f8 |
gdb/gdbserver/configure.ac | 2
|
|
|
0b42f8 |
gdb/gdbserver/configure.srv | 38 +
|
|
|
0b42f8 |
gdb/nat/linux-namespaces.c | 1093 +++++++++++++++++++++++++++++++++++++++++++
|
|
|
0b42f8 |
gdb/nat/linux-namespaces.h | 78 +++
|
|
|
0b42f8 |
8 files changed, 1206 insertions(+), 23 deletions(-)
|
|
|
0b42f8 |
create mode 100644 gdb/nat/linux-namespaces.c
|
|
|
0b42f8 |
create mode 100644 gdb/nat/linux-namespaces.h
|
|
|
0b42f8 |
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/Makefile.in
|
|
|
0b42f8 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/Makefile.in 2018-05-18 10:55:27.630976775 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/Makefile.in 2018-05-18 10:55:28.422983192 +0200
|
|
|
0b42f8 |
@@ -840,7 +840,8 @@
|
|
|
0b42f8 |
common/common-utils.h common/xml-utils.h common/buffer.h common/ptid.h \
|
|
|
0b42f8 |
common/format.h common/host-defs.h utils.h common/queue.h common/gdb_string.h \
|
|
|
0b42f8 |
common/linux-osdata.h gdb-dlfcn.h auto-load.h probe.h stap-probe.h \
|
|
|
0b42f8 |
-gdb_bfd.h sparc-ravenscar-thread.h ppc-ravenscar-thread.h common/linux-btrace.h
|
|
|
0b42f8 |
+gdb_bfd.h sparc-ravenscar-thread.h ppc-ravenscar-thread.h common/linux-btrace.h \
|
|
|
0b42f8 |
+nat/linux-namespaces.h
|
|
|
0b42f8 |
|
|
|
0b42f8 |
# Header files that already have srcdir in them, or which are in objdir.
|
|
|
0b42f8 |
|
|
|
0b42f8 |
@@ -2037,6 +2038,10 @@
|
|
|
0b42f8 |
$(COMPILE) $(srcdir)/common/linux-btrace.c
|
|
|
0b42f8 |
$(POSTCOMPILE)
|
|
|
0b42f8 |
|
|
|
0b42f8 |
+linux-namespaces.o: ${srcdir}/nat/linux-namespaces.c
|
|
|
0b42f8 |
+ $(COMPILE) $(srcdir)/nat/linux-namespaces.c
|
|
|
0b42f8 |
+ $(POSTCOMPILE)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
#
|
|
|
0b42f8 |
# gdb/tui/ dependencies
|
|
|
0b42f8 |
#
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/gdbserver/Makefile.in
|
|
|
0b42f8 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/gdbserver/Makefile.in 2018-05-18 10:55:28.251981806 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/gdbserver/Makefile.in 2018-05-18 10:55:28.422983192 +0200
|
|
|
0b42f8 |
@@ -155,7 +155,8 @@
|
|
|
0b42f8 |
$(srcdir)/common/vec.c $(srcdir)/common/gdb_vecs.c \
|
|
|
0b42f8 |
$(srcdir)/common/common-utils.c $(srcdir)/common/xml-utils.c \
|
|
|
0b42f8 |
$(srcdir)/common/linux-osdata.c $(srcdir)/common/ptid.c \
|
|
|
0b42f8 |
- $(srcdir)/common/buffer.c $(srcdir)/common/linux-btrace.c
|
|
|
0b42f8 |
+ $(srcdir)/common/buffer.c $(srcdir)/common/linux-btrace.c \
|
|
|
0b42f8 |
+ $(srcdir)/nat/linux-namespaces.c
|
|
|
0b42f8 |
|
|
|
0b42f8 |
DEPFILES = @GDBSERVER_DEPFILES@
|
|
|
0b42f8 |
|
|
|
0b42f8 |
@@ -568,6 +569,9 @@
|
|
|
0b42f8 |
linux-low.o: linux-low.c
|
|
|
0b42f8 |
$(COMPILE) $< @USE_THREAD_DB@
|
|
|
0b42f8 |
$(POSTCOMPILE)
|
|
|
0b42f8 |
+linux-namespaces.o: ../nat/linux-namespaces.c
|
|
|
0b42f8 |
+ $(COMPILE) $<
|
|
|
0b42f8 |
+ $(POSTCOMPILE)
|
|
|
0b42f8 |
|
|
|
0b42f8 |
win32_low_h = $(srcdir)/win32-low.h
|
|
|
0b42f8 |
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/gdbserver/config.in
|
|
|
0b42f8 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/gdbserver/config.in 2018-05-18 10:55:26.840970375 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/gdbserver/config.in 2018-05-18 11:00:34.000000000 +0200
|
|
|
41ba02 |
@@ -146,12 +146,18 @@
|
|
|
0b42f8 |
/* Define to 1 if you have the <selinux/selinux.h> header file. */
|
|
|
0b42f8 |
#undef HAVE_SELINUX_SELINUX_H
|
|
|
0b42f8 |
|
|
|
0b42f8 |
+/* Define to 1 if you have the `setns' function. */
|
|
|
0b42f8 |
+#undef HAVE_SETNS
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
/* Define to 1 if you have the <sgtty.h> header file. */
|
|
|
0b42f8 |
#undef HAVE_SGTTY_H
|
|
|
0b42f8 |
|
|
|
41ba02 |
/* Define to 1 if you have the <signal.h> header file. */
|
|
|
41ba02 |
#undef HAVE_SIGNAL_H
|
|
|
41ba02 |
|
|
|
41ba02 |
+/* Define to 1 if you have the `socketpair' function. */
|
|
|
41ba02 |
+#undef HAVE_SOCKETPAIR
|
|
|
41ba02 |
+
|
|
|
41ba02 |
/* Define to 1 if the system has the type `socklen_t'. */
|
|
|
41ba02 |
#undef HAVE_SOCKLEN_T
|
|
|
41ba02 |
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/gdbserver/configure
|
|
|
0b42f8 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/gdbserver/configure 2018-05-18 10:55:26.841970383 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/gdbserver/configure 2018-05-18 11:00:35.421470381 +0200
|
|
|
0b42f8 |
@@ -4796,7 +4796,7 @@
|
|
|
0b42f8 |
|
|
|
0b42f8 |
done
|
|
|
0b42f8 |
|
|
|
0b42f8 |
-for ac_func in pread pwrite pread64 readlink
|
|
|
41ba02 |
+for ac_func in pread pwrite pread64 readlink socketpair setns
|
|
|
0b42f8 |
do :
|
|
|
0b42f8 |
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
|
|
0b42f8 |
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/gdbserver/configure.ac
|
|
|
0b42f8 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/gdbserver/configure.ac 2018-05-18 10:55:26.828970278 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/gdbserver/configure.ac 2018-05-18 11:00:13.703294429 +0200
|
|
|
0b42f8 |
@@ -70,7 +70,7 @@
|
|
|
0b42f8 |
sys/ioctl.h netinet/in.h sys/socket.h netdb.h dnl
|
|
|
0b42f8 |
netinet/tcp.h arpa/inet.h sys/wait.h wait.h sys/un.h dnl
|
|
|
0b42f8 |
linux/perf_event.h)
|
|
|
0b42f8 |
-AC_CHECK_FUNCS(pread pwrite pread64 readlink)
|
|
|
41ba02 |
+AC_CHECK_FUNCS(pread pwrite pread64 readlink socketpair setns)
|
|
|
0b42f8 |
AC_REPLACE_FUNCS(vasprintf vsnprintf)
|
|
|
0b42f8 |
|
|
|
0b42f8 |
# Check for UST
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/gdbserver/configure.srv
|
|
|
0b42f8 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/gdbserver/configure.srv 2018-05-18 10:55:28.252981814 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/gdbserver/configure.srv 2018-05-18 10:55:28.424983208 +0200
|
|
|
0b42f8 |
@@ -45,7 +45,7 @@
|
|
|
0b42f8 |
aarch64*-*-linux*)
|
|
|
0b42f8 |
srv_regobj="aarch64.o aarch64-without-fpu.o"
|
|
|
0b42f8 |
srv_tgtobj="linux-aarch64-low.o"
|
|
|
0b42f8 |
- srv_tgtobj="${srv_tgtobj} linux-low.o"
|
|
|
0b42f8 |
+ srv_tgtobj="${srv_tgtobj} linux-low.o linux-namespaces.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-osdata.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
@@ -61,7 +61,7 @@
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} arm-with-vfpv2.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} arm-with-vfpv3.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} arm-with-neon.o"
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-arm-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-arm-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_xmlfiles="arm-with-iwmmxt.xml"
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} arm-with-vfpv2.xml"
|
|
|
0b42f8 |
@@ -84,19 +84,19 @@
|
|
|
0b42f8 |
srv_mingwce=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
bfin-*-*linux*) srv_regobj=reg-bfin.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-bfin-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-bfin-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
crisv32-*-linux*) srv_regobj=reg-crisv32.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-crisv32-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-crisv32-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
cris-*-linux*) srv_regobj=reg-cris.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-cris-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-cris-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
@@ -111,7 +111,7 @@
|
|
|
0b42f8 |
srv_regobj="$srv_regobj $srv_amd64_linux_regobj"
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} $srv_amd64_linux_xmlfiles"
|
|
|
0b42f8 |
fi
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-x86-low.o i386-low.o i387-fp.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-x86-low.o i386-low.o i387-fp.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o linux-btrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
@@ -147,12 +147,12 @@
|
|
|
0b42f8 |
srv_qnx="yes"
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
ia64-*-linux*) srv_regobj=reg-ia64.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-ia64-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-ia64-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
m32r*-*-linux*) srv_regobj=reg-m32r.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-m32r-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-m32r-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
@@ -162,7 +162,7 @@
|
|
|
0b42f8 |
else
|
|
|
0b42f8 |
srv_regobj=reg-m68k.o
|
|
|
0b42f8 |
fi
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-m68k-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-m68k-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
@@ -173,7 +173,7 @@
|
|
|
0b42f8 |
else
|
|
|
0b42f8 |
srv_regobj=reg-m68k.o
|
|
|
0b42f8 |
fi
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-m68k-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-m68k-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
@@ -183,7 +183,7 @@
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} mips-dsp-linux.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} mips64-linux.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} mips64-dsp-linux.o"
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-mips-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-mips-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_xmlfiles="mips-linux.xml"
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} mips-dsp-linux.xml"
|
|
|
0b42f8 |
@@ -216,7 +216,7 @@
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} powerpc-isa205-64l.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} powerpc-isa205-altivec64l.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} powerpc-isa205-vsx64l.o"
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-ppc-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-ppc-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_xmlfiles="rs6000/powerpc-32l.xml"
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} rs6000/powerpc-altivec32l.xml"
|
|
|
0b42f8 |
@@ -268,7 +268,7 @@
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} s390x-te-linux64.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} s390x-vx-linux64.o"
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} s390x-tevx-linux64.o"
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-s390-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-s390-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_xmlfiles="s390-linux32.xml"
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} s390-linux32v1.xml"
|
|
|
0b42f8 |
@@ -297,14 +297,14 @@
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
sh*-*-linux*) srv_regobj=reg-sh.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-sh-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-sh-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
sparc*-*-linux*) srv_regobj=reg-sparc64.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-sparc-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-sparc-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
@@ -321,14 +321,14 @@
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} tic6x-core.xml"
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} tic6x-gp.xml"
|
|
|
0b42f8 |
srv_xmlfiles="${srv_xmlfiles} tic6x-c6xp.xml"
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-tic6x-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-tic6x-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
srv_linux_usrregs=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
x86_64-*-linux*) srv_regobj="$srv_amd64_linux_regobj $srv_i386_linux_regobj"
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-x86-low.o i386-low.o i387-fp.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-x86-low.o i386-low.o i387-fp.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o linux-btrace.o"
|
|
|
0b42f8 |
srv_xmlfiles="$srv_i386_linux_xmlfiles $srv_amd64_linux_xmlfiles"
|
|
|
0b42f8 |
srv_linux_usrregs=yes # This is for i386 progs.
|
|
|
0b42f8 |
@@ -348,13 +348,13 @@
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
|
|
|
0b42f8 |
xtensa*-*-linux*) srv_regobj=reg-xtensa.o
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-osdata.o linux-xtensa-low.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-osdata.o linux-xtensa-low.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
;;
|
|
|
0b42f8 |
tilegx-*-linux*) srv_regobj=reg-tilegx.o
|
|
|
0b42f8 |
srv_regobj="${srv_regobj} reg-tilegx32.o"
|
|
|
0b42f8 |
- srv_tgtobj="linux-low.o linux-tile-low.o linux-osdata.o linux-procfs.o"
|
|
|
0b42f8 |
+ srv_tgtobj="linux-low.o linux-namespaces.o linux-tile-low.o linux-osdata.o linux-procfs.o"
|
|
|
0b42f8 |
srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
|
|
|
0b42f8 |
srv_linux_regsets=yes
|
|
|
0b42f8 |
srv_linux_thread_db=yes
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/nat/linux-namespaces.c
|
|
|
0b42f8 |
===================================================================
|
|
|
0b42f8 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/nat/linux-namespaces.c 2018-05-18 10:55:28.424983208 +0200
|
|
|
0b42f8 |
@@ -0,0 +1,1093 @@
|
|
|
0b42f8 |
+/* Linux namespaces(7) support.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ This file is part of GDB.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
0b42f8 |
+ it under the terms of the GNU General Public License as published by
|
|
|
0b42f8 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
0b42f8 |
+ (at your option) any later version.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ This program is distributed in the hope that it will be useful,
|
|
|
0b42f8 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
0b42f8 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
0b42f8 |
+ GNU General Public License for more details.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ You should have received a copy of the GNU General Public License
|
|
|
0b42f8 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#include "server.h"
|
|
|
0b42f8 |
+//#include "common-defs.h"
|
|
|
0b42f8 |
+#include "../nat/linux-namespaces.h"
|
|
|
0b42f8 |
+//#include "filestuff.h"
|
|
|
0b42f8 |
+#include <limits.h>
|
|
|
0b42f8 |
+#define debug_printf(x...) do { } while (0)
|
|
|
0b42f8 |
+#define internal_warning(file, line, x...) warning(x)
|
|
|
0b42f8 |
+#include <unistd.h>
|
|
|
0b42f8 |
+#include <fcntl.h>
|
|
|
0b42f8 |
+#include <sys/syscall.h>
|
|
|
0b42f8 |
+#include <sys/types.h>
|
|
|
0b42f8 |
+#include <sys/stat.h>
|
|
|
0b42f8 |
+#include <sys/socket.h>
|
|
|
0b42f8 |
+#include <sys/wait.h>
|
|
|
0b42f8 |
+#include <signal.h>
|
|
|
0b42f8 |
+#include <sched.h>
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* See nat/linux-namespaces.h. */
|
|
|
0b42f8 |
+int debug_linux_namespaces;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Handle systems without setns. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#ifndef HAVE_SETNS
|
|
|
0b42f8 |
+static int
|
|
|
0b42f8 |
+setns (int fd, int nstype)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+#ifdef __NR_setns
|
|
|
0b42f8 |
+ return syscall (__NR_setns, fd, nstype);
|
|
|
0b42f8 |
+#else
|
|
|
0b42f8 |
+ errno = ENOSYS;
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+#endif
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+#endif
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* A Linux namespace. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+struct linux_ns
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ /* Filename of this namespace's entries in /proc/PID/ns. */
|
|
|
0b42f8 |
+ const char *filename;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Nonzero if this object has been initialized. */
|
|
|
0b42f8 |
+ int initialized;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Nonzero if this namespace is supported on this system. */
|
|
|
0b42f8 |
+ int supported;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* ID of the namespace the calling process is in, used to
|
|
|
0b42f8 |
+ see if other processes share the namespace. The code in
|
|
|
0b42f8 |
+ this file assumes that the calling process never changes
|
|
|
0b42f8 |
+ namespace. */
|
|
|
0b42f8 |
+ ino_t id;
|
|
|
0b42f8 |
+};
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Return the absolute filename of process PID's /proc/PID/ns
|
|
|
0b42f8 |
+ entry for namespace NS. The returned value persists until
|
|
|
0b42f8 |
+ this function is next called. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static const char *
|
|
|
0b42f8 |
+linux_ns_filename (struct linux_ns *ns, int pid)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ static char filename[PATH_MAX];
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (pid > 0);
|
|
|
0b42f8 |
+ xsnprintf (filename, sizeof (filename), "/proc/%d/ns/%s", pid,
|
|
|
0b42f8 |
+ ns->filename);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return filename;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Return a representation of the caller's TYPE namespace, or
|
|
|
0b42f8 |
+ NULL if TYPE namespaces are not supported on this system. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static struct linux_ns *
|
|
|
0b42f8 |
+linux_ns_get_namespace (enum linux_ns_type type)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ static struct linux_ns namespaces[NUM_LINUX_NS_TYPES] =
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ { "ipc" },
|
|
|
0b42f8 |
+ { "mnt" },
|
|
|
0b42f8 |
+ { "net" },
|
|
|
0b42f8 |
+ { "pid" },
|
|
|
0b42f8 |
+ { "user" },
|
|
|
0b42f8 |
+ { "uts" },
|
|
|
0b42f8 |
+ };
|
|
|
0b42f8 |
+ struct linux_ns *ns;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (type >= 0 && type < NUM_LINUX_NS_TYPES);
|
|
|
0b42f8 |
+ ns = &namespaces[type];
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (!ns->initialized)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ struct stat sb;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (stat (linux_ns_filename (ns, getpid ()), &sb) == 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ ns->id = sb.st_ino;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ ns->supported = 1;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ ns->initialized = 1;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return ns->supported ? ns : NULL;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* See nat/linux-namespaces.h. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+int
|
|
|
0b42f8 |
+linux_ns_same (pid_t pid, enum linux_ns_type type)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ struct linux_ns *ns = linux_ns_get_namespace (type);
|
|
|
0b42f8 |
+ const char *filename;
|
|
|
0b42f8 |
+ struct stat sb;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* If the kernel does not support TYPE namespaces then there's
|
|
|
0b42f8 |
+ effectively only one TYPE namespace that all processes on
|
|
|
0b42f8 |
+ the system share. */
|
|
|
0b42f8 |
+ if (ns == NULL)
|
|
|
0b42f8 |
+ return 1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Stat PID's TYPE namespace entry to get the namespace ID. This
|
|
|
0b42f8 |
+ might fail if the process died, or if we don't have the right
|
|
|
0b42f8 |
+ permissions (though we should be attached by this time so this
|
|
|
0b42f8 |
+ seems unlikely). In any event, we can't make any decisions and
|
|
|
0b42f8 |
+ must throw. */
|
|
|
0b42f8 |
+ filename = linux_ns_filename (ns, pid);
|
|
|
0b42f8 |
+ if (stat (filename, &sb) != 0)
|
|
|
0b42f8 |
+ perror_with_name (filename);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return sb.st_ino == ns->id;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* We need to use setns(2) to handle filesystem access in mount
|
|
|
0b42f8 |
+ namespaces other than our own, but this isn't permitted for
|
|
|
0b42f8 |
+ multithreaded processes. GDB is multithreaded when compiled
|
|
|
0b42f8 |
+ with Guile support, and may become multithreaded if compiled
|
|
|
0b42f8 |
+ with Python support. We deal with this by spawning a single-
|
|
|
0b42f8 |
+ threaded helper process to access mount namespaces other than
|
|
|
0b42f8 |
+ our own.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ The helper process is started the first time a call to setns
|
|
|
0b42f8 |
+ is required. The main process (GDB or gdbserver) communicates
|
|
|
0b42f8 |
+ with the helper via sockets, passing file descriptors where
|
|
|
0b42f8 |
+ necessary using SCM_RIGHTS. Once started the helper process
|
|
|
0b42f8 |
+ runs until the main process terminates; when this happens the
|
|
|
0b42f8 |
+ helper will receive socket errors, notice that its parent died,
|
|
|
0b42f8 |
+ and exit accordingly (see mnsh_maybe_mourn_peer).
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ The protocol is that the main process sends a request in a
|
|
|
0b42f8 |
+ single message, and the helper replies to every message it
|
|
|
0b42f8 |
+ receives with a single-message response. If the helper
|
|
|
0b42f8 |
+ receives a message it does not understand it will reply with
|
|
|
0b42f8 |
+ a MNSH_MSG_ERROR message. The main process checks all
|
|
|
0b42f8 |
+ responses it receives with gdb_assert, so if the main process
|
|
|
0b42f8 |
+ receives something unexpected (which includes MNSH_MSG_ERROR)
|
|
|
0b42f8 |
+ the main process will call internal_error.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ For avoidance of doubt, if the helper process receives a
|
|
|
0b42f8 |
+ message it doesn't handle it will reply with MNSH_MSG_ERROR.
|
|
|
0b42f8 |
+ If the main process receives MNSH_MSG_ERROR at any time then
|
|
|
0b42f8 |
+ it will call internal_error. If internal_error causes the
|
|
|
0b42f8 |
+ main process to exit, the helper will notice this and also
|
|
|
0b42f8 |
+ exit. The helper will not exit until the main process
|
|
|
0b42f8 |
+ terminates, so if the user continues through internal_error
|
|
|
0b42f8 |
+ the helper will still be there awaiting requests from the
|
|
|
0b42f8 |
+ main process.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ Messages in both directions have the following payload:
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ - TYPE (enum mnsh_msg_type, always sent) - the message type.
|
|
|
0b42f8 |
+ - INT1 and
|
|
|
0b42f8 |
+ - INT2 (int, always sent, though not always used) - two
|
|
|
0b42f8 |
+ values whose meaning is message-type-dependent.
|
|
|
0b42f8 |
+ See enum mnsh_msg_type documentation below.
|
|
|
0b42f8 |
+ - FD (int, optional, sent using SCM_RIGHTS) - an open file
|
|
|
0b42f8 |
+ descriptor.
|
|
|
0b42f8 |
+ - BUF (unstructured data, optional) - some data with message-
|
|
|
0b42f8 |
+ type-dependent meaning.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ Note that the helper process is the child of a call to fork,
|
|
|
0b42f8 |
+ so all code in the helper must be async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Mount namespace helper message types. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+enum mnsh_msg_type
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* A communication error occurred. Receipt of this message
|
|
|
0b42f8 |
+ by either end will cause an assertion failure in the main
|
|
|
0b42f8 |
+ process. */
|
|
|
0b42f8 |
+ MNSH_MSG_ERROR,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Requests, sent from the main process to the helper. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* A request that the helper call setns. Arguments should
|
|
|
0b42f8 |
+ be passed in FD and INT1. Helper should respond with a
|
|
|
0b42f8 |
+ MNSH_RET_INT. */
|
|
|
0b42f8 |
+ MNSH_REQ_SETNS,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* A request that the helper call open. Arguments should
|
|
|
0b42f8 |
+ be passed in BUF, INT1 and INT2. The filename (in BUF)
|
|
|
0b42f8 |
+ should include a terminating NUL character. The helper
|
|
|
0b42f8 |
+ should respond with a MNSH_RET_FD. */
|
|
|
0b42f8 |
+ MNSH_REQ_OPEN,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* A request that the helper call unlink. The single
|
|
|
0b42f8 |
+ argument (the filename) should be passed in BUF, and
|
|
|
0b42f8 |
+ should include a terminating NUL character. The helper
|
|
|
0b42f8 |
+ should respond with a MNSH_RET_INT. */
|
|
|
0b42f8 |
+ MNSH_REQ_UNLINK,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* A request that the helper call readlink. The single
|
|
|
0b42f8 |
+ argument (the filename) should be passed in BUF, and
|
|
|
0b42f8 |
+ should include a terminating NUL character. The helper
|
|
|
0b42f8 |
+ should respond with a MNSH_RET_INTSTR. */
|
|
|
0b42f8 |
+ MNSH_REQ_READLINK,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Responses, sent to the main process from the helper. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Return an integer in INT1 and errno in INT2. */
|
|
|
0b42f8 |
+ MNSH_RET_INT,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Return a file descriptor in FD if one was opened or an
|
|
|
0b42f8 |
+ integer in INT1 otherwise. Return errno in INT2. */
|
|
|
0b42f8 |
+ MNSH_RET_FD,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Return an integer in INT1, errno in INT2, and optionally
|
|
|
0b42f8 |
+ some data in BUF. */
|
|
|
0b42f8 |
+ MNSH_RET_INTSTR,
|
|
|
0b42f8 |
+ };
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Print a string representation of a message using debug_printf.
|
|
|
0b42f8 |
+ This function is not async-signal-safe so should never be
|
|
|
0b42f8 |
+ called from the helper. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static void
|
|
|
0b42f8 |
+mnsh_debug_print_message (enum mnsh_msg_type type,
|
|
|
0b42f8 |
+ int fd, int int1, int int2,
|
|
|
0b42f8 |
+ const void *buf, int bufsiz)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ gdb_byte *c = (gdb_byte *) buf;
|
|
|
0b42f8 |
+ gdb_byte *cl = c + bufsiz;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ switch (type)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ case MNSH_MSG_ERROR:
|
|
|
0b42f8 |
+ debug_printf ("ERROR");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_REQ_SETNS:
|
|
|
0b42f8 |
+ debug_printf ("SETNS");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_REQ_OPEN:
|
|
|
0b42f8 |
+ debug_printf ("OPEN");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_REQ_UNLINK:
|
|
|
0b42f8 |
+ debug_printf ("UNLINK");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_REQ_READLINK:
|
|
|
0b42f8 |
+ debug_printf ("READLINK");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_RET_INT:
|
|
|
0b42f8 |
+ debug_printf ("INT");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_RET_FD:
|
|
|
0b42f8 |
+ debug_printf ("FD");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_RET_INTSTR:
|
|
|
0b42f8 |
+ debug_printf ("INTSTR");
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ default:
|
|
|
0b42f8 |
+ debug_printf ("unknown-packet-%d", type);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ debug_printf (" %d %d %d \"", fd, int1, int2);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ for (; c < cl; c++)
|
|
|
0b42f8 |
+ debug_printf (*c >= ' ' && *c <= '~' ? "%c" : "\\%o", *c);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ debug_printf ("\"");
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Forward declaration. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static void mnsh_maybe_mourn_peer (void);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Send a message. The argument SOCK is the file descriptor of the
|
|
|
0b42f8 |
+ sending socket, the other arguments are the payload to send.
|
|
|
0b42f8 |
+ Return the number of bytes sent on success. Return -1 on failure
|
|
|
0b42f8 |
+ and set errno appropriately. This function is called by both the
|
|
|
0b42f8 |
+ main process and the helper so must be async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static ssize_t
|
|
|
0b42f8 |
+mnsh_send_message (int sock, enum mnsh_msg_type type,
|
|
|
0b42f8 |
+ int fd, int int1, int int2,
|
|
|
0b42f8 |
+ const void *buf, int bufsiz)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ struct msghdr msg;
|
|
|
0b42f8 |
+ struct iovec iov[4];
|
|
|
0b42f8 |
+ char fdbuf[CMSG_SPACE (sizeof (fd))];
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Build the basic TYPE, INT1, INT2 message. */
|
|
|
0b42f8 |
+ memset (&msg, 0, sizeof (msg));
|
|
|
0b42f8 |
+ msg.msg_iov = iov;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ iov[0].iov_base = &type;
|
|
|
0b42f8 |
+ iov[0].iov_len = sizeof (type);
|
|
|
0b42f8 |
+ iov[1].iov_base = &int1;
|
|
|
0b42f8 |
+ iov[1].iov_len = sizeof (int1);
|
|
|
0b42f8 |
+ iov[2].iov_base = &int2;
|
|
|
0b42f8 |
+ iov[2].iov_len = sizeof (int2);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ msg.msg_iovlen = 3;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Append BUF if supplied. */
|
|
|
0b42f8 |
+ if (buf != NULL && bufsiz > 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ iov[3].iov_base = alloca (bufsiz);
|
|
|
0b42f8 |
+ memcpy (iov[3].iov_base, buf, bufsiz);
|
|
|
0b42f8 |
+ iov[3].iov_len = bufsiz;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ msg.msg_iovlen ++;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Attach FD if supplied. */
|
|
|
0b42f8 |
+ if (fd >= 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ struct cmsghdr *cmsg;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ msg.msg_control = fdbuf;
|
|
|
0b42f8 |
+ msg.msg_controllen = sizeof (fdbuf);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ cmsg = CMSG_FIRSTHDR (&msg;;
|
|
|
0b42f8 |
+ cmsg->cmsg_level = SOL_SOCKET;
|
|
|
0b42f8 |
+ cmsg->cmsg_type = SCM_RIGHTS;
|
|
|
0b42f8 |
+ cmsg->cmsg_len = CMSG_LEN (sizeof (int));
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ memcpy (CMSG_DATA (cmsg), &fd, sizeof (int));
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ msg.msg_controllen = cmsg->cmsg_len;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Send the message. */
|
|
|
0b42f8 |
+ size = sendmsg (sock, &msg, 0);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ mnsh_maybe_mourn_peer ();
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (debug_linux_namespaces)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ debug_printf ("mnsh: send: ");
|
|
|
0b42f8 |
+ mnsh_debug_print_message (type, fd, int1, int2, buf, bufsiz);
|
|
|
0b42f8 |
+ debug_printf (" -> %ld\n", size);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return size;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Receive a message. The argument SOCK is the file descriptor of
|
|
|
0b42f8 |
+ the receiving socket, the other arguments point to storage for
|
|
|
0b42f8 |
+ the received payload. Returns the number of bytes stored into
|
|
|
0b42f8 |
+ BUF on success, which may be zero in the event no BUF was sent.
|
|
|
0b42f8 |
+ Return -1 on failure and set errno appropriately. This function
|
|
|
0b42f8 |
+ is called from both the main process and the helper and must be
|
|
|
0b42f8 |
+ async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static ssize_t
|
|
|
0b42f8 |
+mnsh_recv_message (int sock, enum mnsh_msg_type *type,
|
|
|
0b42f8 |
+ int *fd, int *int1, int *int2,
|
|
|
0b42f8 |
+ void *buf, int bufsiz)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ struct msghdr msg;
|
|
|
0b42f8 |
+ struct iovec iov[4];
|
|
|
0b42f8 |
+ char fdbuf[CMSG_SPACE (sizeof (*fd))];
|
|
|
0b42f8 |
+ struct cmsghdr *cmsg;
|
|
|
0b42f8 |
+ ssize_t size, fixed_size;
|
|
|
0b42f8 |
+ int i;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Build the message to receive data into. */
|
|
|
0b42f8 |
+ memset (&msg, 0, sizeof (msg));
|
|
|
0b42f8 |
+ msg.msg_iov = iov;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ iov[0].iov_base = type;
|
|
|
0b42f8 |
+ iov[0].iov_len = sizeof (*type);
|
|
|
0b42f8 |
+ iov[1].iov_base = int1;
|
|
|
0b42f8 |
+ iov[1].iov_len = sizeof (*int1);
|
|
|
0b42f8 |
+ iov[2].iov_base = int2;
|
|
|
0b42f8 |
+ iov[2].iov_len = sizeof (*int2);
|
|
|
0b42f8 |
+ iov[3].iov_base = buf;
|
|
|
0b42f8 |
+ iov[3].iov_len = bufsiz;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ msg.msg_iovlen = 4;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ for (fixed_size = i = 0; i < msg.msg_iovlen - 1; i++)
|
|
|
0b42f8 |
+ fixed_size += iov[i].iov_len;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ msg.msg_control = fdbuf;
|
|
|
0b42f8 |
+ msg.msg_controllen = sizeof (fdbuf);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Receive the message. */
|
|
|
0b42f8 |
+ size = recvmsg (sock, &msg, MSG_CMSG_CLOEXEC);
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ if (debug_linux_namespaces)
|
|
|
0b42f8 |
+ debug_printf ("namespace-helper: recv failed (%ld)\n", size);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ mnsh_maybe_mourn_peer ();
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return size;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Check for truncation. */
|
|
|
0b42f8 |
+ if (size < fixed_size || (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC)))
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ if (debug_linux_namespaces)
|
|
|
0b42f8 |
+ debug_printf ("namespace-helper: recv truncated (%ld 0x%x)\n",
|
|
|
0b42f8 |
+ size, msg.msg_flags);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ mnsh_maybe_mourn_peer ();
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ errno = EBADMSG;
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Unpack the file descriptor if supplied. */
|
|
|
0b42f8 |
+ cmsg = CMSG_FIRSTHDR (&msg;;
|
|
|
0b42f8 |
+ if (cmsg != NULL
|
|
|
0b42f8 |
+ && cmsg->cmsg_len == CMSG_LEN (sizeof (int))
|
|
|
0b42f8 |
+ && cmsg->cmsg_level == SOL_SOCKET
|
|
|
0b42f8 |
+ && cmsg->cmsg_type == SCM_RIGHTS)
|
|
|
0b42f8 |
+ memcpy (fd, CMSG_DATA (cmsg), sizeof (int));
|
|
|
0b42f8 |
+ else
|
|
|
0b42f8 |
+ *fd = -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (debug_linux_namespaces)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ debug_printf ("mnsh: recv: ");
|
|
|
0b42f8 |
+ mnsh_debug_print_message (*type, *fd, *int1, *int2, buf,
|
|
|
0b42f8 |
+ size - fixed_size);
|
|
|
0b42f8 |
+ debug_printf ("\n");
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Return the number of bytes of data in BUF. */
|
|
|
0b42f8 |
+ return size - fixed_size;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Shortcuts for returning results from the helper. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#define mnsh_return_int(sock, result, error) \
|
|
|
0b42f8 |
+ mnsh_send_message (sock, MNSH_RET_INT, -1, result, error, NULL, 0)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#define mnsh_return_fd(sock, fd, error) \
|
|
|
0b42f8 |
+ mnsh_send_message (sock, MNSH_RET_FD, \
|
|
|
0b42f8 |
+ (fd) < 0 ? -1 : (fd), \
|
|
|
0b42f8 |
+ (fd) < 0 ? (fd) : 0, \
|
|
|
0b42f8 |
+ error, NULL, 0)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#define mnsh_return_intstr(sock, result, buf, bufsiz, error) \
|
|
|
0b42f8 |
+ mnsh_send_message (sock, MNSH_RET_INTSTR, -1, result, error, \
|
|
|
0b42f8 |
+ buf, bufsiz)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Handle a MNSH_REQ_SETNS message. Must be async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static ssize_t
|
|
|
0b42f8 |
+mnsh_handle_setns (int sock, int fd, int nstype)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ int result = setns (fd, nstype);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return mnsh_return_int (sock, result, errno);
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* See filestuff.h. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+int
|
|
|
0b42f8 |
+gdb_open_cloexec (const char *filename, int flags, unsigned long mode)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ int fd = open (filename, flags | O_CLOEXEC, mode);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+// if (fd >= 0)
|
|
|
0b42f8 |
+// maybe_mark_cloexec (fd);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return fd;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Handle a MNSH_REQ_OPEN message. Must be async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static ssize_t
|
|
|
0b42f8 |
+mnsh_handle_open (int sock, const char *filename,
|
|
|
0b42f8 |
+ int flags, mode_t mode)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ int fd = gdb_open_cloexec (filename, flags, mode);
|
|
|
0b42f8 |
+ ssize_t result = mnsh_return_fd (sock, fd, errno);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (fd >= 0)
|
|
|
0b42f8 |
+ close (fd);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return result;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Handle a MNSH_REQ_UNLINK message. Must be async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static ssize_t
|
|
|
0b42f8 |
+mnsh_handle_unlink (int sock, const char *filename)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ int result = unlink (filename);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return mnsh_return_int (sock, result, errno);
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Handle a MNSH_REQ_READLINK message. Must be async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static ssize_t
|
|
|
0b42f8 |
+mnsh_handle_readlink (int sock, const char *filename)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ char buf[PATH_MAX];
|
|
|
0b42f8 |
+ int len = readlink (filename, buf, sizeof (buf));
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return mnsh_return_intstr (sock, len,
|
|
|
0b42f8 |
+ buf, len < 0 ? 0 : len,
|
|
|
0b42f8 |
+ errno);
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* The helper process. Never returns. Must be async-signal-safe. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static void mnsh_main (int sock) ATTRIBUTE_NORETURN;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static void
|
|
|
0b42f8 |
+mnsh_main (int sock)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ while (1)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ enum mnsh_msg_type type;
|
|
|
0b42f8 |
+ int fd, int1, int2;
|
|
|
0b42f8 |
+ char buf[PATH_MAX];
|
|
|
0b42f8 |
+ ssize_t size, response = -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_recv_message (sock, &type,
|
|
|
0b42f8 |
+ &fd, &int1, &int2,
|
|
|
0b42f8 |
+ buf, sizeof (buf));
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (size >= 0 && size < sizeof (buf))
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ switch (type)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ case MNSH_REQ_SETNS:
|
|
|
0b42f8 |
+ if (fd > 0)
|
|
|
0b42f8 |
+ response = mnsh_handle_setns (sock, fd, int1);
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_REQ_OPEN:
|
|
|
0b42f8 |
+ if (size > 0 && buf[size - 1] == '\0')
|
|
|
0b42f8 |
+ response = mnsh_handle_open (sock, buf, int1, int2);
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_REQ_UNLINK:
|
|
|
0b42f8 |
+ if (size > 0 && buf[size - 1] == '\0')
|
|
|
0b42f8 |
+ response = mnsh_handle_unlink (sock, buf);
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ case MNSH_REQ_READLINK:
|
|
|
0b42f8 |
+ if (size > 0 && buf[size - 1] == '\0')
|
|
|
0b42f8 |
+ response = mnsh_handle_readlink (sock, buf);
|
|
|
0b42f8 |
+ break;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ default:
|
|
|
0b42f8 |
+ break; /* Handled below. */
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Close any file descriptors we were passed. */
|
|
|
0b42f8 |
+ if (fd >= 0)
|
|
|
0b42f8 |
+ close (fd);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Can't handle this message, bounce it back. */
|
|
|
0b42f8 |
+ if (response < 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ size = 0;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ mnsh_send_message (sock, MNSH_MSG_ERROR,
|
|
|
0b42f8 |
+ -1, int1, int2, buf, size);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* The mount namespace helper process. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+struct linux_mnsh
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ /* PID of helper. */
|
|
|
0b42f8 |
+ pid_t pid;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Socket for communication. */
|
|
|
0b42f8 |
+ int sock;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* ID of the mount namespace the helper is currently in. */
|
|
|
0b42f8 |
+ ino_t nsid;
|
|
|
0b42f8 |
+};
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* In the helper process this is set to the PID of the process that
|
|
|
0b42f8 |
+ created the helper (i.e. GDB or gdbserver). In the main process
|
|
|
0b42f8 |
+ this is set to zero. Used by mnsh_maybe_mourn_peer. */
|
|
|
0b42f8 |
+static int mnsh_creator_pid = 0;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* See filestuff.h. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+int
|
|
|
0b42f8 |
+gdb_socketpair_cloexec (int domain, int style, int protocol,
|
|
|
0b42f8 |
+ int filedes[2])
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+#ifdef HAVE_SOCKETPAIR
|
|
|
0b42f8 |
+ int result = socketpair (domain, style | SOCK_CLOEXEC, protocol, filedes);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (result != -1)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+// socket_mark_cloexec (filedes[0]);
|
|
|
0b42f8 |
+// socket_mark_cloexec (filedes[1]);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return result;
|
|
|
0b42f8 |
+#else
|
|
|
0b42f8 |
+ gdb_assert_not_reached (_("socketpair not available on this host"));
|
|
|
0b42f8 |
+#endif
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Return an object representing the mount namespace helper process.
|
|
|
0b42f8 |
+ If no mount namespace helper process has been started then start
|
|
|
0b42f8 |
+ one. Return NULL if no mount namespace helper process could be
|
|
|
0b42f8 |
+ started. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static struct linux_mnsh *
|
|
|
0b42f8 |
+linux_mntns_get_helper (void)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ static struct linux_mnsh *helper = NULL;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (helper == NULL)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ static struct linux_mnsh h;
|
|
|
0b42f8 |
+ struct linux_ns *ns;
|
|
|
0b42f8 |
+ pid_t helper_creator = getpid ();
|
|
|
0b42f8 |
+ int sv[2];
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ ns = linux_ns_get_namespace (LINUX_NS_MNT);
|
|
|
0b42f8 |
+ if (ns == NULL)
|
|
|
0b42f8 |
+ return NULL;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (gdb_socketpair_cloexec (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
|
|
|
0b42f8 |
+ return NULL;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ h.pid = fork ();
|
|
|
0b42f8 |
+ if (h.pid < 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ int saved_errno = errno;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ close (sv[0]);
|
|
|
0b42f8 |
+ close (sv[1]);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ errno = saved_errno;
|
|
|
0b42f8 |
+ return NULL;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (h.pid == 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* Child process. */
|
|
|
0b42f8 |
+ close (sv[0]);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ mnsh_creator_pid = helper_creator;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Debug printing isn't async-signal-safe. */
|
|
|
0b42f8 |
+ debug_linux_namespaces = 0;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ mnsh_main (sv[1]);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Parent process. */
|
|
|
0b42f8 |
+ close (sv[1]);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ helper = &h;
|
|
|
0b42f8 |
+ helper->sock = sv[0];
|
|
|
0b42f8 |
+ helper->nsid = ns->id;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (debug_linux_namespaces)
|
|
|
0b42f8 |
+ debug_printf ("Started mount namespace helper process %d\n",
|
|
|
0b42f8 |
+ helper->pid);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return helper;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Check whether the other process died and act accordingly. Called
|
|
|
0b42f8 |
+ whenever a socket error occurs, from both the main process and the
|
|
|
0b42f8 |
+ helper. Must be async-signal-safe when called from the helper. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static void
|
|
|
0b42f8 |
+mnsh_maybe_mourn_peer (void)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ if (mnsh_creator_pid != 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* We're in the helper. Check if our current parent is the
|
|
|
0b42f8 |
+ process that started us. If it isn't, then our original
|
|
|
0b42f8 |
+ parent died and we've been reparented. Exit immediately
|
|
|
0b42f8 |
+ if that's the case. */
|
|
|
0b42f8 |
+ if (getppid () != mnsh_creator_pid)
|
|
|
0b42f8 |
+ _exit (0);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+ else
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* We're in the main process. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ struct linux_mnsh *helper = linux_mntns_get_helper ();
|
|
|
0b42f8 |
+ int status;
|
|
|
0b42f8 |
+ pid_t pid;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (helper->pid < 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* We already mourned it. */
|
|
|
0b42f8 |
+ return;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ pid = waitpid (helper->pid, &status, WNOHANG);
|
|
|
0b42f8 |
+ if (pid == 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* The helper is still alive. */
|
|
|
0b42f8 |
+ return;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+ else if (pid == -1)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ if (errno == ECHILD)
|
|
|
0b42f8 |
+ warning (_("mount namespace helper vanished?"));
|
|
|
0b42f8 |
+ else
|
|
|
0b42f8 |
+ internal_warning (__FILE__, __LINE__,
|
|
|
0b42f8 |
+ _("unhandled error %d"), errno);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+ else if (pid == helper->pid)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ if (WIFEXITED (status))
|
|
|
0b42f8 |
+ warning (_("mount namespace helper exited with status %d"),
|
|
|
0b42f8 |
+ WEXITSTATUS (status));
|
|
|
0b42f8 |
+ else if (WIFSIGNALED (status))
|
|
|
0b42f8 |
+ warning (_("mount namespace helper killed by signal %d"),
|
|
|
0b42f8 |
+ WTERMSIG (status));
|
|
|
0b42f8 |
+ else
|
|
|
0b42f8 |
+ internal_warning (__FILE__, __LINE__,
|
|
|
0b42f8 |
+ _("unhandled status %d"), status);
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+ else
|
|
|
0b42f8 |
+ internal_warning (__FILE__, __LINE__,
|
|
|
0b42f8 |
+ _("unknown pid %d"), pid);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Something unrecoverable happened. */
|
|
|
0b42f8 |
+ helper->pid = -1;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Shortcuts for sending messages to the helper. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#define mnsh_send_setns(helper, fd, nstype) \
|
|
|
0b42f8 |
+ mnsh_send_message (helper->sock, MNSH_REQ_SETNS, fd, nstype, 0, \
|
|
|
0b42f8 |
+ NULL, 0)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#define mnsh_send_open(helper, filename, flags, mode) \
|
|
|
0b42f8 |
+ mnsh_send_message (helper->sock, MNSH_REQ_OPEN, -1, flags, mode, \
|
|
|
0b42f8 |
+ filename, strlen (filename) + 1)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#define mnsh_send_unlink(helper, filename) \
|
|
|
0b42f8 |
+ mnsh_send_message (helper->sock, MNSH_REQ_UNLINK, -1, 0, 0, \
|
|
|
0b42f8 |
+ filename, strlen (filename) + 1)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#define mnsh_send_readlink(helper, filename) \
|
|
|
0b42f8 |
+ mnsh_send_message (helper->sock, MNSH_REQ_READLINK, -1, 0, 0, \
|
|
|
0b42f8 |
+ filename, strlen (filename) + 1)
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Receive a message from the helper. Issue an assertion failure if
|
|
|
0b42f8 |
+ the message isn't a correctly-formatted MNSH_RET_INT. Set RESULT
|
|
|
0b42f8 |
+ and ERROR and return 0 on success. Set errno and return -1 on
|
|
|
0b42f8 |
+ failure. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static int
|
|
|
0b42f8 |
+mnsh_recv_int (struct linux_mnsh *helper, int *result, int *error)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ enum mnsh_msg_type type;
|
|
|
0b42f8 |
+ char buf[PATH_MAX];
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+ int fd;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_recv_message (helper->sock, &type, &fd,
|
|
|
0b42f8 |
+ result, error,
|
|
|
0b42f8 |
+ buf, sizeof (buf));
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (type == MNSH_RET_INT);
|
|
|
0b42f8 |
+ gdb_assert (fd == -1);
|
|
|
0b42f8 |
+ gdb_assert (size == 0);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return 0;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Receive a message from the helper. Issue an assertion failure if
|
|
|
0b42f8 |
+ the message isn't a correctly-formatted MNSH_RET_FD. Set FD and
|
|
|
0b42f8 |
+ ERROR and return 0 on success. Set errno and return -1 on
|
|
|
0b42f8 |
+ failure. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static int
|
|
|
0b42f8 |
+mnsh_recv_fd (struct linux_mnsh *helper, int *fd, int *error)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ enum mnsh_msg_type type;
|
|
|
0b42f8 |
+ char buf[PATH_MAX];
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+ int result;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_recv_message (helper->sock, &type, fd,
|
|
|
0b42f8 |
+ &result, error,
|
|
|
0b42f8 |
+ buf, sizeof (buf));
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (type == MNSH_RET_FD);
|
|
|
0b42f8 |
+ gdb_assert (size == 0);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (*fd < 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ gdb_assert (result < 0);
|
|
|
0b42f8 |
+ *fd = result;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return 0;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Receive a message from the helper. Issue an assertion failure if
|
|
|
0b42f8 |
+ the message isn't a correctly-formatted MNSH_RET_INTSTR. Set
|
|
|
0b42f8 |
+ RESULT and ERROR and optionally store data in BUF, then return
|
|
|
0b42f8 |
+ the number of bytes stored in BUF on success (this may be zero).
|
|
|
0b42f8 |
+ Set errno and return -1 on error. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static ssize_t
|
|
|
0b42f8 |
+mnsh_recv_intstr (struct linux_mnsh *helper,
|
|
|
0b42f8 |
+ int *result, int *error,
|
|
|
0b42f8 |
+ void *buf, int bufsiz)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ enum mnsh_msg_type type;
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+ int fd;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_recv_message (helper->sock, &type, &fd,
|
|
|
0b42f8 |
+ result, error,
|
|
|
0b42f8 |
+ buf, bufsiz);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (type == MNSH_RET_INTSTR);
|
|
|
0b42f8 |
+ gdb_assert (fd == -1);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return size;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Return values for linux_mntns_access_fs. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+enum mnsh_fs_code
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* Something went wrong, errno is set. */
|
|
|
0b42f8 |
+ MNSH_FS_ERROR = -1,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* The main process is in the correct mount namespace.
|
|
|
0b42f8 |
+ The caller should access the filesystem directly. */
|
|
|
0b42f8 |
+ MNSH_FS_DIRECT,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* The helper is in the correct mount namespace.
|
|
|
0b42f8 |
+ The caller should access the filesystem via the helper. */
|
|
|
0b42f8 |
+ MNSH_FS_HELPER
|
|
|
0b42f8 |
+ };
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Return a value indicating how the caller should access the
|
|
|
0b42f8 |
+ mount namespace of process PID. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+static enum mnsh_fs_code
|
|
|
0b42f8 |
+linux_mntns_access_fs (pid_t pid)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+// struct cleanup *old_chain;
|
|
|
0b42f8 |
+ struct linux_ns *ns;
|
|
|
0b42f8 |
+ struct stat sb;
|
|
|
0b42f8 |
+ struct linux_mnsh *helper;
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+ int fd, saved_errno;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (pid == getpid ())
|
|
|
0b42f8 |
+ return MNSH_FS_DIRECT;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ ns = linux_ns_get_namespace (LINUX_NS_MNT);
|
|
|
0b42f8 |
+ if (ns == NULL)
|
|
|
0b42f8 |
+ return MNSH_FS_DIRECT;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+// old_chain = make_cleanup (null_cleanup, NULL);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ fd = gdb_open_cloexec (linux_ns_filename (ns, pid), O_RDONLY, 0);
|
|
|
0b42f8 |
+ if (fd < 0)
|
|
|
0b42f8 |
+ goto error_nofd;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+// old_chain = make_cleanup_close (fd);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (fstat (fd, &sb) != 0)
|
|
|
0b42f8 |
+ goto error;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (sb.st_ino == ns->id)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+// do_cleanups (old_chain);
|
|
|
0b42f8 |
+close (fd);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return MNSH_FS_DIRECT;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ helper = linux_mntns_get_helper ();
|
|
|
0b42f8 |
+ if (helper == NULL)
|
|
|
0b42f8 |
+ goto error;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (sb.st_ino != helper->nsid)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ int result, error;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_send_setns (helper, fd, 0);
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ goto error;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (mnsh_recv_int (helper, &result, &error) != 0)
|
|
|
0b42f8 |
+ goto error;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (result != 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* ENOSYS indicates that an entire function is unsupported
|
|
|
0b42f8 |
+ (it's not appropriate for our versions of open/unlink/
|
|
|
0b42f8 |
+ readlink to sometimes return with ENOSYS depending on how
|
|
|
0b42f8 |
+ they're called) so we convert ENOSYS to ENOTSUP if setns
|
|
|
0b42f8 |
+ fails. */
|
|
|
0b42f8 |
+ if (error == ENOSYS)
|
|
|
0b42f8 |
+ error = ENOTSUP;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ errno = error;
|
|
|
0b42f8 |
+ goto error;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ helper->nsid = sb.st_ino;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+// do_cleanups (old_chain);
|
|
|
0b42f8 |
+close (fd);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return MNSH_FS_HELPER;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+error:
|
|
|
0b42f8 |
+ saved_errno = errno;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+// do_cleanups (old_chain);
|
|
|
0b42f8 |
+close (fd);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ errno = saved_errno;
|
|
|
0b42f8 |
+error_nofd:
|
|
|
0b42f8 |
+ return MNSH_FS_ERROR;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* See nat/linux-namespaces.h. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+int
|
|
|
0b42f8 |
+linux_mntns_open_cloexec (pid_t pid, const char *filename,
|
|
|
0b42f8 |
+ int flags, mode_t mode)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ enum mnsh_fs_code access = linux_mntns_access_fs (pid);
|
|
|
0b42f8 |
+ struct linux_mnsh *helper;
|
|
|
0b42f8 |
+ int fd, error;
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (access == MNSH_FS_ERROR)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (access == MNSH_FS_DIRECT)
|
|
|
0b42f8 |
+ return gdb_open_cloexec (filename, flags, mode);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (access == MNSH_FS_HELPER);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ helper = linux_mntns_get_helper ();
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_send_open (helper, filename, flags, mode);
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (mnsh_recv_fd (helper, &fd, &error) != 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (fd < 0)
|
|
|
0b42f8 |
+ errno = error;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return fd;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* See nat/linux-namespaces.h. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+int
|
|
|
0b42f8 |
+linux_mntns_unlink (pid_t pid, const char *filename)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ enum mnsh_fs_code access = linux_mntns_access_fs (pid);
|
|
|
0b42f8 |
+ struct linux_mnsh *helper;
|
|
|
0b42f8 |
+ int ret, error;
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (access == MNSH_FS_ERROR)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (access == MNSH_FS_DIRECT)
|
|
|
0b42f8 |
+ return unlink (filename);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (access == MNSH_FS_HELPER);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ helper = linux_mntns_get_helper ();
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_send_unlink (helper, filename);
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (mnsh_recv_int (helper, &ret, &error) != 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (ret != 0)
|
|
|
0b42f8 |
+ errno = error;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return ret;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* See nat/linux-namespaces.h. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ssize_t
|
|
|
0b42f8 |
+linux_mntns_readlink (pid_t pid, const char *filename,
|
|
|
0b42f8 |
+ char *buf, size_t bufsiz)
|
|
|
0b42f8 |
+{
|
|
|
0b42f8 |
+ enum mnsh_fs_code access = linux_mntns_access_fs (pid);
|
|
|
0b42f8 |
+ struct linux_mnsh *helper;
|
|
|
0b42f8 |
+ int ret, error;
|
|
|
0b42f8 |
+ ssize_t size;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (access == MNSH_FS_ERROR)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (access == MNSH_FS_DIRECT)
|
|
|
0b42f8 |
+ return readlink (filename, buf, bufsiz);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ gdb_assert (access == MNSH_FS_HELPER);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ helper = linux_mntns_get_helper ();
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_send_readlink (helper, filename);
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ return -1;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ size = mnsh_recv_intstr (helper, &ret, &error, buf, bufsiz);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ if (size < 0)
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ ret = -1;
|
|
|
0b42f8 |
+ errno = error;
|
|
|
0b42f8 |
+ }
|
|
|
0b42f8 |
+ else
|
|
|
0b42f8 |
+ gdb_assert (size == ret);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ return ret;
|
|
|
0b42f8 |
+}
|
|
|
0b42f8 |
Index: gdb-7.6.1/gdb/nat/linux-namespaces.h
|
|
|
0b42f8 |
===================================================================
|
|
|
0b42f8 |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/nat/linux-namespaces.h 2018-05-18 10:55:28.424983208 +0200
|
|
|
0b42f8 |
@@ -0,0 +1,78 @@
|
|
|
0b42f8 |
+/* Linux namespaces(7) support.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ This file is part of GDB.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
0b42f8 |
+ it under the terms of the GNU General Public License as published by
|
|
|
0b42f8 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
0b42f8 |
+ (at your option) any later version.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ This program is distributed in the hope that it will be useful,
|
|
|
0b42f8 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
0b42f8 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
0b42f8 |
+ GNU General Public License for more details.
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ You should have received a copy of the GNU General Public License
|
|
|
0b42f8 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#ifndef LINUX_NAMESPACES_H
|
|
|
0b42f8 |
+#define LINUX_NAMESPACES_H
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#include <sys/types.h>
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Set to nonzero to enable debugging of Linux namespaces code. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+extern int debug_linux_namespaces;
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Enumeration of Linux namespace types. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+enum linux_ns_type
|
|
|
0b42f8 |
+ {
|
|
|
0b42f8 |
+ /* IPC namespace: System V IPC, POSIX message queues. */
|
|
|
0b42f8 |
+ LINUX_NS_IPC,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Mount namespace: mount points. */
|
|
|
0b42f8 |
+ LINUX_NS_MNT,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Network namespace: network devices, stacks, ports, etc. */
|
|
|
0b42f8 |
+ LINUX_NS_NET,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* PID namespace: process IDs. */
|
|
|
0b42f8 |
+ LINUX_NS_PID,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* User namespace: user and group IDs. */
|
|
|
0b42f8 |
+ LINUX_NS_USER,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* UTS namespace: hostname and NIS domain name. */
|
|
|
0b42f8 |
+ LINUX_NS_UTS,
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+ /* Number of Linux namespaces. */
|
|
|
0b42f8 |
+ NUM_LINUX_NS_TYPES
|
|
|
0b42f8 |
+ };
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Return nonzero if process PID has the same TYPE namespace as the
|
|
|
0b42f8 |
+ calling process, or if the kernel does not support TYPE namespaces
|
|
|
0b42f8 |
+ (in which case there is only one TYPE namespace). Return zero if
|
|
|
0b42f8 |
+ the kernel supports TYPE namespaces and the two processes have
|
|
|
0b42f8 |
+ different TYPE namespaces. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+extern int linux_ns_same (pid_t pid, enum linux_ns_type type);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Like gdb_open_cloexec, but in the mount namespace of process
|
|
|
0b42f8 |
+ PID. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+extern int linux_mntns_open_cloexec (pid_t pid, const char *filename,
|
|
|
0b42f8 |
+ int flags, mode_t mode);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Like unlink(2), but in the mount namespace of process PID. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+extern int linux_mntns_unlink (pid_t pid, const char *filename);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+/* Like readlink(2), but in the mount namespace of process PID. */
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+extern ssize_t linux_mntns_readlink (pid_t pid, const char *filename,
|
|
|
0b42f8 |
+ char *buf, size_t bufsiz);
|
|
|
0b42f8 |
+
|
|
|
0b42f8 |
+#endif /* LINUX_NAMESPACES_H */
|
|
|
41ba02 |
Index: gdb-7.6.1/gdb/config.in
|
|
|
41ba02 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/config.in 2018-05-18 10:55:26.838970359 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/config.in 2018-05-18 11:00:28.000000000 +0200
|
|
|
41ba02 |
@@ -369,6 +369,9 @@
|
|
|
41ba02 |
/* Define to 1 if you have the `setlocale' function. */
|
|
|
41ba02 |
#undef HAVE_SETLOCALE
|
|
|
41ba02 |
|
|
|
41ba02 |
+/* Define to 1 if you have the `setns' function. */
|
|
|
41ba02 |
+#undef HAVE_SETNS
|
|
|
41ba02 |
+
|
|
|
41ba02 |
/* Define to 1 if you have the `setpgid' function. */
|
|
|
41ba02 |
#undef HAVE_SETPGID
|
|
|
41ba02 |
|
|
|
41ba02 |
Index: gdb-7.6.1/gdb/configure
|
|
|
41ba02 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/configure 2018-05-18 10:55:26.840970375 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/configure 2018-05-18 11:00:30.074427061 +0200
|
|
|
41ba02 |
@@ -10667,7 +10667,7 @@
|
|
|
41ba02 |
sbrk setpgid setpgrp setsid \
|
|
|
41ba02 |
sigaction sigprocmask sigsetmask socketpair syscall \
|
|
|
41ba02 |
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
|
|
|
41ba02 |
- setrlimit getrlimit posix_madvise waitpid lstat
|
|
|
41ba02 |
+ setrlimit getrlimit posix_madvise waitpid lstat setns
|
|
|
41ba02 |
do :
|
|
|
41ba02 |
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
|
|
41ba02 |
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
|
|
41ba02 |
Index: gdb-7.6.1/gdb/configure.ac
|
|
|
41ba02 |
===================================================================
|
|
|
41ba02 |
--- gdb-7.6.1.orig/gdb/configure.ac 2018-05-18 10:55:26.828970278 +0200
|
|
|
41ba02 |
+++ gdb-7.6.1/gdb/configure.ac 2018-05-18 11:00:02.912207003 +0200
|
|
|
41ba02 |
@@ -1365,7 +1365,7 @@
|
|
|
41ba02 |
sbrk setpgid setpgrp setsid \
|
|
|
41ba02 |
sigaction sigprocmask sigsetmask socketpair syscall \
|
|
|
41ba02 |
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
|
|
|
41ba02 |
- setrlimit getrlimit posix_madvise waitpid lstat])
|
|
|
41ba02 |
+ setrlimit getrlimit posix_madvise waitpid lstat setns])
|
|
|
41ba02 |
AM_LANGINFO_CODESET
|
|
|
41ba02 |
|
|
|
41ba02 |
# Check the return and argument types of ptrace. No canned test for
|