]> git.pld-linux.org Git - packages/chrpath.git/blame - chrpath-multilib.patch
- rediffed
[packages/chrpath.git] / chrpath-multilib.patch
CommitLineData
3ad63461
MK
1diff -urNp -x '*.orig' chrpath-0.16.org/Makefile.am chrpath-0.16/Makefile.am
2--- chrpath-0.16.org/Makefile.am 2014-01-12 08:52:21.000000000 +0100
3+++ chrpath-0.16/Makefile.am 2023-12-16 18:36:06.850493419 +0100
4@@ -12,12 +12,19 @@ debs:
6416aa35
PS
5 fakeroot debian/rules binary
6
7 chrpath_SOURCES = \
8- chrpath.c \
9- killrpath.c \
10 main.c \
11- elf.c \
12 protos.h
13
14+chrpath_LDADD = -ldl
15+
16+lib_LTLIBRARIES = libchrpath32.la libchrpath64.la
17+libchrpath32_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
18+libchrpath32_la_CFLAGS = -DSIZEOF_VOID_P=4
d71ed8fd 19+libchrpath32_la_LDFLAGS = -avoid-version
6416aa35
PS
20+libchrpath64_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
21+libchrpath64_la_CFLAGS = -DSIZEOF_VOID_P=8
d71ed8fd 22+libchrpath64_la_LDFLAGS = -avoid-version
6416aa35 23+
7c6d367c 24 EXTRA_DIST = $(man_MANS)
6416aa35 25
3ad63461
MK
26 config-updates:
27diff -urNp -x '*.orig' chrpath-0.16.org/configure.ac chrpath-0.16/configure.ac
28--- chrpath-0.16.org/configure.ac 2014-01-12 09:01:52.000000000 +0100
29+++ chrpath-0.16/configure.ac 2023-12-16 18:36:06.850493419 +0100
30@@ -16,6 +16,7 @@ CHRPATH_LDRPATH_OPTION
31 dnl Checks for programs.
32 AC_PROG_CC
33 AC_PROG_INSTALL
34+AC_PROG_LIBTOOL
35
36 dnl Checks for libraries.
37
38@@ -26,7 +27,6 @@ AC_CHECK_HEADERS([getopt.h elf.h fcntl.h
39 dnl Checks for typedefs, structures, and compiler characteristics.
40 AC_C_CONST
41 AC_C_BIGENDIAN
42-AC_CHECK_SIZEOF(void *)
43
44 dnl Checks for library functions.
45 AC_CHECK_FUNCS(getopt_long)
46diff -urNp -x '*.orig' chrpath-0.16.org/main.c chrpath-0.16/main.c
47--- chrpath-0.16.org/main.c 2014-01-14 10:15:59.000000000 +0100
48+++ chrpath-0.16/main.c 2023-12-16 18:36:06.850493419 +0100
6416aa35
PS
49@@ -12,13 +12,19 @@
50 # include "config.h"
51 #endif
52
53+#include <dlfcn.h>
54+#include <elf.h>
55+#include <fcntl.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58+#include <string.h>
59 #include <unistd.h>
60 #ifdef HAVE_GETOPT_H
61 #include <getopt.h>
62 #endif
63-#include "protos.h"
64+
65+typedef int (*killrpath_t)(const char *filename);
66+typedef int (*chrpath_t)(const char *filename, const char *newpath, int convert);
67
68 #ifdef HAVE_GETOPT_LONG
69 # define GETOPT_LONG getopt_long
3ad63461 70@@ -63,6 +69,30 @@ usage(char *progname)
6416aa35
PS
71 printf("\n");
72 }
73
74+static unsigned
75+elf_class(const char *filename)
76+{
77+ Elf32_Ehdr ehdr;
78+ int fd;
79+
80+ fd = open(filename, O_RDONLY);
81+ if (fd == -1)
82+ return 0;
83+ if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr))
84+ {
85+ close(fd);
86+ return 0;
87+ }
88+ close(fd);
89+ if ((memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0)
90+ || (ehdr.e_ident[EI_VERSION] != EV_CURRENT))
91+ {
92+ fprintf(stderr, "`%s' probably isn't an ELF file.\n", filename);
93+ return 0;
94+ }
95+ return ehdr.e_ident[EI_CLASS];
96+}
97+
98 int
99 main(int argc, char * const argv[])
100 {
3ad63461 101@@ -75,6 +105,9 @@ main(int argc, char * const argv[])
6416aa35
PS
102 #ifdef HAVE_GETOPT_LONG
103 int option_index = 0;
104 #endif /* HAVE_GETOPT_LONG */
105+ void* dll[2];
106+ killrpath_t killrpath[2];
107+ chrpath_t chrpath[2];
108
109 if (argc < 2)
110 {
3ad63461 111@@ -119,14 +152,31 @@ main(int argc, char * const argv[])
6416aa35
PS
112 }
113 } while (-1 != opt);
114
d71ed8fd 115+ dll[0] = dlopen("libchrpath32.so", RTLD_LAZY);
6416aa35
PS
116+ killrpath[0] = (killrpath_t)dlsym(dll[0], "killrpath");
117+ chrpath[0] = (chrpath_t)dlsym(dll[0], "chrpath");
118+
d71ed8fd 119+ dll[1] = dlopen("libchrpath64.so", RTLD_LAZY);
6416aa35
PS
120+ killrpath[1] = (killrpath_t)dlsym(dll[1], "killrpath");
121+ chrpath[1] = (chrpath_t)dlsym(dll[1], "chrpath");
122+
123 while (optind < argc && (!retval || keep_going))
124 {
125+ const char* program = argv[optind++];
126+ unsigned eclass = elf_class(program);
127+ if (!eclass)
128+ {
129+ retval = 1;
130+ continue;
131+ }
132 if (remove)
133- retval |= killrpath(argv[optind++]);
134+ retval |= killrpath[eclass - ELFCLASS32](program);
135 else
136 /* list by default, replace if path is set */
137- retval |= chrpath(argv[optind++], newpath, convert);
138+ retval |= chrpath[eclass - ELFCLASS32](program, newpath, convert);
139 }
140
141+ dlclose(dll[0]);
142+ dlclose(dll[1]);
143 return retval;
144 }
This page took 0.167002 seconds and 4 git commands to generate.