bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Use the new file_exec_file_name RPC


From: Emilio Pozuelo Monfort
Subject: [PATCH] Use the new file_exec_file_name RPC
Date: Mon, 26 Jul 2010 19:42:25 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100619 Icedove/3.0.5

Hi,

I've tested __attribute_deprecated__ and link_warning() with the following
test case:

address@hidden:~/tmp$ cat deprecated-_hurd_exec.c 
#define _GNU_SOURCE
#include <stdio.h>
#include <mach.h>
#include <hurd.h>

int
main (int argc, char **argv)
{
  _hurd_exec (__mach_task_self (), MACH_PORT_NULL, NULL, NULL);
  return 0;
}
address@hidden:~/tmp$ gcc -g -Wall -o deprecated-_hurd_exec 
deprecated-_hurd_exec.c 
deprecated-_hurd_exec.c: In function ‘main’:
deprecated-_hurd_exec.c:9: warning: ‘_hurd_exec’ is deprecated (declared at 
/usr/include/hurd.h:252)
/tmp/cciiOS7J.o: In function `main':
/root/tmp/deprecated-_hurd_exec.c:9: warning: _hurd_exec is deprecated, use 
_hurd_exec_file_name instead
address@hidden:~/tmp$ 


What is missing here: we should probably add a check for the presence
of file_exec_file_name in hurd/fs.defs. Ideas on how to do it more
than welcome.

Also I've tested with the Debian package (which is at 2.11.2) so I
needed to change the Versions file. I changed it to 2.11.2, but I
got quite some warnings that GLIBC_2_11_2 was undefined. I changed
it to 2_11 and it worked fine. No idea why.

Regards,
Emilio


2010-07-26  Emilio Pozuelo Monfort  <address@hidden>
        * 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 2d7cf2259596bcb74913851705302fe24ba5c7ef Mon Sep 17 00:00:00 2001
From: Emilio Pozuelo Monfort <address@hidden>
Date: Sat, 22 May 2010 18:26:29 +0200
Subject: [PATCH] Use the new file_exec_file_name RPC

This fixes the problem that a script could end up with /dev/fd/N
in argv[0] because the exec server couldn't guess the file name.
---
 hurd/Versions               |    4 +++
 hurd/hurd.h                 |   14 ++++++++--
 hurd/hurdexec.c             |   52 ++++++++++++++++++++++++++++++-------
 sysdeps/mach/hurd/execve.c  |    6 +++-
 sysdeps/mach/hurd/fexecve.c |    7 +++--
 sysdeps/mach/hurd/spawni.c  |   59 +++++++++++++++++++++++++-----------------
 6 files changed, 100 insertions(+), 42 deletions(-)

diff --git a/hurd/Versions b/hurd/Versions
index 83c8ab1..f760e49 100644
--- a/hurd/Versions
+++ b/hurd/Versions
@@ -156,6 +156,10 @@ libc {
     # functions used in macros & inline functions
     __errno_location;
   }
+  GLIBC_2.12.90 {
+    # "quasi-internal" functions
+    _hurd_exec_file_name;
+  }
 
 %if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
   HURD_CTHREADS_0.3 {
diff --git a/hurd/hurd.h b/hurd/hurd.h
index 642ea43..3429f66 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993,94,95,96,97,98,99,2001,2002,2007
+/* Copyright (C) 1993,94,95,96,97,98,99,2001,2002,2007,2010
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -243,12 +243,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
diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index beae869..1283634 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,99,2001,02
+/* Copyright (C) 1991,92,93,94,95,96,97,99,2001,02,10
        Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -32,11 +32,29 @@
 
 /* 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;
   size_t argslen, envlen;
@@ -218,7 +236,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;
 
@@ -362,13 +380,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.  */
diff --git a/sysdeps/mach/hurd/execve.c b/sysdeps/mach/hurd/execve.c
index 8af8b33..ba5f5a9 100644
--- a/sysdeps/mach/hurd/execve.c
+++ b/sysdeps/mach/hurd/execve.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 94, 95, 97, 2010
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -35,7 +36,8 @@ __execve (file_name, argv, 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);
diff --git a/sysdeps/mach/hurd/fexecve.c b/sysdeps/mach/hurd/fexecve.c
index d6eb7c0..e925d68 100644
--- a/sysdeps/mach/hurd/fexecve.c
+++ b/sysdeps/mach/hurd/fexecve.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1994, 1997, 2010 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -26,8 +26,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);
diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c
index 244ca2d..12ea83f 100644
--- a/sysdeps/mach/hurd/spawni.c
+++ b/sysdeps/mach/hurd/spawni.c
@@ -1,5 +1,5 @@
 /* spawn a new process running an executable.  Hurd version.
-   Copyright (C) 2001,02,04 Free Software Foundation, Inc.
+   Copyright (C) 2001,02,04,10 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -44,7 +44,7 @@ __spawni (pid_t *pid, const char *file,
          int use_path)
 {
   pid_t new_pid;
-  char *path, *p, *name;
+  char *path, *p, *name, *filename;
   size_t len;
   size_t pathlen;
   short int flags;
@@ -60,14 +60,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.
 
@@ -545,7 +545,7 @@ __spawni (pid_t *pid, const char *file,
 
   if (! use_path || 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.  */
@@ -572,20 +572,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:
@@ -622,14 +620,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,
-- 
1.7.1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]