projects/guix·blob python-team · refs

85 lines · 2.5 KiB

1/* GNU Guix --- Functional package management for GNU
2 Copyright (C) 2020 Ludovic Courtès <[email protected]>
3
4 This file is part of GNU Guix.
5
6 GNU Guix is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or (at
9 your option) any later version.
10
11 GNU Guix is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
18
19/* This file implements part of the GNU ld.so audit interface. It is used by
20 the "fakechroot" engine of the 'guix pack -RR' wrappers to make sure the
21 loader looks for shared objects under the "fake" root directory. */
22
23#define _GNU_SOURCE 1
24
25#include <link.h>
26
27#include <error.h>
28#include <stdlib.h>
29#include <string.h>
30#include <assert.h>
31
32/* The pseudo root directory and store that we are relocating to. */
33static const char *root_directory;
34static char *store;
35
36/* The original store, "/gnu/store" by default. */
37static const char original_store[] = "@STORE_DIRECTORY@";
38
39/* Like 'malloc', but abort if 'malloc' returns NULL. */
40static void *
41xmalloc (size_t size)
42{
43 void *result = malloc (size);
44 assert (result != NULL);
45 return result;
46}
47
48unsigned int
49la_version (unsigned int v)
50{
51 if (v != LAV_CURRENT)
52 error (1, 0, "cannot handle interface version %u", v);
53
54 root_directory = getenv ("FAKECHROOT_BASE");
55 if (root_directory == NULL)
56 error (1, 0, "'FAKECHROOT_BASE' is not set");
57
58 store = xmalloc (strlen (root_directory) + sizeof original_store);
59 strcpy (store, root_directory);
60 strcat (store, original_store);
61
62 return v;
63}
64
65/* Return NAME, a shared object file name, relocated under STORE. This
66 function is called by the loader whenever it looks for a shared object. */
67char *
68la_objsearch (const char *name, uintptr_t *cookie, unsigned int flag)
69{
70 char *result;
71
72 if (strncmp (name, original_store,
73 sizeof original_store - 1) == 0)
74 {
75 size_t len = strlen (name) - sizeof original_store
76 + strlen (store) + 1;
77 result = xmalloc (len);
78 strcpy (result, store);
79 strcat (result, name + sizeof original_store - 1);
80 }
81 else
82 result = strdup (name);
83
84 return result;
85}