[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 15/16: Add support for $ORIGIN rpath expansion
From: |
Samuel Thibault |
Subject: |
[hurd] 15/16: Add support for $ORIGIN rpath expansion |
Date: |
Tue, 09 Jan 2018 01:35:30 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit 9d3ba19ddc56ad929f673af23eb87ab07ae30631
Author: Samuel Thibault <address@hidden>
Date: Mon Jan 8 22:56:23 2018 +0100
Add support for $ORIGIN rpath expansion
* exec/exec.c (do_exec): When abspath is absolute, record its dirname
into the LD_ORIGIN_PATH environment variable.
---
exec/exec.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 83 insertions(+), 4 deletions(-)
diff --git a/exec/exec.c b/exec/exec.c
index cc61352..94f0a73 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -951,7 +951,7 @@ do_exec (file_t file,
secure = (flags & EXEC_SECURE);
defaults = (flags & EXEC_DEFAULTS);
- /* Now record the big blocks of data we shuffle around unchanged.
+ /* Now record the big blocks of data we shuffle around.
Whatever arrived inline, we must allocate space for so it can
survive after this RPC returns. */
@@ -962,11 +962,90 @@ do_exec (file_t file,
goto stdout;
boot->argv = argv;
boot->argvlen = argvlen;
- envp = servercopy (envp, envplen, envp_copy, &e.error);
- if (e.error)
- goto stdout;
+
+ if (abspath && abspath[0] == '/')
+ {
+ /* Explicit absolute filename, put its dirname in the LD_ORIGIN_PATH
+ environment variable for $ORIGIN rpath expansion. */
+ const char *end = strrchr (abspath, '/');
+ size_t pathlen;
+ const char ld_origin_s[] = "\0LD_ORIGIN_PATH=";
+ const char *existing;
+ size_t existing_len = 0;
+ size_t new_envplen;
+ char *new_envp;
+
+ /* Drop trailing slashes. */
+ while (end > abspath && end[-1] == '/')
+ end--;
+
+ if (end == abspath)
+ /* Root, keep explicit heading/trailing slash. */
+ end++;
+
+ pathlen = end - abspath;
+
+ if (memcmp (envp, ld_origin_s + 1, sizeof (ld_origin_s) - 2) == 0)
+ /* Existing variable at the beginning of envp. */
+ existing = envp - 1;
+ else
+ /* Look for the definition. */
+ existing = memmem (envp, envplen, ld_origin_s, sizeof (ld_origin_s) -
1);
+
+ if (existing)
+ {
+ /* Definition already exists, just replace the content. */
+ existing += sizeof (ld_origin_s) - 1;
+ existing_len = strnlen (existing, envplen - (existing - envp));
+
+ /* Allocate room for the new content. */
+ new_envplen = envplen - existing_len + pathlen;
+ new_envp = mmap (0, new_envplen,
+ PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
+ if (new_envp == MAP_FAILED)
+ {
+ e.error = errno;
+ goto stdout;
+ }
+
+ /* And copy. */
+ memcpy (new_envp, envp, existing - envp);
+ memcpy (new_envp + (existing - envp), abspath, pathlen);
+ memcpy (new_envp + (existing - envp) + pathlen,
+ existing + existing_len,
+ envplen - ((existing - envp) + existing_len));
+ }
+ else
+ {
+ /* No existing definition, prepend one. */
+ new_envplen = sizeof (ld_origin_s) - 1 + pathlen + envplen;
+ new_envp = mmap (0, new_envplen,
+ PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
+
+ memcpy (new_envp, ld_origin_s + 1, sizeof (ld_origin_s) - 2);
+ memcpy (new_envp + sizeof (ld_origin_s) - 2, abspath, pathlen);
+ new_envp [sizeof (ld_origin_s) - 2 + pathlen] = 0;
+ memcpy (new_envp + sizeof (ld_origin_s) - 2 + pathlen + 1, envp,
envplen);
+ }
+
+ if (! envp_copy)
+ /* Deallocate original environment */
+ munmap (envp, envplen);
+
+ envp = new_envp;
+ envplen = new_envplen;
+ }
+ else
+ {
+ /* No explicit abspath, just copy the existing environment */
+ envp = servercopy (envp, envplen, envp_copy, &e.error);
+ if (e.error)
+ goto stdout;
+ }
+
boot->envp = envp;
boot->envplen = envplen;
+
dtable = servercopy (dtable, dtablesize * sizeof (mach_port_t),
dtable_copy, &e.error);
if (e.error)
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 08/16: libihash: Make sure we do not remove a locp several times, (continued)
- [hurd] 08/16: libihash: Make sure we do not remove a locp several times, Samuel Thibault, 2018/01/08
- [hurd] 02/16: Record executable entry for PIE core dumps, Samuel Thibault, 2018/01/08
- [hurd] 04/16: libfshelp: Add weak reference for hash table reference, Samuel Thibault, 2018/01/08
- [hurd] 13/16: rpctrace: Pass prefixed_name to _hurd_exec_paths., Samuel Thibault, 2018/01/08
- [hurd] 05/16: libfshelp/get-identity.c: add FIXME, Samuel Thibault, 2018/01/08
- [hurd] 01/16: Reserve IDs for proc_set_exe and proc_get_exe, Samuel Thibault, 2018/01/08
- [hurd] 12/16: Use the new _hurd_exec_file_name function, Samuel Thibault, 2018/01/08
- [hurd] 16/16: Implement /proc/<pid>/exe, Samuel Thibault, 2018/01/08
- [hurd] 14/16: Fix exec_paths through fakeroot or chroot, Samuel Thibault, 2018/01/08
- [hurd] 10/16: Add a new exec_exec_paths RPC, Samuel Thibault, 2018/01/08
- [hurd] 15/16: Add support for $ORIGIN rpath expansion,
Samuel Thibault <=
- [hurd] 11/16: Add a file_exec_file_name RPC, Samuel Thibault, 2018/01/08
- [hurd] 03/16: lwip: Add LwIP-based TCP/IP translator, Samuel Thibault, 2018/01/08