submitted-exec_filename
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Mon, 16 Jan 2017 17:43:37 +0000 (17:43 +0000)
committerAurelien Jarno <aurel32@debian.org>
Mon, 16 Jan 2017 17:43:37 +0000 (17:43 +0000)
2.13-33 dates when this was added

TODO: _DEBIAN_ in versions however pose problem. Remove the _DEBIAN_ version
once packages are rebuilt against 2.21.

2010-08-04  Emilio Pozuelo Monfort  <pochu27@gmail.com>
* hurd/hurdexec.c (_hurd_exec): Deprecate it.
(_hurd_exec_file_name): New function.
* hurd/hurd.h (_hurd_exec): Deprecate it.
(_hurd_exec_file_name): Declare it.
* hurd/Versions: Export it.
* sysdeps/mach/hurd/execve.c: Use it.
* sysdeps/mach/hurd/fexecve.c: Likewise.
* sysdeps/mach/hurd/spawni.c: Likewise.

From d1793416cf8bf6fccd42679a8ec30b0058823ab8 Mon Sep 17 00:00:00 2001
From: Emilio Pozuelo Monfort <pochu27@gmail.com>
Date: Sat, 22 May 2010 18:26:29 +0200
Subject: [PATCH] Use the new file_exec_file_name RPC

Pass the file name of executable to the exec server, which it needs to
execute #!-scripts.  Currently, the exec server tries to guess the name
from argv[0] but argv[0] only contains the executable name by convention.

Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name submitted-exec_filename.diff

hurd/Makefile
hurd/Versions
hurd/hurd.h
hurd/hurdexec.c
sysdeps/mach/hurd/execve.c
sysdeps/mach/hurd/fexecve.c
sysdeps/mach/hurd/spawni.c

index 8a38066bfea633830cb1e9a67a47966f898573c1..b79fa18305d0a9cd3130a0d4e3685c4ee7504657 100644 (file)
@@ -32,8 +32,8 @@ user-interfaces               := $(addprefix hurd/,\
                                       auth auth_request auth_reply startup \
                                       process process_request \
                                       msg msg_reply msg_request \
-                                      exec exec_startup crash interrupt \
-                                      fs fsys io term tioctl socket ifsock \
+                                      exec exec_experimental exec_startup crash interrupt \
+                                      fs fs_experimental fsys io term tioctl socket ifsock \
                                       login password pfinet \
                                       )
 server-interfaces      := hurd/msg faultexc
index 41ea1aef9bc859a9bd76e90610d70ca8cf486f00..c44e3e0412fac0d0a1936cd8529d6063fb3af30c 100644 (file)
@@ -140,6 +140,14 @@ libc {
     _hurd_sigstate_unlock;
     _hurd_sigstate_delete;
   }
