This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] [PR server/18976] fallback to open if multifs_open fails

gdbserver on linux currently tries to open files from within the
target's mount namespace via setns in a helper process, but this only
works for users with CAP_SYS_CHROOT and CAP_SYS_ADMIN, which regular
users generally don't have (particularly on android).

This patch retries with a regular open if multifs_open reports failure.


2015-09-16  Josh Gao  <>
        PR server/18976
        * hostio.c(handle_open): fallback to open if multifs_open fails.
diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index a631d9e..d69a141 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -297,7 +297,7 @@ handle_open (char *own_buf)
   char filename[HOSTIO_PATH_MAX];
   char *p;
-  int fileio_flags, fileio_mode, flags, fd;
+  int fileio_flags, fileio_mode, flags, fd = -1;
   mode_t mode;
   struct fd_list *new_fd;
@@ -321,7 +321,11 @@ handle_open (char *own_buf)
   if (hostio_fs_pid != 0 && the_target->multifs_open != NULL)
     fd = the_target->multifs_open (hostio_fs_pid, filename,
 				   flags, mode);
-  else
+  /* If multifs_open fails (for example, if we're running as a regular
+     user and don't have permissions to switch to the target's mount
+     namespace), fall back to a regular open. */
+  if (fd == -1)
     fd = open (filename, flags, mode);
   if (fd == -1)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]