1 /* skeleton based on version from Fedora Core 3 */
18 #define verbose_exec(failcode, fail_ok, path...) \
21 char *const arr[] = { path, NULL }; \
22 vexec (failcode, fail_ok, arr); \
25 __attribute__((noinline)) void vexec (int failcode, int fail_ok, char *const path[]);
26 __attribute__((noinline)) void says (const char *str);
27 __attribute__((noinline)) void sayn (long num);
28 __attribute__((noinline)) void message (char *const path[]);
29 __attribute__((noinline)) int check_elf (const char *name);
35 struct stat root, init_root;
37 /* First, get rid of platform-optimized libraries. We remove any we have
38 ever built, since otherwise we might end up using some old leftover
39 libraries when new ones aren't installed in their place anymore. */
40 #ifdef REMOVE_TLS_DIRS
41 const char *library[] = {"libc.so.6", "libc.so.6.1", "libm.so.6",
42 "libm.so.6.1", "librt.so.1", "librtkaio.so.1",
43 "libpthread.so.0", "libthread_db.so.1"};
44 const char *remove_dir[] = {
49 #ifdef REMOVE_PPC_OPTIMIZE_POWER4
53 #ifdef REMOVE_PPC_OPTIMIZE_POWER5
57 #ifdef REMOVE_PPC_OPTIMIZE_POWER6
61 #ifdef REMOVE_PPC_OPTIMIZE_POWER7
64 #ifdef REMOVE_PPC_OPTIMIZE_CELL
65 "/lib64/ppc-cell-be/",
67 #endif /* __powerpc64__ */
69 #ifdef REMOVE_PPC_OPTIMIZE_POWER4
73 #ifdef REMOVE_PPC_OPTIMIZE_POWER5
77 #ifdef REMOVE_PPC_OPTIMIZE_POWER6
81 #ifdef REMOVE_PPC_OPTIMIZE_POWER7
84 #ifdef REMOVE_PPC_OPTIMIZE_CELL
87 #endif /* __powerpc__ */
91 for (i = 0; i < sizeof (remove_dir) / sizeof (remove_dir[0]); ++i)
92 for (j = 0; j < sizeof (library) / sizeof (library[0]); j++)
94 char buf[strlen (remove_dir[i]) + strlen (library[j]) + 1];
95 char readlink_buf[(strlen (remove_dir[i]) + strlen (library[j])) * 2 + 30];
99 cp = stpcpy (buf, remove_dir[i]);
100 strcpy (cp, library[j]);
101 /* This file could be a symlink to library-%{version}.so, so check
102 this and don't remove only the link, but also the library itself. */
103 cp = stpcpy (readlink_buf, remove_dir[i]);
104 if ((len = readlink (buf, cp, (sizeof (readlink_buf)
105 - (cp - readlink_buf) - 1))) > 0)
108 if (cp[0] != '/') cp = readlink_buf;
115 /* If installing bi-arch glibc, rpm sometimes doesn't unpack all files
116 before running one of the lib's %post scriptlet. /sbin/ldconfig will
117 then be run by the other arch's %post. */
118 if (access ("/sbin/ldconfig", X_OK) == 0)
119 verbose_exec (110, 0, "/sbin/ldconfig", "/sbin/ldconfig", "-X");
121 if (utimes (GCONV_MODULES_DIR "/gconv-modules.cache", NULL) == 0)
124 #define ICONVCONFIG "/usr/sbin/iconvconfig"
126 verbose_exec (113, 0, ICONVCONFIG, "/usr/sbin/iconvconfig",
127 "-o", GCONV_MODULES_DIR"/gconv-modules.cache",
128 "--nostdlib", GCONV_MODULES_DIR);
131 /* Implement %set_permissions %{_libexecdir}/pt_chown. */
132 if (access ("/usr/bin/chkstat", X_OK) == 0)
133 verbose_exec (114, 1, "/usr/bin/chkstat", "/usr/bin/chkstat",
134 "-n", "--set", "--system", "/usr/lib/pt_chown");
136 /* Check if telinit is available and the init fifo as well. */
137 if (access ("/sbin/telinit", X_OK) || access ("/dev/initctl", F_OK))
139 /* Check if we are not inside of some chroot, because we'd just
140 timeout and leave /etc/initrunlvl. */
141 if (readlink ("/proc/1/exe", initpath, 256) <= 0 ||
142 readlink ("/proc/1/root", initpath, 256) <= 0 ||
143 stat ("/proc/1/root", &init_root) < 0 ||
144 stat ("/.buildenv", &init_root) < 0 || /* XEN build */
145 stat ("/", &root) < 0 ||
146 init_root.st_dev != root.st_dev || init_root.st_ino != root.st_ino)
149 if (check_elf ("/proc/1/exe"))
150 verbose_exec (116, 0, "/sbin/telinit", "/sbin/telinit", "u");
153 /* Check if we can safely condrestart sshd. */
154 if (access ("/sbin/service", X_OK) == 0
155 && access ("/usr/sbin/sshd", X_OK) == 0
156 && access ("/bin/bash", X_OK) == 0)
158 if (check_elf ("/usr/sbin/sshd"))
159 verbose_exec (121, 0, "/sbin/service", "/sbin/service", "sshd", "condrestart");
167 vexec (int failcode, int fail_ok, char *const path[])
170 int status, save_errno;
175 execv (path[0], path + 1);
178 says (" exec failed with errno ");
187 says (" fork failed with errno ");
190 _exit (failcode + 1);
192 if (waitpid (0, &status, 0) != pid || !WIFEXITED (status))
195 says (" child terminated abnormally\n");
196 _exit (failcode + 2);
198 if (WEXITSTATUS (status))
201 says (" child exited with exit code ");
202 sayn (WEXITSTATUS (status));
205 says (" (ignored) \n");
210 _exit (WEXITSTATUS (status));
216 says (const char *str)
218 write (1, str, strlen (str));
224 char string[sizeof (long) * 3 + 1];
225 char *p = string + sizeof (string) - 1;
233 *--p = '0' + num % 10;
241 message (char *const path[])
243 says ("/usr/sbin/glibc_post_upgrade: While trying to execute ");
248 check_elf (const char *name)
250 /* Play safe, if we can't open or read, assume it might be
251 ELF for the current arch. */
253 int fd = open (name, O_RDONLY);
257 if (read (fd, &ehdr, offsetof (Elf32_Ehdr, e_version))
258 == offsetof (Elf32_Ehdr, e_version))
261 if (ehdr.e_ident[EI_CLASS]
262 == (sizeof (long) == 8 ? ELFCLASS64 : ELFCLASS32))
265 ret = ehdr.e_machine == EM_386;
266 #elif defined __x86_64__
267 ret = ehdr.e_machine == EM_X86_64;
268 #elif defined __ia64__
269 ret = ehdr.e_machine == EM_IA_64;
270 #elif defined __powerpc64__
271 ret = ehdr.e_machine == EM_PPC64;
272 #elif defined __powerpc__
273 ret = ehdr.e_machine == EM_PPC;
274 #elif defined __s390__ || defined __s390x__
275 ret = ehdr.e_machine == EM_S390;
276 #elif defined __x86_64__
277 ret = ehdr.e_machine == EM_X86_64;
278 #elif defined __sparc__
279 if (sizeof (long) == 8)
280 ret = ehdr.e_machine == EM_SPARCV9;
282 ret = (ehdr.e_machine == EM_SPARC
283 || ehdr.e_machine == EM_SPARC32PLUS);
296 int __libc_multiple_threads __attribute__((nocommon));
297 int __libc_enable_asynccancel (void) { return 0; }
298 void __libc_disable_asynccancel (int x) { }
299 void __libc_csu_init (void) { }
300 void __libc_csu_fini (void) { }
301 pid_t __fork (void) { return -1; }
306 __libc_start_main (int (*main) (void), int argc, char **argv,
307 void (*init) (void), void (*fini) (void),
308 void (*rtld_fini) (void), void * stack_end)
313 int (*main) (int, char **, char **, void *);
314 int (*init) (int, char **, char **, void *);
319 __libc_start_main (int argc, char **ubp_av, char **ubp_ev,
320 void *auxvec, void (*rtld_fini) (void),
321 struct startup_info *stinfo,
322 char **stack_on_entry)
325 #if defined __ia64__ || defined __powerpc64__
326 register void *r13 __asm ("r13") = thr_buf + 32768;
327 __asm ("" : : "r" (r13));
328 #elif defined __sparc__
329 register void *g6 __asm ("g6") = thr_buf + 32768;
331 __thread_self = thr_buf + 32768;
333 register void *__thread_self __asm ("g7") = thr_buf + 32768;
335 __asm ("" : : "r" (g6), "r" (__thread_self));
336 #elif defined __s390__ && !defined __s390x__
337 __asm ("sar %%a0,%0" : : "d" (thr_buf + 32768));
338 #elif defined __s390x__
339 __asm ("sar %%a1,%0; srlg 0,%0,32; sar %%a0,0" : : "d" (thr_buf + 32768) : "0");
340 #elif defined __powerpc__ && !defined __powerpc64__
341 register void *r2 __asm ("r2") = thr_buf + 32768;
342 __asm ("" : : "r" (r2));