+  GLIBC_2.13_DEBIAN_33 {
+    # "quasi-internal" functions
+    _hurd_exec_file_name;
+  }
+  GLIBC_2.21 {
+    # "quasi-internal" functions
+    _hurd_exec_file_name;
+  }
 
   HURD_CTHREADS_0.3 {
     # weak refs to libthreads functions that libc calls iff libthreads in use
index ec0782797d7be0785463ce634e558938a1243e76..ac6ad589b2e0d24cd6f4667a58caab97e8564f3a 100644 (file)
@@ -241,12 +241,20 @@ 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_file_name 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_file_name (task_t task,
+                                    file_t file,
+                                    const char *filename,
+                                    char *const argv[],
+                                    char *const envp[]);
 
 
 /* Inform the proc server we have exited with STATUS, and kill the
index 79a6208743ed32214ce4559dd9b4c1eaa8f31a0c..355a1d973cd5c1d1e6c35053786eef77e4102622 100644 (file)
 #include <hurd/fd.h>
 #include <hurd/signal.h>
 #include <hurd/id.h>
+#include <hurd/fs_experimental.h>
 #include <assert.h>
 #include <argz.h>
 
+#include <shlib-compat.h>
+
 /* 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_file_name instead.  */
 error_t
 _hurd_exec (task_t task, file_t file,
            char *const argv[], char *const envp[])
+{
+  return _hurd_exec_file_name (task, file, NULL, argv, envp);
+}
+
+link_warning (_hurd_exec,
+             "_hurd_exec is deprecated, use _hurd_exec_file_name 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.  FILENAME is the path
+   (either absolute or relative) 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_file_name (task_t task, file_t file, const char *filename,
+                     char *const argv[], char *const envp[])
 {
   error_t err;
   char *args, *env;
@@ -216,7 +237,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_file_name instead of our own ports.  */
 
       auth_t newauth;
 
@@ -360,13 +381,27 @@ _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_file_name (file, task, flags,
+                                  filename ? filename : "",
+                                  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.  */
@@ -401,3 +436,13 @@ _hurd_exec (task_t task, file_t file,
   free (env);
   return err;
 }
+versioned_symbol (libc, __hurd_exec_file_name, _hurd_exec_file_name, GLIBC_2_21);
+#if SHLIB_COMPAT (libc, GLIBC_2_13, GLIBC_2_21)
+error_t
+__hurd_exec_file_name_2_13 (task_t task, file_t file, const char *filename,
+                     char *const argv[], char *const envp[])
+{
+  return __hurd_exec_file_name (task, file, filename, argv, envp);
+}
+compat_symbol (libc, __hurd_exec_file_name_2_13, _hurd_exec_file_name, GLIBC_2_13_DEBIAN_33);
+#endif
index 6904fc64523b4274083c9df96135eb8699dd8b4d..6c5f0eff18cc706685f615baa505ea2549151561 100644 (file)
@@ -31,7 +31,8 @@ __execve (const char *file_name, char *const argv[], char *const envp[])
     return -1;
 
   /* Hopefully this will not return.  */
-  err = _hurd_exec (__mach_task_self (), file, argv, envp);
+  err = _hurd_exec_file_name (__mach_task_self (), file,
+                             file_name, argv, envp);
 
   /* Oh well.  Might as well be tidy.  */
   __mach_port_deallocate (__mach_task_self (), file);
index e7b451543a7e29f54469cb5ca61f9a2088bf3df1..0f8af7b841b80a34bccab2cc95e0465835fc6e20 100644 (file)
@@ -25,8 +25,9 @@
 int
 fexecve (int fd, char *const argv[], char *const envp[])
 {
-  error_t err = HURD_DPORT_USE (fd, _hurd_exec (__mach_task_self (), port,
-                                               argv, envp));
+  error_t err = HURD_DPORT_USE (fd, _hurd_exec_file_name (__mach_task_self (),
+                                                         port, NULL,
+                                                         argv, envp));
   if (! err)
     err = EGRATUITOUS;
   return __hurd_fail (err);
index e4d0be152452f7c6cdca14796762e22480bf3fb1..22e426afcc1e162dca963858bc70b33f9c198d05 100644 (file)
@@ -29,6 +29,7 @@
 #include <hurd/id.h>
 #include <hurd/lookup.h>
 #include <hurd/resource.h>
+#include <hurd/fs_experimental.h>
 #include <assert.h>
 #include <argz.h>
 #include "spawn_int.h"
@@ -44,6 +45,7 @@ __spawni (pid_t *pid, const char *file,
 {
   pid_t new_pid;
   char *path, *p, *name;
+  const char *filename;
   size_t len;
   size_t pathlen;
   short int flags;
@@ -59,14 +61,14 @@ __spawni (pid_t *pid, const char *file,
      that remains visible after an exec is registration with the proc
      server, and the inheritance of various values and ports.  All those
      inherited values and ports are what get collected up and passed in the
-     file_exec RPC by an exec call.  So we do the proc server registration
-     here, following the model of fork (see fork.c).  We then collect up
-     the inherited values and ports from this (parent) process following
-     the model of exec (see hurd/hurdexec.c), modify or replace each value
-     that fork would (plus the specific changes demanded by ATTRP and
-     FILE_ACTIONS), and make the file_exec RPC on the requested executable
-     file with the child process's task port rather than our own.  This
-     should be indistinguishable from the fork + exec implementation,
+     file_exec_file_name RPC by an exec call.  So we do the proc server
+     registration here, following the model of fork (see fork.c).  We then
+     collect up the inherited values and ports from this (parent) process
+     following the model of exec (see hurd/hurdexec.c), modify or replace each
+     value that fork would (plus the specific changes demanded by ATTRP and
+     FILE_ACTIONS), and make the file_exec_file_name RPC on the requested
+     executable file with the child process's task port rather than our own.
+     This should be indistinguishable from the fork + exec implementation,
      except that all errors will be detected here (in the parent process)
      and return proper errno codes rather than the child dying with 127.
 
@@ -546,7 +548,7 @@ __spawni (pid_t *pid, const char *file,
 
   if ((xflags & SPAWN_XFLAGS_USE_PATH) == 0 || strchr (file, '/') != NULL)
     /* The FILE parameter is actually a path.  */
-    err = child_lookup (file, O_EXEC, 0, &execfile);
+    err = child_lookup (filename = file, O_EXEC, 0, &execfile);
   else
     {
       /* We have to search for FILE on the path.  */
@@ -573,20 +575,18 @@ __spawni (pid_t *pid, const char *file,
       p = path;
       do
        {
-         char *startp;
-
          path = p;
          p = __strchrnul (path, ':');
 
          if (p == path)
            /* Two adjacent colons, or a colon at the beginning or the end
               of `PATH' means to search the current directory.  */
-           startp = name + 1;
+           filename = name + 1;
          else
-           startp = (char *) memcpy (name - (p - path), path, p - path);
+           filename = (char *) memcpy (name - (p - path), path, p - path);
 
          /* Try to open this file name.  */
-         err = child_lookup (startp, O_EXEC, 0, &execfile);
+         err = child_lookup (filename, O_EXEC, 0, &execfile);
          switch (err)
            {
            case EACCES:
@@ -623,14 +623,27 @@ __spawni (pid_t *pid, const char *file,
 
     inline error_t exec (file_t file)
       {
-       return __file_exec (file, task,
-                           (__sigismember (&_hurdsig_traced, SIGKILL)
-                            ? EXEC_SIGTRAP : 0),
-                           args, argslen, env, envlen,
-                           dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
-                           ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
-                           ints, INIT_INT_MAX,
-                           NULL, 0, NULL, 0);
+       error_t err = __file_exec_file_name
+         (file, task,
+          __sigismember (&_hurdsig_traced, SIGKILL) ? EXEC_SIGTRAP : 0,
+          filename, args, argslen, env, envlen,
+          dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+          ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
+          ints, INIT_INT_MAX, NULL, 0, NULL, 0);
+
+       /* Fallback for backwards compatibility.  This can just be removed
+          when __file_exec goes away.  */
+       if (err == MIG_BAD_ID)
+         return __file_exec (file, task,
+                             (__sigismember (&_hurdsig_traced, SIGKILL)
+                             ? EXEC_SIGTRAP : 0),
+                             args, argslen, env, envlen,
+                             dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+                             ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
+                             ints, INIT_INT_MAX,
+                             NULL, 0, NULL, 0);
+
+       return err;
       }
 
     /* Now we are out of things that can fail before the file_exec RPC,