Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 265575 | Differences between
and this patch

Collapse All | Expand All

(-)a/configure.ac (-1 / +1 lines)
Lines 16-21 Link Here
16
dnl Checks for programs.
16
dnl Checks for programs.
17
AC_PROG_CC
17
AC_PROG_CC
18
AC_PROG_INSTALL
18
AC_PROG_INSTALL
19
AC_PROG_LIBTOOL
19
20
20
dnl Checks for libraries.
21
dnl Checks for libraries.
21
22
Lines 26-32 Link Here
26
dnl Checks for typedefs, structures, and compiler characteristics.
27
dnl Checks for typedefs, structures, and compiler characteristics.
27
AC_C_CONST
28
AC_C_CONST
28
AC_C_BIGENDIAN
29
AC_C_BIGENDIAN
29
AC_CHECK_SIZEOF(void *)
30
30
31
dnl Checks for library functions.
31
dnl Checks for library functions.
32
AC_CHECK_FUNCS(getopt_long)
32
AC_CHECK_FUNCS(getopt_long)
(-)a/Makefile.am (-3 / +10 lines)
Lines 12-23 Link Here
12
	fakeroot debian/rules binary
12
	fakeroot debian/rules binary
13
13
14
chrpath_SOURCES = \
14
chrpath_SOURCES = \
15
	chrpath.c	\
16
	killrpath.c	\
17
	main.c		\
15
	main.c		\
18
	elf.c		\
19
	protos.h
16
	protos.h
20
17
18
chrpath_LDADD = -ldl
19
20
lib_LTLIBRARIES = libchrpath32.la libchrpath64.la
21
libchrpath32_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
22
libchrpath32_la_CFLAGS = -DSIZEOF_VOID_P=4
23
libchrpath32_la_LDFLAGS = -avoid-version
24
libchrpath64_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
25
libchrpath64_la_CFLAGS = -DSIZEOF_VOID_P=8
26
libchrpath64_la_LDFLAGS = -avoid-version
27
21
EXTRA_DIST = ChangeLog.usermap $(man_MANS)
28
EXTRA_DIST = ChangeLog.usermap $(man_MANS)
22
29
23
CLEANFILES = *.bb *.bbg *.da *.gcov testsuite/*.bb testsuite/*.bbg
30
CLEANFILES = *.bb *.bbg *.da *.gcov testsuite/*.bb testsuite/*.bbg
(-)a/main.c (-3 / +53 lines)
Lines 12-24 Link Here
12
#  include "config.h"
12
#  include "config.h"
13
#endif
13
#endif
14
14
15
#include <dlfcn.h>
16
#include <elf.h>
17
#include <fcntl.h>
15
#include <stdio.h>
18
#include <stdio.h>
16
#include <stdlib.h>
19
#include <stdlib.h>
20
#include <string.h>
17
#include <unistd.h>
21
#include <unistd.h>
18
#ifdef HAVE_GETOPT_H
22
#ifdef HAVE_GETOPT_H
19
#include <getopt.h>
23
#include <getopt.h>
20
#endif
24
#endif
21
#include "protos.h"
25
26
typedef int (*killrpath_t)(const char *filename);
27
typedef int (*chrpath_t)(const char *filename, const char *newpath, int convert);
22
28
23
#ifdef HAVE_GETOPT_LONG
29
#ifdef HAVE_GETOPT_LONG
24
#  define GETOPT_LONG getopt_long
30
#  define GETOPT_LONG getopt_long
Lines 61-66 Link Here
61
  printf("\n");
67
  printf("\n");
62
}
68
}
63
69
70
static unsigned
71
elf_class(const char *filename)
72
{
73
   Elf32_Ehdr ehdr;
74
   int fd;
75
76
   fd = open(filename, O_RDONLY);
77
   if (fd == -1)
78
     return 0;
79
   if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr))
80
   {
81
     close(fd);
82
     return 0;
83
   }
84
   close(fd);
85
   if ((memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0)
86
       || (ehdr.e_ident[EI_VERSION] != EV_CURRENT))
87
   {
88
     fprintf(stderr, "`%s' probably isn't an ELF file.\n", filename);
89
     return 0;
90
   }
91
   return ehdr.e_ident[EI_CLASS];
92
}
93
64
int
94
int
65
main(int argc, char * const argv[])
95
main(int argc, char * const argv[])
66
{
96
{
Lines 73-78 Link Here
73
#ifdef HAVE_GETOPT_LONG
103
#ifdef HAVE_GETOPT_LONG
74
  int option_index = 0;
104
  int option_index = 0;
75
#endif /* HAVE_GETOPT_LONG */
105
#endif /* HAVE_GETOPT_LONG */
106
  void* dll[2];
107
  killrpath_t killrpath[2];
108
  chrpath_t chrpath[2];
76
109
77
  if (argc < 2)
110
  if (argc < 2)
78
    {
111
    {
Lines 116-129 Link Here
116
      }
149
      }
117
  } while (-1 != opt);
150
  } while (-1 != opt);
118
151
152
  dll[0] = dlopen("libchrpath32.so", RTLD_LAZY);
153
  killrpath[0] = (killrpath_t)dlsym(dll[0], "killrpath");
154
  chrpath[0] = (chrpath_t)dlsym(dll[0], "chrpath");
155
156
  dll[1] = dlopen("libchrpath64.so", RTLD_LAZY);
157
  killrpath[1] = (killrpath_t)dlsym(dll[1], "killrpath");
158
  chrpath[1] = (chrpath_t)dlsym(dll[1], "chrpath");
159
119
  while (optind < argc && (!retval || keep_going))
160
  while (optind < argc && (!retval || keep_going))
120
    {
161
    {
162
      const char* program = argv[optind++];
163
      unsigned eclass = elf_class(program);
164
      if (!eclass)
165
      {
166
        retval = 1;
167
        continue;
168
      }
121
      if (remove)
169
      if (remove)
122
        retval |= killrpath(argv[optind++]);
170
        retval |= killrpath[eclass - ELFCLASS32](program);
123
      else
171
      else
124
        /* list by default, replace if path is set */
172
        /* list by default, replace if path is set */
125
        retval |= chrpath(argv[optind++], newpath, convert);
173
        retval |= chrpath[eclass - ELFCLASS32](program, newpath, convert);
126
    }
174
    }
127
175
176
  dlclose(dll[0]);
177
  dlclose(dll[1]);
128
  return retval;
178
  return retval;
129
}
179
}

Return to bug 265575