]> git.pld-linux.org Git - packages/glibc.git/blob - glibc-LD-path.c
24709031829a3744a3ee206f2da8107c2b7bf688
[packages/glibc.git] / glibc-LD-path.c
1 /*
2  * Copyright (c) 2004 Elan Ruusamäe <glen@pld-linux.org>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *        This product includes software developed by Elan Ruusamäe
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ELAN RUUSAMÄE AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33 /*
34  * Usage
35  * ~~~~~
36  *
37  * This simple program is aimed to be used as a workaround when installing over
38  * glibc which has placed glibc.so into /lib/i686.
39  *
40  * For example, in glibc.spec:
41  *
42  * %post -p /sbin/postshell
43  * /sbin/glibc-postrm /%{_lib}/i686
44  *
45  * Patches and bugreports are welcome, direct them to Elan Ruusamäe
46  * <glen@pld-linux.org>.
47  */
48
49
50 #include <sys/types.h>
51 #include <sys/stat.h>
52 #include <unistd.h>
53 #include <stdio.h>
54 #include <limits.h>
55 #include <errno.h>
56 #include <string.h>
57 #include <stdlib.h>
58
59 int main (int argc, char *argv[])
60 {
61 struct stat st;
62 int i, rv = 0;
63
64         if (argc == 1) {
65                 fprintf(stderr, "This program is intended to be used by glibc postinstall stage.\n");
66                 exit(1);
67         }
68
69         for (i = 1; i < argc; i++) {
70                 char *path = argv[i];
71
72                 if (stat(path, &st) == -1) {
73                         // doesn't exist. good. next please.
74                         if (errno == ENOENT) {
75                                 continue;
76                         }
77                         perror("stat");
78                         exit(1);
79                 }
80
81                 if (S_ISDIR(st.st_mode)) {
82                         char p[strlen(path) + sizeof(".rpmsave") + 1];
83
84                         sprintf(p, "%s.rpmsave", path);
85                         fprintf(stderr, "Renaming %s to %s\n", path, p);
86                         if (rename(path, p) == -1) {
87                                 perror("rename");
88                                 rv = 1;
89                         }
90                 }
91         }
92
93         exit(rv);
94 }
95
This page took 0.0246960000000001 seconds and 3 git commands to generate.