This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

[HURD PATCH 7/7] _hurd_exec_file_name: canonicalize filename


	* hurd/hurdexec.c (_hurd_exec_file_name): Canonicalize filename.
---
 hurd/hurdexec.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index c2f45cf..4a69df4 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -47,46 +47,53 @@ link_warning (_hurd_exec,
 /* 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 *canonname;
   char *args, *env;
   size_t argslen, envlen;
   int ints[INIT_INT_MAX];
   mach_port_t ports[_hurd_nports];
   struct hurd_userlink ulink_ports[_hurd_nports];
   inline void free_port (unsigned int i)
     {
       _hurd_port_free (&_hurd_ports[i], &ulink_ports[i], ports[i]);
     }
   file_t *dtable;
   unsigned int dtablesize, i;
   struct hurd_port **dtable_cells;
   struct hurd_userlink *ulink_dtable;
   struct hurd_sigstate *ss;
   mach_port_t *please_dealloc, *pdp;
   int reauth = 0;
 
+  /* Canonicalize the filename for the sake of RPATH $ORIGIN substitution.
+     This is done here because we can't use __realpath from ld.so.
+     Also, realpath uses stat, which under fakeroot uses a socket, so we
+     must do this before _hurd_dtable_lock is acquired below.  */
+  canonname = filename ? __realpath (filename, NULL) : NULL;
+
   /* XXX needs to be hurdmalloc XXX */
   if (argv == NULL)
     args = NULL, argslen = 0;
   else if (err = __argz_create (argv, &args, &argslen))
-    return err;
+    goto outcanonname;
   if (envp == NULL)
     env = NULL, envlen = 0;
   else if (err = __argz_create (envp, &env, &envlen))
     goto outargs;
 
   /* Load up the ports to give to the new program.  */
   for (i = 0; i < _hurd_nports; ++i)
     if (i == INIT_PORT_PROC && task != __mach_task_self ())
       {
 	/* This is another task, so we need to ask the proc server
 	   for the right proc server port for it.  */
 	if (err = __USEPORT (PROC, __proc_task2proc (port, task, &ports[i])))
@@ -373,33 +380,34 @@ _hurd_exec_file_name (task_t task, file_t file, const char *filename,
 	}
 
       flags = 0;
 #ifdef EXEC_SIGTRAP
       /* PTRACE_TRACEME sets all bits in _hurdsig_traced, which is
 	 propagated through exec by INIT_TRACEMASK, so this checks if
 	 PTRACE_TRACEME has been called in this process in any of its
 	 current or prior lives.  */
       if (__sigismember (&_hurdsig_traced, SIGKILL))
 	flags |= EXEC_SIGTRAP;
 #endif
       err = __file_exec_file_name (file, task, flags,
-				   filename ? filename : "",
+				   canonname ?: 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);
     }
@@ -425,14 +433,16 @@ _hurd_exec_file_name (task_t task, file_t file, const char *filename,
       __mach_port_deallocate (__mach_task_self (), dtable[i]);
 
   /* Release lock on the file descriptor table. */
   __mutex_unlock (&_hurd_dtable_lock);
 
   /* Safe to let signals happen now.  */
   _hurd_critical_section_unlock (ss);
 
  outargs:
   free (args);
  outenv:
   free (env);
+ outcanonname:
+  free (canonname);
   return err;
 }
-- 
1.7.5.4


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