about summary refs log tree commit diff
path: root/hurd
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2018-01-09 01:36:58 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-01-09 01:37:34 +0100
commit311ba8dc4416467947eff2ab327854f124226309 (patch)
treead9a00d6a87de80ddc241b60b2d52aad971fa10e /hurd
parentd7ff3f11b64a28273285d341f795217bbf18ac9c (diff)
downloadglibc-311ba8dc4416467947eff2ab327854f124226309.tar.gz
glibc-311ba8dc4416467947eff2ab327854f124226309.tar.xz
glibc-311ba8dc4416467947eff2ab327854f124226309.zip
hurd: Use the new file_exec_paths RPC
From: Emilio Pozuelo Monfort <pochu27@gmail.com>
From: Svante Signell <svante.signell@gmail.com>

Pass the file paths of executable to the exec server, both relative and
absolute, which exec needs to properly execute and avertise #!-scripts.
Previously, the exec server tried to guess the name from argv[0] but argv[0]
only contains the executable name by convention.

	* hurd/hurdexec.c (_hurd_exec): Deprecate function.
	(_hurd_exec_paths): New function.
	* hurd/hurd.h (_hurd_exec): Deprecate function.
	(_hurd_exec_paths): Declare function.
	* hurd/Versions: Export _hurd_exec_paths.
	* sysdeps/mach/hurd/execve.c: Include <stdlib.h> and <stdio.h>
	(__execve): Use __getcwd to build absolute path, and use
	_hurd_exec_paths instead of _hurd_exec.
	* sysdeps/mach/hurd/spawni.c: Likewise.
	* sysdeps/mach/hurd/fexecve.c: Use _hurd_exec_paths instead of
	_hurd_exec.
Diffstat (limited to 'hurd')
-rw-r--r--hurd/Versions4
-rw-r--r--hurd/hurd.h13
-rw-r--r--hurd/hurdexec.c52
3 files changed, 58 insertions, 11 deletions
diff --git a/hurd/Versions b/hurd/Versions
index 77f5b4271e..b059405a50 100644
--- a/hurd/Versions
+++ b/hurd/Versions
@@ -129,6 +129,10 @@ libc {
     # functions used in macros & inline functions
     __errno_location;
   }
+  GLIBC_2.27 {
+    # "quasi-internal" functions
+    _hurd_exec_paths;
+  }
 
   HURD_CTHREADS_0.3 {
     # weak refs to libthreads functions that libc calls iff libthreads in use
diff --git a/hurd/hurd.h b/hurd/hurd.h
index a3d534a35a..7cf23b5598 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -240,12 +240,21 @@ extern FILE *fopenport (io_t port, const char *mode);
 extern FILE *__fopenport (io_t port, const char *mode);
 
 
-/* Execute a file, replacing TASK's current program image.  */
+/* Deprecated: use _hurd_exec_paths instead.  */
 
 extern error_t _hurd_exec (task_t task,
 			   file_t file,
 			   char *const argv[],
-			   char *const envp[]);
+			   char *const envp[]) __attribute_deprecated__;
+
+/* Execute a file, replacing TASK's current program image.  */
+
+extern error_t _hurd_exec_paths (task_t task,
+				 file_t file,
+				 const char *path,
+				 const char *abspath,
+				 char *const argv[],
+				 char *const envp[]);
 
 
 /* Inform the proc server we have exited with STATUS, and kill the
diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index 6fa9cf5c1d..027fa5a3ee 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -30,11 +30,30 @@
 
 /* Overlay TASK, executing FILE with arguments ARGV and environment ENVP.
    If TASK == mach_task_self (), some ports are dealloc'd by the exec server.
-   ARGV and ENVP are terminated by NULL pointers.  */
+   ARGV and ENVP are terminated by NULL pointers.
+   Deprecated: use _hurd_exec_paths instead.  */
 error_t
 _hurd_exec (task_t task, file_t file,
 	    char *const argv[], char *const envp[])
 {
+  return _hurd_exec_paths (task, file, NULL, NULL, argv, envp);
+}
+
+link_warning (_hurd_exec,
+	      "_hurd_exec is deprecated, use _hurd_exec_paths instead");
+
+/* Overlay TASK, executing FILE with arguments ARGV and environment ENVP.
+   If TASK == mach_task_self (), some ports are dealloc'd by the exec server.
+   ARGV and ENVP are terminated by NULL pointers.  PATH is the relative path to
+   FILE and ABSPATH is the absolute path to FILE. Passing NULL, though possible,
+   should be avoided, since then the exec server may not know the path to
+   FILE if FILE is a script, and will then pass /dev/fd/N to the
+   interpreter.  */
+error_t
+_hurd_exec_paths (task_t task, file_t file,
+		   const char *path, const char *abspath,
+		   char *const argv[], char *const envp[])
+{
   error_t err;
   char *args, *env;
   size_t argslen, envlen;
@@ -216,7 +235,7 @@ _hurd_exec (task_t task, file_t file,
       /* We have euid != svuid or egid != svgid.  POSIX.1 says that exec
 	 sets svuid = euid and svgid = egid.  So we must get a new auth
 	 port and reauthenticate everything with it.  We'll pass the new
-	 ports in file_exec instead of our own ports.  */
+	 ports in file_exec_paths instead of our own ports.  */
 
       auth_t newauth;
 
@@ -360,13 +379,28 @@ _hurd_exec (task_t task, file_t file,
       if (__sigismember (&_hurdsig_traced, SIGKILL))
 	flags |= EXEC_SIGTRAP;
 #endif
-      err = __file_exec (file, task, flags,
-			 args, argslen, env, envlen,
-			 dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
-			 ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
-			 ints, INIT_INT_MAX,
-			 please_dealloc, pdp - please_dealloc,
-			 &_hurd_msgport, task == __mach_task_self () ? 1 : 0);
+      err = __file_exec_paths (file, task, flags,
+			       path ? path : "",
+			       abspath ? abspath : "",
+			       args, argslen, env, envlen,
+			       dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+			       ports, MACH_MSG_TYPE_COPY_SEND,
+			       _hurd_nports,
+			       ints, INIT_INT_MAX,
+			       please_dealloc, pdp - please_dealloc,
+			       &_hurd_msgport,
+			       task == __mach_task_self () ? 1 : 0);
+      /* Fall back for backwards compatibility.  This can just be removed
+         when __file_exec goes away.  */
+      if (err == MIG_BAD_ID)
+	err = __file_exec (file, task, flags,
+			   args, argslen, env, envlen,
+			   dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+			   ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
+			   ints, INIT_INT_MAX,
+			   please_dealloc, pdp - please_dealloc,
+			   &_hurd_msgport,
+			   task == __mach_task_self () ? 1 : 0);
     }
 
   /* Release references to the standard ports.  */