]> git.pld-linux.org Git - packages/glibc.git/blob - glibc-postshell.patch
- trigger to try to rescue ld.so.conf after glibc-misc upgrade (untested)
[packages/glibc.git] / glibc-postshell.patch
1 diff -urN glibc-2.3.1-/elf/Makefile glibc-2.3.1/elf/Makefile
2 --- glibc-2.3.1-/elf/Makefile   Thu Oct 17 15:21:30 2002
3 +++ glibc-2.3.1/elf/Makefile    Thu Oct 17 15:18:20 2002
4 @@ -95,7 +95,7 @@
5  install-bin-script = ldd
6  endif
7  
8 -others         = sprof sln
9 +others         = postshell sprof sln
10  install-bin    = sprof
11  others-static   = sln
12  install-rootsbin = sln
13 diff -urN glibc-2.3.1-/elf/postshell.c glibc-2.3.1/elf/postshell.c
14 --- glibc-2.3.1-/elf/postshell.c        Thu Jan  1 01:00:00 1970
15 +++ glibc-2.3.1/elf/postshell.c Thu Oct 17 14:54:34 2002
16 @@ -0,0 +1,216 @@
17 +/*
18 + * Copyright (c) 2002 Michal Moskal <malekith@pld-linux.org>.
19 + * All rights reserved.
20 + *
21 + * Redistribution and use in source and binary forms, with or without
22 + * modification, are permitted provided that the following conditions
23 + * are met:
24 + * 1. Redistributions of source code must retain the above copyright
25 + *    notice, this list of conditions and the following disclaimer.
26 + * 2. Redistributions in binary form must reproduce the above copyright
27 + *    notice, this list of conditions and the following disclaimer in the
28 + *    documentation and/or other materials provided with the distribution.
29 + * 3. All advertising materials mentioning features or use of this software
30 + *    must display the following acknowledgement:
31 + *     This product includes software developed by Michal Moskal.
32 + * 4. Neither the name of the author nor the names of any co-contributors
33 + *    may be used to endorse or promote products derived from this software
34 + *    without specific prior written permission.
35 + *
36 + * THIS SOFTWARE IS PROVIDED BY MICHAL MOSKAL AND CONTRIBUTORS ``AS IS'' AND
37 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
40 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 + * SUCH DAMAGE.
47 + */
48 +
49 +/*
50 + * Usage
51 + * ~~~~~
52 + *
53 + * This simple program is aimed to be used as script interpreter in rpm
54 + * %post scriptlets and the like. It opens file passed as first argument
55 + * and executes commands found there. Only linear execution is supported.
56 + * For example, in glibc.spec:
57 + *
58 + * %post -p /sbin/postshell
59 + * ldconfig
60 + * -telinit q
61 + *
62 + * (full patch like /sbin/ldconfig or -/sbin/tellinit will also work).
63 + *
64 + * If command starts with - its exit status is ignored. Otherwise last 
65 + * non-zero exit status is returned.
66 + *
67 + * There are no builtin commands (yet :).
68 + *
69 + * Following commands *will* work as expected (as in Bourne shell):
70 + *
71 + * /bin/echo "Foo     bar baz"
72 + * insmod foobar options="foo bar 'qux'"
73 + * false
74 + *
75 + * Following *won't*:
76 + *
77 + * exit 1
78 + * echo foo || echo baz
79 + * set -x
80 + * 
81 + * Patches and bugreports are welcome, direct them to Michal Moskal
82 + * <malekith@pld-linux.org>.
83 + */
84 +
85 +#define _GNU_SOURCE
86 +#include <sys/types.h>
87 +#include <sys/wait.h>
88 +#include <unistd.h>
89 +#include <stdio.h>
90 +#include <stdlib.h>
91 +#include <string.h>
92 +
93 +#define MAX_LINE 1024
94 +#define MAX_ARGS 32
95 +#define SEARCH_PATH { "/sbin/", "/bin/", "/usr/sbin/", "/usr/bin/", NULL }
96 +
97 +int exit_status;
98 +int ignore_status;
99 +
100 +void do_execve(char **argv)
101 +{
102 +       char *path[] = SEARCH_PATH;
103 +       char file[MAX_LINE + 100];
104 +       int i; 
105 +
106 +       if (**argv == '.' || **argv == '/')
107 +               execve(argv[0], argv, environ);
108 +       else 
109 +               for (i = 0; path[i]; i++) {
110 +                       strcpy(file, path[i]);
111 +                       strcat(file, argv[0]);
112 +                       execve(file, argv, environ);
113 +               }
114 +}
115 +
116 +int exec_and_wait(char **argv)
117 +{
118 +       pid_t pid;
119 +
120 +       pid = fork();
121 +
122 +       if (pid == -1) {
123 +               perror("fork");
124 +               return -1;
125 +       } else if (pid == 0) {
126 +               /* child. */
127 +               do_execve(argv);
128 +               if (!ignore_status) 
129 +                       perror(argv[0]); 
130 +               exit(127);
131 +       } else {
132 +               int status, err;
133 +               
134 +               err = waitpid(pid, &status, 0);
135 +               if (err < 0) {
136 +                       perror("waitpid");
137 +                       return -1;
138 +               } else
139 +                       return WEXITSTATUS(status);
140 +       }
141 +}
142 +
143 +void split_argv(char **argv, char *s)
144 +{
145 +       char *dst;
146 +       int argc, delim;
147 +       
148 +       for (argc = 0; argc < MAX_ARGS; argc++) {
149 +               while (*s == ' ' || *s == '\t')
150 +                       s++;
151 +
152 +               if (*s == 0)
153 +                       break;
154 +
155 +               argv[argc] = s;
156 +               dst = s;
157 +               
158 +               while (*s && *s != ' ' && *s != '\t') {
159 +                       if (*s == '\'' || *s == '"') {
160 +                               delim = *s++;
161 +                               while (*s && *s != delim)
162 +                                       *dst++ = *s++;
163 +                               if (*s)
164 +                                       s++;
165 +                       } else {
166 +                               *dst++ = *s++;
167 +                       }
168 +               }
169 +
170 +               if (*dst) {
171 +                       if (s == dst)
172 +                               s++;
173 +                       *dst++ = 0;
174 +               }
175 +       }
176 +
177 +       argv[argc] = NULL;
178 +}
179 +
180 +void exec_line(char *s)
181 +{
182 +       char *argv[MAX_ARGS + 1];
183 +       int ret;
184 +
185 +       split_argv(argv, s);
186 +       
187 +       ignore_status = 0;
188 +
189 +       if (**argv == '-') {
190 +               ignore_status++;
191 +               (*argv)++;
192 +       }
193 +
194 +       ret = exec_and_wait(argv);
195 +
196 +       if (ret && !ignore_status)
197 +               exit_status = ret;
198 +}
199 +
200 +void exec_file(FILE *f)
201 +{
202 +       char line[MAX_LINE];
203 +
204 +       while (fgets(line, sizeof(line), f)) {
205 +               /* chomp it */
206 +               if (line[strlen(line) - 1] == '\n')
207 +                       line[strlen(line) - 1] = 0;
208 +               /* and exec. */
209 +               exec_line(line);
210 +       }
211 +}
212 +
213 +int main(int argc, char **argv)
214 +{
215 +       FILE *f;
216 +
217 +       if (argc < 2) {
218 +               fprintf(stderr, "USAGE: %s filename\n", argv[0]);
219 +               exit(1);
220 +       }
221 +
222 +       f = fopen(argv[1], "r");
223 +       
224 +       if (f == NULL) {
225 +               perror(argv[1]);
226 +               exit(1);
227 +       }
228 +
229 +       exec_file(f);
230 +       fclose(f);
231 +       exit(exit_status);
232 +}
This page took 0.038204 seconds and 3 git commands to generate.