More update tweaks.
[glibc/history.git] / fedora / glibc_post_upgrade.c
blob095b1ebb32dfb8d480dc022c2d2beb4782192cdd
1 #if defined __sparc__ && defined __arch64__
2 register void *__thread_self __asm ("g7");
3 #endif
4 #include <sys/types.h>
5 #include <sys/wait.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <unistd.h>
9 #include <sys/time.h>
10 #include <dirent.h>
11 #include <stddef.h>
12 #include <fcntl.h>
13 #include <string.h>
14 #include <sys/stat.h>
16 int main(void)
18 pid_t pid;
19 int status, rerun_ldconfig = 0, rerun_cnt = 0;
20 char initpath[256];
22 #ifdef __i386__
23 char buffer[4096];
24 struct pref {
25 char *p;
26 int len;
27 } prefix[] = { { "libc-", 5 }, { "libm-", 5 },
28 { "librt-", 6 }, { "libpthread-", 11 },
29 { "librtkaio-", 10 }, { "libthread_db-", 13 } };
30 int i, j, fd;
31 off_t base;
32 ssize_t ret;
33 #ifdef ARCH_386
34 const char *remove_dirs[] = { "/lib/i686", "/lib/tls" };
35 #else
36 const char *remove_dirs[] = { "/lib/tls/i686" };
37 #endif
38 for (j = 0; j < sizeof (remove_dirs) / sizeof (remove_dirs[0]); ++j)
40 size_t rmlen = strlen (remove_dirs[j]);
41 fd = open (remove_dirs[j], O_RDONLY);
42 if (fd >= 0
43 && (ret = getdirentries (fd, buffer, sizeof (buffer), &base))
44 >= (ssize_t) offsetof (struct dirent, d_name))
46 for (base = 0; base + offsetof (struct dirent, d_name) < ret; )
48 struct dirent *d = (struct dirent *) (buffer + base);
50 for (i = 0; i < sizeof (prefix) / sizeof (prefix[0]); i++)
51 if (! strncmp (d->d_name, prefix[i].p, prefix[i].len))
53 char *p = d->d_name + prefix[i].len;
55 while (*p == '.' || (*p >= '0' && *p <= '9')) p++;
56 if (p[0] == 's' && p[1] == 'o' && p[2] == '\0'
57 && p + 3 - d->d_name
58 < sizeof (initpath) - rmlen - 1)
60 memcpy (initpath, remove_dirs[j], rmlen);
61 initpath[rmlen] = '/';
62 strcpy (initpath + rmlen + 1, d->d_name);
63 unlink (initpath);
64 break;
67 base += d->d_reclen;
69 close (fd);
72 #endif
74 int ldsocfd = open (LD_SO_CONF, O_RDONLY);
75 struct stat ldsocst;
76 if (ldsocfd >= 0 && fstat (ldsocfd, &ldsocst) >= 0)
78 char p[ldsocst.st_size + 1];
79 if (read (ldsocfd, p, ldsocst.st_size) == ldsocst.st_size)
81 p[ldsocst.st_size] = '\0';
82 if (strstr (p, "include ld.so.conf.d/*.conf") == NULL)
84 close (ldsocfd);
85 ldsocfd = open (LD_SO_CONF, O_WRONLY | O_TRUNC);
86 if (ldsocfd >= 0)
88 size_t slen = strlen ("include ld.so.conf.d/*.conf\n");
89 if (write (ldsocfd, "include ld.so.conf.d/*.conf\n", slen)
90 != slen
91 || write (ldsocfd, p, ldsocst.st_size) != ldsocst.st_size)
92 _exit (109);
96 if (ldsocfd >= 0)
97 close (ldsocfd);
102 char linkbuf[64], *linkp;
103 int linklen;
105 pid = vfork ();
106 if (pid == 0)
108 execl ("/sbin/ldconfig", "/sbin/ldconfig", NULL);
109 _exit (110);
111 else if (pid < 0)
112 _exit (111);
113 if (waitpid (0, &status, 0) != pid || !WIFEXITED (status))
114 _exit (112);
115 if (WEXITSTATUS (status))
116 _exit (WEXITSTATUS (status));
118 rerun_ldconfig = 0;
119 #ifdef LIBTLS
120 linkp = linkbuf + strlen (LIBTLS);
121 linklen = readlink (LIBTLS "librt.so.1", linkp,
122 sizeof (linkbuf) - 1 - strlen (LIBTLS));
123 if (linklen == strlen ("librtkaio-2.3.X.so")
124 && memcmp (linkp, "librtkaio-2.3.", 14) == 0
125 && strchr ("23", linkp[14])
126 && memcmp (linkp + 15, ".so", 4) == 0)
128 memcpy (linkbuf, LIBTLS, strlen (LIBTLS));
129 unlink (linkbuf);
130 rerun_ldconfig = 1;
132 #endif
134 #ifdef __i386__
135 linkp = linkbuf + strlen ("/lib/i686/");
136 linklen = readlink ("/lib/i686/librt.so.1", linkp,
137 sizeof (linkbuf) - 1 - strlen ("/lib/i686/"));
138 if (linklen == strlen ("librtkaio-2.3.X.so")
139 && memcmp (linkp, "librtkaio-2.3.", 14) == 0
140 && strchr ("23", linkp[14])
141 && memcmp (linkp + 15, ".so", 4) == 0)
143 memcpy (linkbuf, "/lib/i686/", strlen ("/lib/i686/"));
144 unlink (linkbuf);
145 rerun_ldconfig = 1;
147 #endif
149 while (rerun_ldconfig && ++rerun_cnt < 2);
151 if (! utimes (GCONV_MODULES_CACHE, NULL))
153 pid = vfork ();
154 if (pid == 0)
156 execl ("/usr/sbin/iconvconfig", "/usr/sbin/iconvconfig", NULL);
157 _exit (113);
159 else if (pid < 0)
160 _exit (114);
161 if (waitpid (0, &status, 0) != pid || !WIFEXITED (status))
162 _exit (115);
163 if (WEXITSTATUS (status))
164 _exit (WEXITSTATUS (status));
167 /* Check if telinit is available and the init fifo as well. */
168 if (access ("/sbin/telinit", X_OK) || access ("/dev/initctl", F_OK))
169 _exit (0);
170 /* Check if we are not inside of some chroot, because we'd just
171 timeout and leave /etc/initrunlvl. */
172 if (readlink ("/proc/1/exe", initpath, 256) <= 0 ||
173 readlink ("/proc/1/root", initpath, 256) <= 0)
174 _exit (0);
176 pid = vfork ();
177 if (pid == 0)
179 execl ("/sbin/telinit", "/sbin/telinit", "u", NULL);
180 _exit (116);
182 else if (pid < 0)
183 _exit (117);
184 if (waitpid (0, &status, 0) != pid || !WIFEXITED (status))
185 _exit (118);
187 /* Check if we can safely condrestart sshd. */
188 if (access ("/sbin/service", X_OK) == 0
189 && access ("/usr/sbin/sshd", X_OK) == 0
190 && access ("/bin/bash", X_OK) == 0)
192 pid = vfork ();
193 if (pid == 0)
195 execl ("/sbin/service", "/sbin/service", "sshd", "condrestart", NULL);
196 _exit (119);
198 else if (pid < 0)
199 _exit (120);
200 if (waitpid (0, &status, 0) != pid || !WIFEXITED (status))
201 _exit (121);
204 _exit(0);
207 int __libc_multiple_threads __attribute__((nocommon));
208 int __libc_enable_asynccancel (void) { return 0; }
209 void __libc_disable_asynccancel (int x) { }
210 void __libc_csu_init (void) { }
211 void __libc_csu_fini (void) { }
212 pid_t __fork (void) { return -1; }
213 char thr_buf[65536];
215 #ifndef __powerpc__
216 int __libc_start_main (int (*main) (void), int argc, char **argv,
217 void (*init) (void), void (*fini) (void),
218 void (*rtld_fini) (void), void * stack_end)
219 #else
220 struct startup_info
222 void *sda_base;
223 int (*main) (int, char **, char **, void *);
224 int (*init) (int, char **, char **, void *);
225 void (*fini) (void);
228 int __libc_start_main (int argc, char **ubp_av,
229 char **ubp_ev,
230 void *auxvec, void (*rtld_fini) (void),
231 struct startup_info *stinfo,
232 char **stack_on_entry)
233 #endif
235 #if defined __ia64__ || defined __powerpc64__
236 register void *r13 __asm ("r13") = thr_buf + 32768;
237 __asm ("" : : "r" (r13));
238 #elif defined __sparc__
239 register void *g6 __asm ("g6") = thr_buf + 32768;
240 # ifdef __arch64__
241 __thread_self = thr_buf + 32768;
242 # else
243 register void *__thread_self __asm ("g7") = thr_buf + 32768;
244 # endif
245 __asm ("" : : "r" (g6), "r" (__thread_self));
246 #elif defined __s390__ && !defined __s390x__
247 __asm ("sar %%a0,%0" : : "d" (thr_buf + 32768));
248 #elif defined __s390x__
249 __asm ("sar %%a1,%0; srlg 0,%0,32; sar %%a0,0" : : "d" (thr_buf + 32768) : "0");
250 #elif defined __powerpc__ && !defined __powerpc64__
251 register void *r2 __asm ("r2") = thr_buf + 32768;
252 __asm ("" : : "r" (r2));
253 #endif
254 main();
255 return 0;