rev |
line source |
pascal@757
|
1 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-completion.patch
|
pascal@757
|
2 --- busybox-1.10.1/libbb/lineedit.c Sat Apr 19 05:50:33 2008
|
pascal@757
|
3 +++ busybox-1.10.1-completion/libbb/lineedit.c Thu Apr 24 06:45:39 2008
|
pascal@757
|
4 @@ -518,8 +518,8 @@
|
pascal@757
|
5
|
pascal@757
|
6 for (i = 0; i < npaths; i++) {
|
pascal@757
|
7 dir = opendir(paths[i]);
|
pascal@757
|
8 - if (!dir) /* Don't print an error */
|
pascal@757
|
9 - continue;
|
pascal@757
|
10 + if (!dir)
|
pascal@757
|
11 + continue; /* don't print an error */
|
pascal@757
|
12
|
pascal@757
|
13 while ((next = readdir(dir)) != NULL) {
|
pascal@757
|
14 int len1;
|
pascal@757
|
15 @@ -529,18 +529,21 @@
|
pascal@757
|
16 if (strncmp(str_found, pfind, strlen(pfind)))
|
pascal@757
|
17 continue;
|
pascal@757
|
18 /* not see .name without .match */
|
pascal@757
|
19 - if (*str_found == '.' && *pfind == 0) {
|
pascal@757
|
20 + if (*str_found == '.' && *pfind == '\0') {
|
pascal@757
|
21 if (NOT_LONE_CHAR(paths[i], '/') || str_found[1])
|
pascal@757
|
22 continue;
|
pascal@757
|
23 str_found = ""; /* only "/" */
|
pascal@757
|
24 }
|
pascal@757
|
25 found = concat_path_file(paths[i], str_found);
|
pascal@757
|
26 - /* hmm, remover in progress? */
|
pascal@757
|
27 - if (lstat(found, &st) < 0)
|
pascal@757
|
28 + /* hmm, remove in progress? */
|
pascal@757
|
29 + /* NB: stat() first so that we see is it a directory;
|
pascal@757
|
30 + * but if that fails, use lstat() so that
|
pascal@757
|
31 + * we still match dangling links */
|
pascal@757
|
32 + if (stat(found, &st) && lstat(found, &st))
|
pascal@757
|
33 goto cont;
|
pascal@757
|
34 /* find with dirs? */
|
pascal@757
|
35 if (paths[i] != dirbuf)
|
pascal@757
|
36 - strcpy(found, next->d_name); /* only name */
|
pascal@757
|
37 + strcpy(found, next->d_name); /* only name */
|
pascal@757
|
38
|
pascal@757
|
39 len1 = strlen(found);
|
pascal@757
|
40 found = xrealloc(found, len1 + 2);
|
pascal@757
|
41 @@ -548,7 +551,7 @@
|
pascal@757
|
42 found[len1+1] = '\0';
|
pascal@757
|
43
|
pascal@757
|
44 if (S_ISDIR(st.st_mode)) {
|
pascal@757
|
45 - /* name is directory */
|
pascal@757
|
46 + /* name is a directory */
|
pascal@757
|
47 if (found[len1-1] != '/') {
|
pascal@757
|
48 found[len1] = '/';
|
pascal@757
|
49 }
|
pascal@757
|
50 @@ -566,7 +569,7 @@
|
pascal@757
|
51 closedir(dir);
|
pascal@757
|
52 }
|
pascal@757
|
53 if (paths != path1) {
|
pascal@757
|
54 - free(paths[0]); /* allocated memory only in first member */
|
pascal@757
|
55 + free(paths[0]); /* allocated memory is only in first member */
|
pascal@757
|
56 free(paths);
|
pascal@757
|
57 }
|
pascal@757
|
58 #undef dirbuf
|
pascal@757
|
59 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-echo.patch
|
pascal@757
|
60 --- busybox-1.10.1/coreutils/echo.c Sat Apr 19 05:50:32 2008
|
pascal@757
|
61 +++ busybox-1.10.1-echo/coreutils/echo.c Wed Apr 30 02:37:08 2008
|
pascal@757
|
62 @@ -27,10 +27,8 @@
|
pascal@757
|
63
|
pascal@757
|
64 /* This is a NOFORK applet. Be very careful! */
|
pascal@757
|
65
|
pascal@757
|
66 -/* argc is unused, but removing it precludes compiler from
|
pascal@757
|
67 - * using call -> jump optimization */
|
pascal@757
|
68 +/* NB: can be used by shell even if not enabled as applet */
|
pascal@757
|
69
|
pascal@757
|
70 -int echo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
pascal@757
|
71 int echo_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
pascal@757
|
72 {
|
pascal@757
|
73 const char *arg;
|
pascal@757
|
74 @@ -110,15 +108,19 @@
|
pascal@757
|
75 }
|
pascal@757
|
76 #if !ENABLE_FEATURE_FANCY_ECHO
|
pascal@757
|
77 /* SUSv3 specifies that octal escapes must begin with '0'. */
|
pascal@757
|
78 - if ( (((unsigned char)*arg) - '1') >= 7)
|
pascal@757
|
79 + if ( ((int)(unsigned char)(*arg) - '0') >= 8) /* '8' or bigger */
|
pascal@757
|
80 #endif
|
pascal@757
|
81 {
|
pascal@757
|
82 /* Since SUSv3 mandates a first digit of 0, 4-digit octals
|
pascal@757
|
83 * of the form \0### are accepted. */
|
pascal@757
|
84 - if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
|
pascal@757
|
85 - arg++;
|
pascal@757
|
86 + if (*arg == '0') {
|
pascal@757
|
87 + /* NB: don't turn "...\0" into "...\" */
|
pascal@757
|
88 + if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) {
|
pascal@757
|
89 + arg++;
|
pascal@757
|
90 + }
|
pascal@757
|
91 }
|
pascal@757
|
92 - /* bb_process_escape_sequence can handle nul correctly */
|
pascal@757
|
93 + /* bb_process_escape_sequence handles NUL correctly
|
pascal@757
|
94 + * ("...\" case). */
|
pascal@757
|
95 c = bb_process_escape_sequence(&arg);
|
pascal@757
|
96 }
|
pascal@757
|
97 }
|
pascal@757
|
98 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-fixes-1.10.1.u
|
pascal@757
|
99 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-hppa.patch
|
pascal@757
|
100 --- busybox-1.10.1/include/libbb.h Sat Apr 19 05:50:36 2008
|
pascal@757
|
101 +++ busybox-1.10.1-hppa/include/libbb.h Mon Apr 28 10:34:36 2008
|
pascal@757
|
102 @@ -288,20 +288,20 @@
|
pascal@757
|
103 * SIGSYS Bad argument to routine
|
pascal@757
|
104 * SIGTRAP Trace/breakpoint trap
|
pascal@757
|
105 */
|
pascal@757
|
106 - BB_FATAL_SIGS = 0
|
pascal@757
|
107 - + (1 << SIGHUP)
|
pascal@757
|
108 - + (1 << SIGINT)
|
pascal@757
|
109 - + (1 << SIGTERM)
|
pascal@757
|
110 - + (1 << SIGPIPE) // Write to pipe with no readers
|
pascal@757
|
111 - + (1 << SIGQUIT) // Quit from keyboard
|
pascal@757
|
112 - + (1 << SIGABRT) // Abort signal from abort(3)
|
pascal@757
|
113 - + (1 << SIGALRM) // Timer signal from alarm(2)
|
pascal@757
|
114 - + (1 << SIGVTALRM) // Virtual alarm clock
|
pascal@757
|
115 - + (1 << SIGXCPU) // CPU time limit exceeded
|
pascal@757
|
116 - + (1 << SIGXFSZ) // File size limit exceeded
|
pascal@757
|
117 - + (1 << SIGUSR1) // Yes kids, these are also fatal!
|
pascal@757
|
118 - + (1 << SIGUSR2)
|
pascal@757
|
119 - + 0,
|
pascal@757
|
120 + BB_FATAL_SIGS = (int)(0
|
pascal@757
|
121 + + (1LL << SIGHUP)
|
pascal@757
|
122 + + (1LL << SIGINT)
|
pascal@757
|
123 + + (1LL << SIGTERM)
|
pascal@757
|
124 + + (1LL << SIGPIPE) // Write to pipe with no readers
|
pascal@757
|
125 + + (1LL << SIGQUIT) // Quit from keyboard
|
pascal@757
|
126 + + (1LL << SIGABRT) // Abort signal from abort(3)
|
pascal@757
|
127 + + (1LL << SIGALRM) // Timer signal from alarm(2)
|
pascal@757
|
128 + + (1LL << SIGVTALRM) // Virtual alarm clock
|
pascal@757
|
129 + + (1LL << SIGXCPU) // CPU time limit exceeded
|
pascal@757
|
130 + + (1LL << SIGXFSZ) // File size limit exceeded
|
pascal@757
|
131 + + (1LL << SIGUSR1) // Yes kids, these are also fatal!
|
pascal@757
|
132 + + (1LL << SIGUSR2)
|
pascal@757
|
133 + + 0),
|
pascal@757
|
134 };
|
pascal@757
|
135 void bb_signals(int sigs, void (*f)(int));
|
pascal@757
|
136 /* Unlike signal() and bb_signals, sets handler with sigaction()
|
pascal@757
|
137 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-httpd.patch
|
pascal@757
|
138 --- busybox-1.10.1/networking/httpd.c Sat Apr 19 05:50:27 2008
|
pascal@757
|
139 +++ busybox-1.10.1-httpd/networking/httpd.c Wed May 7 11:19:11 2008
|
pascal@757
|
140 @@ -1457,6 +1457,11 @@
|
pascal@757
|
141 }
|
pascal@757
|
142 }
|
pascal@757
|
143 #endif
|
pascal@757
|
144 + /* restore default signal dispositions for CGI process */
|
pascal@757
|
145 + signal(SIGCHLD, SIG_DFL);
|
pascal@757
|
146 + signal(SIGPIPE, SIG_DFL);
|
pascal@757
|
147 + signal(SIGHUP, SIG_DFL);
|
pascal@757
|
148 +
|
pascal@757
|
149 execv(fullpath, argv);
|
pascal@757
|
150 if (verbose)
|
pascal@757
|
151 bb_perror_msg("exec %s", fullpath);
|
pascal@757
|
152 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-ioctl.patch
|
pascal@757
|
153 --- busybox-1.10.1/include/libbb.h Sat Apr 19 05:50:36 2008
|
pascal@757
|
154 +++ busybox-1.10.1-ioctl/include/libbb.h Thu Apr 24 06:45:03 2008
|
pascal@757
|
155 @@ -995,16 +995,16 @@
|
pascal@757
|
156 /* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
|
pascal@757
|
157 int get_terminal_width_height(int fd, int *width, int *height);
|
pascal@757
|
158
|
pascal@757
|
159 -int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
pascal@757
|
160 -void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
pascal@757
|
161 +int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
pascal@757
|
162 +void ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
pascal@757
|
163 #if ENABLE_IOCTL_HEX2STR_ERROR
|
pascal@757
|
164 -int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name);
|
pascal@757
|
165 -void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name);
|
pascal@757
|
166 +int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name);
|
pascal@757
|
167 +void bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name);
|
pascal@757
|
168 #define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request)
|
pascal@757
|
169 #define xioctl(fd,request,argp) bb_xioctl(fd,request,argp,#request)
|
pascal@757
|
170 #else
|
pascal@757
|
171 -int bb_ioctl_or_warn(int fd, int request, void *argp);
|
pascal@757
|
172 -void bb_xioctl(int fd, int request, void *argp);
|
pascal@757
|
173 +int bb_ioctl_or_warn(int fd, unsigned request, void *argp);
|
pascal@757
|
174 +void bb_xioctl(int fd, unsigned request, void *argp);
|
pascal@757
|
175 #define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
|
pascal@757
|
176 #define xioctl(fd,request,argp) bb_xioctl(fd,request,argp)
|
pascal@757
|
177 #endif
|
pascal@757
|
178 --- busybox-1.10.1/libbb/xfuncs.c Sat Apr 19 05:50:33 2008
|
pascal@757
|
179 +++ busybox-1.10.1-ioctl/libbb/xfuncs.c Thu Apr 24 06:45:14 2008
|
pascal@757
|
180 @@ -704,7 +704,7 @@
|
pascal@757
|
181 return ret;
|
pascal@757
|
182 }
|
pascal@757
|
183
|
pascal@757
|
184 -void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...)
|
pascal@757
|
185 +void ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...)
|
pascal@757
|
186 {
|
pascal@757
|
187 va_list p;
|
pascal@757
|
188
|
pascal@757
|
189 @@ -717,7 +717,7 @@
|
pascal@757
|
190 }
|
pascal@757
|
191 }
|
pascal@757
|
192
|
pascal@757
|
193 -int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...)
|
pascal@757
|
194 +int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...)
|
pascal@757
|
195 {
|
pascal@757
|
196 va_list p;
|
pascal@757
|
197 int ret = ioctl(fd, request, argp);
|
pascal@757
|
198 @@ -731,7 +731,7 @@
|
pascal@757
|
199 }
|
pascal@757
|
200
|
pascal@757
|
201 #if ENABLE_IOCTL_HEX2STR_ERROR
|
pascal@757
|
202 -int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name)
|
pascal@757
|
203 +int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name)
|
pascal@757
|
204 {
|
pascal@757
|
205 int ret;
|
pascal@757
|
206
|
pascal@757
|
207 @@ -740,13 +740,13 @@
|
pascal@757
|
208 bb_simple_perror_msg(ioctl_name);
|
pascal@757
|
209 return ret;
|
pascal@757
|
210 }
|
pascal@757
|
211 -void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name)
|
pascal@757
|
212 +void bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name)
|
pascal@757
|
213 {
|
pascal@757
|
214 if (ioctl(fd, request, argp) < 0)
|
pascal@757
|
215 bb_simple_perror_msg_and_die(ioctl_name);
|
pascal@757
|
216 }
|
pascal@757
|
217 #else
|
pascal@757
|
218 -int bb_ioctl_or_warn(int fd, int request, void *argp)
|
pascal@757
|
219 +int bb_ioctl_or_warn(int fd, unsigned request, void *argp)
|
pascal@757
|
220 {
|
pascal@757
|
221 int ret;
|
pascal@757
|
222
|
pascal@757
|
223 @@ -755,7 +755,7 @@
|
pascal@757
|
224 bb_perror_msg("ioctl %#x failed", request);
|
pascal@757
|
225 return ret;
|
pascal@757
|
226 }
|
pascal@757
|
227 -void bb_xioctl(int fd, int request, void *argp)
|
pascal@757
|
228 +void bb_xioctl(int fd, unsigned request, void *argp)
|
pascal@757
|
229 {
|
pascal@757
|
230 if (ioctl(fd, request, argp) < 0)
|
pascal@757
|
231 bb_perror_msg_and_die("ioctl %#x failed", request);
|
pascal@757
|
232 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-mdev.patch
|
pascal@757
|
233 --- busybox-1.10.1/util-linux/mdev.c Sat Apr 19 05:50:39 2008
|
pascal@757
|
234 +++ busybox-1.10.1-mdev/util-linux/mdev.c Fri May 2 14:48:06 2008
|
pascal@757
|
235 @@ -12,6 +12,8 @@
|
pascal@757
|
236 #include "libbb.h"
|
pascal@757
|
237 #include "xregex.h"
|
pascal@757
|
238
|
pascal@757
|
239 +#define ENABLE_FEATURE_MDEV_RENAME_REGEXP 1
|
pascal@757
|
240 +
|
pascal@757
|
241 struct globals {
|
pascal@757
|
242 int root_major, root_minor;
|
pascal@757
|
243 };
|
pascal@757
|
244 @@ -21,7 +23,21 @@
|
pascal@757
|
245
|
pascal@757
|
246 #define MAX_SYSFS_DEPTH 3 /* prevent infinite loops in /sys symlinks */
|
pascal@757
|
247
|
pascal@757
|
248 +/* We use additional 64+ bytes in make_device() */
|
pascal@757
|
249 +#define SCRATCH_SIZE 80
|
pascal@757
|
250 +
|
pascal@757
|
251 +static char *next_field(char *s)
|
pascal@757
|
252 +{
|
pascal@757
|
253 + char *end = skip_non_whitespace(s);
|
pascal@757
|
254 + s = skip_whitespace(end);
|
pascal@757
|
255 + *end = '\0';
|
pascal@757
|
256 + if (*s == '\0')
|
pascal@757
|
257 + s = NULL;
|
pascal@757
|
258 + return s;
|
pascal@757
|
259 +}
|
pascal@757
|
260 +
|
pascal@757
|
261 /* mknod in /dev based on a path like "/sys/block/hda/hda1" */
|
pascal@757
|
262 +/* NB: "mdev -s" may call us many times, do not leak memory/fds! */
|
pascal@757
|
263 static void make_device(char *path, int delete)
|
pascal@757
|
264 {
|
pascal@757
|
265 const char *device_name;
|
pascal@757
|
266 @@ -29,7 +45,7 @@
|
pascal@757
|
267 int mode = 0660;
|
pascal@757
|
268 uid_t uid = 0;
|
pascal@757
|
269 gid_t gid = 0;
|
pascal@757
|
270 - char *temp = path + strlen(path);
|
pascal@757
|
271 + char *dev_maj_min = path + strlen(path);
|
pascal@757
|
272 char *command = NULL;
|
pascal@757
|
273 char *alias = NULL;
|
pascal@757
|
274
|
pascal@757
|
275 @@ -42,156 +58,178 @@
|
pascal@757
|
276 * also depend on path having writeable space after it.
|
pascal@757
|
277 */
|
pascal@757
|
278 if (!delete) {
|
pascal@757
|
279 - strcat(path, "/dev");
|
pascal@757
|
280 - len = open_read_close(path, temp + 1, 64);
|
pascal@757
|
281 - *temp++ = 0;
|
pascal@757
|
282 + strcpy(dev_maj_min, "/dev");
|
pascal@757
|
283 + len = open_read_close(path, dev_maj_min + 1, 64);
|
pascal@757
|
284 + *dev_maj_min++ = '\0';
|
pascal@757
|
285 if (len < 1) {
|
pascal@757
|
286 - if (ENABLE_FEATURE_MDEV_EXEC)
|
pascal@757
|
287 - /* no "dev" file, so just try to run script */
|
pascal@757
|
288 - *temp = 0;
|
pascal@757
|
289 - else
|
pascal@757
|
290 + if (!ENABLE_FEATURE_MDEV_EXEC)
|
pascal@757
|
291 return;
|
pascal@757
|
292 + /* no "dev" file, so just try to run script */
|
pascal@757
|
293 + *dev_maj_min = '\0';
|
pascal@757
|
294 }
|
pascal@757
|
295 }
|
pascal@757
|
296
|
pascal@757
|
297 /* Determine device name, type, major and minor */
|
pascal@757
|
298 device_name = bb_basename(path);
|
pascal@757
|
299 - type = (path[5] == 'c' ? S_IFCHR : S_IFBLK);
|
pascal@757
|
300 + /* http://kernel.org/doc/pending/hotplug.txt says that only
|
pascal@757
|
301 + * "/sys/block/..." is for block devices. "sys/bus" etc is not! */
|
pascal@757
|
302 + type = (strncmp(&path[5], "block/", 6) == 0 ? S_IFBLK : S_IFCHR);
|
pascal@757
|
303
|
pascal@757
|
304 if (ENABLE_FEATURE_MDEV_CONF) {
|
pascal@757
|
305 FILE *fp;
|
pascal@757
|
306 - char *line, *vline;
|
pascal@757
|
307 + char *line, *val, *next;
|
pascal@757
|
308 unsigned lineno = 0;
|
pascal@757
|
309
|
pascal@757
|
310 - /* If we have a config file, look up the user settings */
|
pascal@757
|
311 + /* If we have config file, look up user settings */
|
pascal@757
|
312 fp = fopen_or_warn("/etc/mdev.conf", "r");
|
pascal@757
|
313 if (!fp)
|
pascal@757
|
314 goto end_parse;
|
pascal@757
|
315
|
pascal@757
|
316 - while ((vline = line = xmalloc_getline(fp)) != NULL) {
|
pascal@757
|
317 - int field;
|
pascal@757
|
318 + while ((line = xmalloc_getline(fp)) != NULL) {
|
pascal@757
|
319 + regmatch_t off[1+9*ENABLE_FEATURE_MDEV_RENAME_REGEXP];
|
pascal@757
|
320
|
pascal@757
|
321 - /* A pristine copy for command execution. */
|
pascal@757
|
322 - char *orig_line;
|
pascal@757
|
323 - if (ENABLE_FEATURE_MDEV_EXEC)
|
pascal@757
|
324 - orig_line = xstrdup(line);
|
pascal@757
|
325 -
|
pascal@757
|
326 ++lineno;
|
pascal@757
|
327 + trim(line);
|
pascal@757
|
328 + if (!line[0])
|
pascal@757
|
329 + goto next_line;
|
pascal@757
|
330
|
pascal@757
|
331 - /* Three fields: regex, uid:gid, mode */
|
pascal@757
|
332 - for (field = 0; field < (3 + ENABLE_FEATURE_MDEV_RENAME + ENABLE_FEATURE_MDEV_EXEC); ++field) {
|
pascal@757
|
333 + /* Fields: regex uid:gid mode [alias] [cmd] */
|
pascal@757
|
334
|
pascal@757
|
335 - /* Find a non-empty field */
|
pascal@757
|
336 - char *val;
|
pascal@757
|
337 - do {
|
pascal@757
|
338 - val = strtok(vline, " \t");
|
pascal@757
|
339 - vline = NULL;
|
pascal@757
|
340 - } while (val && !*val);
|
pascal@757
|
341 - if (!val) {
|
pascal@757
|
342 - if (field)
|
pascal@757
|
343 - break;
|
pascal@757
|
344 - else
|
pascal@757
|
345 - goto next_line;
|
pascal@757
|
346 - }
|
pascal@757
|
347 + /* 1st field: regex to match this device */
|
pascal@757
|
348 + next = next_field(line);
|
pascal@757
|
349 + {
|
pascal@757
|
350 + regex_t match;
|
pascal@757
|
351 + int result;
|
pascal@757
|
352
|
pascal@757
|
353 - if (field == 0) {
|
pascal@757
|
354 + /* Is this it? */
|
pascal@757
|
355 + xregcomp(&match, line, REG_EXTENDED);
|
pascal@757
|
356 + result = regexec(&match, device_name, ARRAY_SIZE(off), off, 0);
|
pascal@757
|
357 + regfree(&match);
|
pascal@757
|
358
|
pascal@757
|
359 - /* Regex to match this device */
|
pascal@757
|
360 - regex_t match;
|
pascal@757
|
361 - regmatch_t off;
|
pascal@757
|
362 - int result;
|
pascal@757
|
363 + //bb_error_msg("matches:");
|
pascal@757
|
364 + //for (int i = 0; i < ARRAY_SIZE(off); i++) {
|
pascal@757
|
365 + // if (off[i].rm_so < 0) continue;
|
pascal@757
|
366 + // bb_error_msg("match %d: '%.*s'\n", i,
|
pascal@757
|
367 + // (int)(off[i].rm_eo - off[i].rm_so),
|
pascal@757
|
368 + // device_name + off[i].rm_so);
|
pascal@757
|
369 + //}
|
pascal@757
|
370
|
pascal@757
|
371 - /* Is this it? */
|
pascal@757
|
372 - xregcomp(&match, val, REG_EXTENDED);
|
pascal@757
|
373 - result = regexec(&match, device_name, 1, &off, 0);
|
pascal@757
|
374 - regfree(&match);
|
pascal@757
|
375 + /* If not this device, skip rest of line */
|
pascal@757
|
376 + /* (regexec returns whole pattern as "range" 0) */
|
pascal@757
|
377 + if (result || off[0].rm_so || off[0].rm_eo != strlen(device_name))
|
pascal@757
|
378 + goto next_line;
|
pascal@757
|
379 + }
|
pascal@757
|
380
|
pascal@757
|
381 - /* If not this device, skip rest of line */
|
pascal@757
|
382 - if (result || off.rm_so || off.rm_eo != strlen(device_name))
|
pascal@757
|
383 - goto next_line;
|
pascal@757
|
384 + /* This line matches: stop parsing the file
|
pascal@757
|
385 + * after parsing the rest of fields */
|
pascal@757
|
386
|
pascal@757
|
387 - } else if (field == 1) {
|
pascal@757
|
388 + /* 2nd field: uid:gid - device ownership */
|
pascal@757
|
389 + if (!next) /* field must exist */
|
pascal@757
|
390 + bb_error_msg_and_die("bad line %u", lineno);
|
pascal@757
|
391 + val = next;
|
pascal@757
|
392 + next = next_field(val);
|
pascal@757
|
393 + {
|
pascal@757
|
394 + struct passwd *pass;
|
pascal@757
|
395 + struct group *grp;
|
pascal@757
|
396 + char *str_uid = val;
|
pascal@757
|
397 + char *str_gid = strchrnul(val, ':');
|
pascal@757
|
398
|
pascal@757
|
399 - /* uid:gid device ownership */
|
pascal@757
|
400 - struct passwd *pass;
|
pascal@757
|
401 - struct group *grp;
|
pascal@757
|
402 + if (*str_gid)
|
pascal@757
|
403 + *str_gid++ = '\0';
|
pascal@757
|
404 + /* Parse UID */
|
pascal@757
|
405 + pass = getpwnam(str_uid);
|
pascal@757
|
406 + if (pass)
|
pascal@757
|
407 + uid = pass->pw_uid;
|
pascal@757
|
408 + else
|
pascal@757
|
409 + uid = strtoul(str_uid, NULL, 10);
|
pascal@757
|
410 + /* Parse GID */
|
pascal@757
|
411 + grp = getgrnam(str_gid);
|
pascal@757
|
412 + if (grp)
|
pascal@757
|
413 + gid = grp->gr_gid;
|
pascal@757
|
414 + else
|
pascal@757
|
415 + gid = strtoul(str_gid, NULL, 10);
|
pascal@757
|
416 + }
|
pascal@757
|
417
|
pascal@757
|
418 - char *str_uid = val;
|
pascal@757
|
419 - char *str_gid = strchr(val, ':');
|
pascal@757
|
420 - if (str_gid)
|
pascal@757
|
421 - *str_gid = '\0', ++str_gid;
|
pascal@757
|
422 + /* 3rd field: mode - device permissions */
|
pascal@757
|
423 + if (!next) /* field must exist */
|
pascal@757
|
424 + bb_error_msg_and_die("bad line %u", lineno);
|
pascal@757
|
425 + val = next;
|
pascal@757
|
426 + next = next_field(val);
|
pascal@757
|
427 + mode = strtoul(val, NULL, 8);
|
pascal@757
|
428
|
pascal@757
|
429 - /* Parse UID */
|
pascal@757
|
430 - pass = getpwnam(str_uid);
|
pascal@757
|
431 - if (pass)
|
pascal@757
|
432 - uid = pass->pw_uid;
|
pascal@757
|
433 - else
|
pascal@757
|
434 - uid = strtoul(str_uid, NULL, 10);
|
pascal@757
|
435 + /* 4th field (opt): >alias */
|
pascal@757
|
436 + if (ENABLE_FEATURE_MDEV_RENAME) {
|
pascal@757
|
437 + if (!next)
|
pascal@757
|
438 + break;
|
pascal@757
|
439 + if (*next == '>') {
|
pascal@757
|
440 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
|
pascal@757
|
441 + char *s, *p;
|
pascal@757
|
442 + unsigned i, n;
|
pascal@757
|
443 +#endif
|
pascal@757
|
444 + val = next;
|
pascal@757
|
445 + next = next_field(val);
|
pascal@757
|
446 +#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
|
pascal@757
|
447 + /* substitute %1..9 with off[1..9], if any */
|
pascal@757
|
448 + n = 0;
|
pascal@757
|
449 + s = val;
|
pascal@757
|
450 + while (*s && *s++ == '%')
|
pascal@757
|
451 + n++;
|
pascal@757
|
452
|
pascal@757
|
453 - /* parse GID */
|
pascal@757
|
454 - grp = getgrnam(str_gid);
|
pascal@757
|
455 - if (grp)
|
pascal@757
|
456 - gid = grp->gr_gid;
|
pascal@757
|
457 - else
|
pascal@757
|
458 - gid = strtoul(str_gid, NULL, 10);
|
pascal@757
|
459 -
|
pascal@757
|
460 - } else if (field == 2) {
|
pascal@757
|
461 -
|
pascal@757
|
462 - /* Mode device permissions */
|
pascal@757
|
463 - mode = strtoul(val, NULL, 8);
|
pascal@757
|
464 -
|
pascal@757
|
465 - } else if (ENABLE_FEATURE_MDEV_RENAME && field == 3) {
|
pascal@757
|
466 -
|
pascal@757
|
467 - if (*val != '>')
|
pascal@757
|
468 - ++field;
|
pascal@757
|
469 - else
|
pascal@757
|
470 - alias = xstrdup(val + 1);
|
pascal@757
|
471 -
|
pascal@757
|
472 + p = alias = xzalloc(strlen(val) + n * strlen(device_name));
|
pascal@757
|
473 + s = val + 1;
|
pascal@757
|
474 + while (*s) {
|
pascal@757
|
475 + *p = *s;
|
pascal@757
|
476 + if ('%' == *s) {
|
pascal@757
|
477 + i = (s[1] - '0');
|
pascal@757
|
478 + if (i <= 9 && off[i].rm_so >= 0) {
|
pascal@757
|
479 + n = off[i].rm_eo - off[i].rm_so;
|
pascal@757
|
480 + strncpy(p, device_name + off[i].rm_so, n);
|
pascal@757
|
481 + p += n - 1;
|
pascal@757
|
482 + s++;
|
pascal@757
|
483 + }
|
pascal@757
|
484 + }
|
pascal@757
|
485 + p++;
|
pascal@757
|
486 + s++;
|
pascal@757
|
487 + }
|
pascal@757
|
488 +#else
|
pascal@757
|
489 + alias = xstrdup(val + 1);
|
pascal@757
|
490 +#endif
|
pascal@757
|
491 }
|
pascal@757
|
492 + }
|
pascal@757
|
493
|
pascal@757
|
494 - if (ENABLE_FEATURE_MDEV_EXEC && field == 3 + ENABLE_FEATURE_MDEV_RENAME) {
|
pascal@757
|
495 + /* The rest (opt): command to run */
|
pascal@757
|
496 + if (!next)
|
pascal@757
|
497 + break;
|
pascal@757
|
498 + val = next;
|
pascal@757
|
499 + if (ENABLE_FEATURE_MDEV_EXEC) {
|
pascal@757
|
500 + const char *s = "@$*";
|
pascal@757
|
501 + const char *s2 = strchr(s, *val);
|
pascal@757
|
502
|
pascal@757
|
503 - /* Optional command to run */
|
pascal@757
|
504 - const char *s = "@$*";
|
pascal@757
|
505 - const char *s2 = strchr(s, *val);
|
pascal@757
|
506 + if (!s2)
|
pascal@757
|
507 + bb_error_msg_and_die("bad line %u", lineno);
|
pascal@757
|
508
|
pascal@757
|
509 - if (!s2) {
|
pascal@757
|
510 - /* Force error */
|
pascal@757
|
511 - field = 1;
|
pascal@757
|
512 - break;
|
pascal@757
|
513 - }
|
pascal@757
|
514 -
|
pascal@757
|
515 - /* Correlate the position in the "@$*" with the delete
|
pascal@757
|
516 - * step so that we get the proper behavior.
|
pascal@757
|
517 - */
|
pascal@757
|
518 - if ((s2 - s + 1) & (1 << delete))
|
pascal@757
|
519 - command = xstrdup(orig_line + (val + 1 - line));
|
pascal@757
|
520 + /* Correlate the position in the "@$*" with the delete
|
pascal@757
|
521 + * step so that we get the proper behavior:
|
pascal@757
|
522 + * @cmd: run on create
|
pascal@757
|
523 + * $cmd: run on delete
|
pascal@757
|
524 + * *cmd: run on both
|
pascal@757
|
525 + */
|
pascal@757
|
526 + if ((s2 - s + 1) /*1/2/3*/ & /*1/2*/ (1 + delete)) {
|
pascal@757
|
527 + command = xstrdup(val + 1);
|
pascal@757
|
528 }
|
pascal@757
|
529 }
|
pascal@757
|
530 -
|
pascal@757
|
531 - /* Did everything parse happily? */
|
pascal@757
|
532 - if (field <= 2)
|
pascal@757
|
533 - bb_error_msg_and_die("bad line %u", lineno);
|
pascal@757
|
534 -
|
pascal@757
|
535 + /* end of field parsing */
|
pascal@757
|
536 + break; /* we found matching line, stop */
|
pascal@757
|
537 next_line:
|
pascal@757
|
538 free(line);
|
pascal@757
|
539 - if (ENABLE_FEATURE_MDEV_EXEC)
|
pascal@757
|
540 - free(orig_line);
|
pascal@757
|
541 - }
|
pascal@757
|
542 + } /* end of "while line is read from /etc/mdev.conf" */
|
pascal@757
|
543
|
pascal@757
|
544 - if (ENABLE_FEATURE_CLEAN_UP)
|
pascal@757
|
545 - fclose(fp);
|
pascal@757
|
546 -
|
pascal@757
|
547 - end_parse: /* nothing */ ;
|
pascal@757
|
548 + free(line); /* in case we used "break" to get here */
|
pascal@757
|
549 + fclose(fp);
|
pascal@757
|
550 }
|
pascal@757
|
551 + end_parse:
|
pascal@757
|
552
|
pascal@757
|
553 - if (!delete) {
|
pascal@757
|
554 - if (sscanf(temp, "%d:%d", &major, &minor) != 2) {
|
pascal@757
|
555 - if (ENABLE_FEATURE_MDEV_EXEC)
|
pascal@757
|
556 - goto skip_creation;
|
pascal@757
|
557 - else
|
pascal@757
|
558 - return;
|
pascal@757
|
559 - }
|
pascal@757
|
560 + if (!delete && sscanf(dev_maj_min, "%u:%u", &major, &minor) == 2) {
|
pascal@757
|
561
|
pascal@757
|
562 if (ENABLE_FEATURE_MDEV_RENAME)
|
pascal@757
|
563 unlink(device_name);
|
pascal@757
|
564 @@ -208,39 +246,44 @@
|
pascal@757
|
565 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
|
pascal@757
|
566 char *dest;
|
pascal@757
|
567
|
pascal@757
|
568 - temp = strrchr(alias, '/');
|
pascal@757
|
569 - if (temp) {
|
pascal@757
|
570 - if (temp[1] != '\0')
|
pascal@757
|
571 - /* given a file name, so rename it */
|
pascal@757
|
572 - *temp = '\0';
|
pascal@757
|
573 + /* ">bar/": rename to bar/device_name */
|
pascal@757
|
574 + /* ">bar[/]baz": rename to bar[/]baz */
|
pascal@757
|
575 + dest = strrchr(alias, '/');
|
pascal@757
|
576 + if (dest) { /* ">bar/[baz]" ? */
|
pascal@757
|
577 + *dest = '\0'; /* mkdir bar */
|
pascal@757
|
578 bb_make_directory(alias, 0755, FILEUTILS_RECUR);
|
pascal@757
|
579 - dest = concat_path_file(alias, device_name);
|
pascal@757
|
580 - } else
|
pascal@757
|
581 - dest = alias;
|
pascal@757
|
582 + *dest = '/';
|
pascal@757
|
583 + if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
|
pascal@757
|
584 + dest = alias;
|
pascal@757
|
585 + alias = concat_path_file(alias, device_name);
|
pascal@757
|
586 + free(dest);
|
pascal@757
|
587 + }
|
pascal@757
|
588 + }
|
pascal@757
|
589
|
pascal@757
|
590 - rename(device_name, dest); // TODO: xrename?
|
pascal@757
|
591 - symlink(dest, device_name);
|
pascal@757
|
592 + /* recreate device_name as a symlink to moved device node */
|
pascal@757
|
593 + if (rename(device_name, alias) == 0) {
|
pascal@757
|
594 + symlink(alias, device_name);
|
pascal@757
|
595 + }
|
pascal@757
|
596
|
pascal@757
|
597 - if (alias != dest)
|
pascal@757
|
598 - free(alias);
|
pascal@757
|
599 - free(dest);
|
pascal@757
|
600 + free(alias);
|
pascal@757
|
601 }
|
pascal@757
|
602 }
|
pascal@757
|
603 - skip_creation: /* nothing */ ;
|
pascal@757
|
604 }
|
pascal@757
|
605 +
|
pascal@757
|
606 if (ENABLE_FEATURE_MDEV_EXEC && command) {
|
pascal@757
|
607 - /* setenv will leak memory, so use putenv */
|
pascal@757
|
608 + /* setenv will leak memory, use putenv/unsetenv/free */
|
pascal@757
|
609 char *s = xasprintf("MDEV=%s", device_name);
|
pascal@757
|
610 putenv(s);
|
pascal@757
|
611 if (system(command) == -1)
|
pascal@757
|
612 - bb_perror_msg_and_die("cannot run %s", command);
|
pascal@757
|
613 + bb_perror_msg_and_die("can't run '%s'", command);
|
pascal@757
|
614 s[4] = '\0';
|
pascal@757
|
615 unsetenv(s);
|
pascal@757
|
616 free(s);
|
pascal@757
|
617 free(command);
|
pascal@757
|
618 }
|
pascal@757
|
619 +
|
pascal@757
|
620 if (delete)
|
pascal@757
|
621 - remove_file(device_name, FILEUTILS_FORCE);
|
pascal@757
|
622 + unlink(device_name);
|
pascal@757
|
623 }
|
pascal@757
|
624
|
pascal@757
|
625 /* File callback for /sys/ traversal */
|
pascal@757
|
626 @@ -249,14 +292,15 @@
|
pascal@757
|
627 void *userData,
|
pascal@757
|
628 int depth ATTRIBUTE_UNUSED)
|
pascal@757
|
629 {
|
pascal@757
|
630 - size_t len = strlen(fileName) - 4;
|
pascal@757
|
631 + size_t len = strlen(fileName) - 4; /* can't underflow */
|
pascal@757
|
632 char *scratch = userData;
|
pascal@757
|
633
|
pascal@757
|
634 - if (strcmp(fileName + len, "/dev"))
|
pascal@757
|
635 + /* len check is for paranoid reasons */
|
pascal@757
|
636 + if (strcmp(fileName + len, "/dev") || len >= PATH_MAX)
|
pascal@757
|
637 return FALSE;
|
pascal@757
|
638
|
pascal@757
|
639 strcpy(scratch, fileName);
|
pascal@757
|
640 - scratch[len] = 0;
|
pascal@757
|
641 + scratch[len] = '\0';
|
pascal@757
|
642 make_device(scratch, 0);
|
pascal@757
|
643
|
pascal@757
|
644 return TRUE;
|
pascal@757
|
645 @@ -287,12 +331,6 @@
|
pascal@757
|
646 int cnt;
|
pascal@757
|
647 int firmware_fd, loading_fd, data_fd;
|
pascal@757
|
648
|
pascal@757
|
649 - /* check for $FIRMWARE from kernel */
|
pascal@757
|
650 - /* XXX: dont bother: open(NULL) works same as open("no-such-file")
|
pascal@757
|
651 - * if (!firmware)
|
pascal@757
|
652 - * return;
|
pascal@757
|
653 - */
|
pascal@757
|
654 -
|
pascal@757
|
655 /* check for /lib/firmware/$FIRMWARE */
|
pascal@757
|
656 xchdir("/lib/firmware");
|
pascal@757
|
657 firmware_fd = xopen(firmware, O_RDONLY);
|
pascal@757
|
658 @@ -304,16 +342,15 @@
|
pascal@757
|
659 xchdir(sysfs_path);
|
pascal@757
|
660 for (cnt = 0; cnt < 30; ++cnt) {
|
pascal@757
|
661 loading_fd = open("loading", O_WRONLY);
|
pascal@757
|
662 - if (loading_fd == -1)
|
pascal@757
|
663 - sleep(1);
|
pascal@757
|
664 - else
|
pascal@757
|
665 - break;
|
pascal@757
|
666 + if (loading_fd != -1)
|
pascal@757
|
667 + goto loading;
|
pascal@757
|
668 + sleep(1);
|
pascal@757
|
669 }
|
pascal@757
|
670 - if (loading_fd == -1)
|
pascal@757
|
671 - goto out;
|
pascal@757
|
672 + goto out;
|
pascal@757
|
673
|
pascal@757
|
674 + loading:
|
pascal@757
|
675 /* tell kernel we're loading by `echo 1 > /sys/$DEVPATH/loading` */
|
pascal@757
|
676 - if (write(loading_fd, "1", 1) != 1)
|
pascal@757
|
677 + if (full_write(loading_fd, "1", 1) != 1)
|
pascal@757
|
678 goto out;
|
pascal@757
|
679
|
pascal@757
|
680 /* load firmware by `cat /lib/firmware/$FIRMWARE > /sys/$DEVPATH/data */
|
pascal@757
|
681 @@ -324,9 +361,9 @@
|
pascal@757
|
682
|
pascal@757
|
683 /* tell kernel result by `echo [0|-1] > /sys/$DEVPATH/loading` */
|
pascal@757
|
684 if (cnt > 0)
|
pascal@757
|
685 - write(loading_fd, "0", 1);
|
pascal@757
|
686 + full_write(loading_fd, "0", 1);
|
pascal@757
|
687 else
|
pascal@757
|
688 - write(loading_fd, "-1", 2);
|
pascal@757
|
689 + full_write(loading_fd, "-1", 2);
|
pascal@757
|
690
|
pascal@757
|
691 out:
|
pascal@757
|
692 if (ENABLE_FEATURE_CLEAN_UP) {
|
pascal@757
|
693 @@ -341,16 +378,14 @@
|
pascal@757
|
694 {
|
pascal@757
|
695 char *action;
|
pascal@757
|
696 char *env_path;
|
pascal@757
|
697 - RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
|
pascal@757
|
698 + RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
|
pascal@757
|
699
|
pascal@757
|
700 xchdir("/dev");
|
pascal@757
|
701
|
pascal@757
|
702 - if (argc == 2 && !strcmp(argv[1],"-s")) {
|
pascal@757
|
703 -
|
pascal@757
|
704 + if (argc == 2 && !strcmp(argv[1], "-s")) {
|
pascal@757
|
705 /* Scan:
|
pascal@757
|
706 * mdev -s
|
pascal@757
|
707 */
|
pascal@757
|
708 -
|
pascal@757
|
709 struct stat st;
|
pascal@757
|
710
|
pascal@757
|
711 xstat("/", &st);
|
pascal@757
|
712 @@ -366,26 +401,27 @@
|
pascal@757
|
713 fileAction, dirAction, temp, 0);
|
pascal@757
|
714
|
pascal@757
|
715 } else {
|
pascal@757
|
716 -
|
pascal@757
|
717 /* Hotplug:
|
pascal@757
|
718 * env ACTION=... DEVPATH=... mdev
|
pascal@757
|
719 * ACTION can be "add" or "remove"
|
pascal@757
|
720 * DEVPATH is like "/block/sda" or "/class/input/mice"
|
pascal@757
|
721 */
|
pascal@757
|
722 -
|
pascal@757
|
723 action = getenv("ACTION");
|
pascal@757
|
724 env_path = getenv("DEVPATH");
|
pascal@757
|
725 if (!action || !env_path)
|
pascal@757
|
726 bb_show_usage();
|
pascal@757
|
727
|
pascal@757
|
728 - sprintf(temp, "/sys%s", env_path);
|
pascal@757
|
729 + snprintf(temp, PATH_MAX, "/sys%s", env_path);
|
pascal@757
|
730 if (!strcmp(action, "remove"))
|
pascal@757
|
731 make_device(temp, 1);
|
pascal@757
|
732 else if (!strcmp(action, "add")) {
|
pascal@757
|
733 make_device(temp, 0);
|
pascal@757
|
734
|
pascal@757
|
735 - if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE)
|
pascal@757
|
736 - load_firmware(getenv("FIRMWARE"), temp);
|
pascal@757
|
737 + if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) {
|
pascal@757
|
738 + char *fw = getenv("FIRMWARE");
|
pascal@757
|
739 + if (fw)
|
pascal@757
|
740 + load_firmware(fw, temp);
|
pascal@757
|
741 + }
|
pascal@757
|
742 }
|
pascal@757
|
743 }
|
pascal@757
|
744
|
pascal@757
|
745 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-pidof.patch
|
pascal@757
|
746 --- busybox-1.10.1/libbb/procps.c Sat Apr 19 05:50:33 2008
|
pascal@757
|
747 +++ busybox-1.10.1-pidof/libbb/procps.c Sat Apr 26 01:18:32 2008
|
pascal@757
|
748 @@ -258,7 +258,7 @@
|
pascal@757
|
749 &sp->start_time,
|
pascal@757
|
750 &vsz,
|
pascal@757
|
751 &rss);
|
pascal@757
|
752 - if (n != 10)
|
pascal@757
|
753 + if (n != 11)
|
pascal@757
|
754 break;
|
pascal@757
|
755 /* vsz is in bytes and we want kb */
|
pascal@757
|
756 sp->vsz = vsz >> 10;
|
pascal@757
|
757 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-ssd.patch
|
pascal@757
|
758 --- busybox-1.10.1/debianutils/start_stop_daemon.c Sat Apr 19 05:50:30 2008
|
pascal@757
|
759 +++ busybox-1.10.1-ssd/debianutils/start_stop_daemon.c Tue Apr 22 03:13:13 2008
|
pascal@757
|
760 @@ -11,7 +11,6 @@
|
pascal@757
|
761 /* NB: we have a problem here with /proc/NN/exe usage, similar to
|
pascal@757
|
762 * one fixed in killall/pidof */
|
pascal@757
|
763
|
pascal@757
|
764 -#include <getopt.h>
|
pascal@757
|
765 #include <sys/resource.h>
|
pascal@757
|
766
|
pascal@757
|
767 /* Override ENABLE_FEATURE_PIDFILE */
|
pascal@757
|
768 @@ -33,6 +32,7 @@
|
pascal@757
|
769 int user_id;
|
pascal@757
|
770 smallint quiet;
|
pascal@757
|
771 smallint signal_nr;
|
pascal@757
|
772 + struct stat execstat;
|
pascal@757
|
773 };
|
pascal@757
|
774 #define G (*(struct globals*)&bb_common_bufsiz1)
|
pascal@757
|
775 #define found (G.found )
|
pascal@757
|
776 @@ -43,6 +43,7 @@
|
pascal@757
|
777 #define user_id (G.user_id )
|
pascal@757
|
778 #define quiet (G.quiet )
|
pascal@757
|
779 #define signal_nr (G.signal_nr )
|
pascal@757
|
780 +#define execstat (G.execstat )
|
pascal@757
|
781 #define INIT_G() \
|
pascal@757
|
782 do { \
|
pascal@757
|
783 user_id = -1; \
|
pascal@757
|
784 @@ -50,25 +51,21 @@
|
pascal@757
|
785 } while (0)
|
pascal@757
|
786
|
pascal@757
|
787
|
pascal@757
|
788 -static int pid_is_exec(pid_t pid, const char *name)
|
pascal@757
|
789 +static int pid_is_exec(pid_t pid)
|
pascal@757
|
790 {
|
pascal@757
|
791 + struct stat st;
|
pascal@757
|
792 char buf[sizeof("/proc//exe") + sizeof(int)*3];
|
pascal@757
|
793 - char *execbuf;
|
pascal@757
|
794 - int n;
|
pascal@757
|
795
|
pascal@757
|
796 sprintf(buf, "/proc/%u/exe", pid);
|
pascal@757
|
797 - n = strlen(name) + 1;
|
pascal@757
|
798 - execbuf = xzalloc(n + 1);
|
pascal@757
|
799 - readlink(buf, execbuf, n);
|
pascal@757
|
800 - /* if readlink fails because link target is longer than strlen(name),
|
pascal@757
|
801 - * execbuf still contains "", and strcmp will return !0. */
|
pascal@757
|
802 - n = strcmp(execbuf, name);
|
pascal@757
|
803 - if (ENABLE_FEATURE_CLEAN_UP)
|
pascal@757
|
804 - free(execbuf);
|
pascal@757
|
805 - return !n; /* nonzero (true) if execbuf == name */
|
pascal@757
|
806 + if (stat(buf, &st) < 0)
|
pascal@757
|
807 + return 0;
|
pascal@757
|
808 + if (st.st_dev == execstat.st_dev
|
pascal@757
|
809 + && st.st_ino == execstat.st_ino)
|
pascal@757
|
810 + return 1;
|
pascal@757
|
811 + return 0;
|
pascal@757
|
812 }
|
pascal@757
|
813
|
pascal@757
|
814 -static int pid_is_user(int pid, int uid)
|
pascal@757
|
815 +static int pid_is_user(int pid)
|
pascal@757
|
816 {
|
pascal@757
|
817 struct stat sb;
|
pascal@757
|
818 char buf[sizeof("/proc/") + sizeof(int)*3];
|
pascal@757
|
819 @@ -76,42 +73,39 @@
|
pascal@757
|
820 sprintf(buf, "/proc/%u", pid);
|
pascal@757
|
821 if (stat(buf, &sb) != 0)
|
pascal@757
|
822 return 0;
|
pascal@757
|
823 - return (sb.st_uid == uid);
|
pascal@757
|
824 + return (sb.st_uid == user_id);
|
pascal@757
|
825 }
|
pascal@757
|
826
|
pascal@757
|
827 -static int pid_is_cmd(pid_t pid, const char *name)
|
pascal@757
|
828 +static int pid_is_cmd(pid_t pid)
|
pascal@757
|
829 {
|
pascal@757
|
830 - char fname[sizeof("/proc//stat") + sizeof(int)*3];
|
pascal@757
|
831 - char *buf;
|
pascal@757
|
832 - int r = 0;
|
pascal@757
|
833 + char buf[256]; /* is it big enough? */
|
pascal@757
|
834 + char *p, *pe;
|
pascal@757
|
835
|
pascal@757
|
836 - sprintf(fname, "/proc/%u/stat", pid);
|
pascal@757
|
837 - buf = xmalloc_open_read_close(fname, NULL);
|
pascal@757
|
838 - if (buf) {
|
pascal@757
|
839 - char *p = strchr(buf, '(');
|
pascal@757
|
840 - if (p) {
|
pascal@757
|
841 - char *pe = strrchr(++p, ')');
|
pascal@757
|
842 - if (pe) {
|
pascal@757
|
843 - *pe = '\0';
|
pascal@757
|
844 - r = !strcmp(p, name);
|
pascal@757
|
845 - }
|
pascal@757
|
846 - }
|
pascal@757
|
847 - free(buf);
|
pascal@757
|
848 - }
|
pascal@757
|
849 - return r;
|
pascal@757
|
850 + sprintf(buf, "/proc/%u/stat", pid);
|
pascal@757
|
851 + if (open_read_close(buf, buf, sizeof(buf) - 1) < 0)
|
pascal@757
|
852 + return 0;
|
pascal@757
|
853 + buf[sizeof(buf) - 1] = '\0'; /* paranoia */
|
pascal@757
|
854 + p = strchr(buf, '(');
|
pascal@757
|
855 + if (!p)
|
pascal@757
|
856 + return 0;
|
pascal@757
|
857 + pe = strrchr(++p, ')');
|
pascal@757
|
858 + if (!pe)
|
pascal@757
|
859 + return 0;
|
pascal@757
|
860 + *pe = '\0';
|
pascal@757
|
861 + return !strcmp(p, cmdname);
|
pascal@757
|
862 }
|
pascal@757
|
863
|
pascal@757
|
864 static void check(int pid)
|
pascal@757
|
865 {
|
pascal@757
|
866 struct pid_list *p;
|
pascal@757
|
867
|
pascal@757
|
868 - if (execname && !pid_is_exec(pid, execname)) {
|
pascal@757
|
869 + if (execname && !pid_is_exec(pid)) {
|
pascal@757
|
870 return;
|
pascal@757
|
871 }
|
pascal@757
|
872 - if (userspec && !pid_is_user(pid, user_id)) {
|
pascal@757
|
873 + if (userspec && !pid_is_user(pid)) {
|
pascal@757
|
874 return;
|
pascal@757
|
875 }
|
pascal@757
|
876 - if (cmdname && !pid_is_cmd(pid, cmdname)) {
|
pascal@757
|
877 + if (cmdname && !pid_is_cmd(pid)) {
|
pascal@757
|
878 return;
|
pascal@757
|
879 }
|
pascal@757
|
880 p = xmalloc(sizeof(*p));
|
pascal@757
|
881 @@ -148,9 +142,16 @@
|
pascal@757
|
882 procdir = xopendir("/proc");
|
pascal@757
|
883
|
pascal@757
|
884 pid = 0;
|
pascal@757
|
885 - while ((entry = readdir(procdir)) != NULL) {
|
pascal@757
|
886 + while(1) {
|
pascal@757
|
887 + errno = 0; /* clear any previous error */
|
pascal@757
|
888 + entry = readdir(procdir);
|
pascal@757
|
889 +// TODO: check for exact errno(s) which mean that we got stale entry
|
pascal@757
|
890 + if (errno) /* Stale entry, process has died after opendir */
|
pascal@757
|
891 + continue;
|
pascal@757
|
892 + if (!entry) /* EOF, no more entries */
|
pascal@757
|
893 + break;
|
pascal@757
|
894 pid = bb_strtou(entry->d_name, NULL, 10);
|
pascal@757
|
895 - if (errno)
|
pascal@757
|
896 + if (errno) /* NaN */
|
pascal@757
|
897 continue;
|
pascal@757
|
898 check(pid);
|
pascal@757
|
899 }
|
pascal@757
|
900 @@ -165,8 +166,6 @@
|
pascal@757
|
901 struct pid_list *p;
|
pascal@757
|
902 int killed = 0;
|
pascal@757
|
903
|
pascal@757
|
904 - do_procinit();
|
pascal@757
|
905 -
|
pascal@757
|
906 if (cmdname) {
|
pascal@757
|
907 if (ENABLE_FEATURE_CLEAN_UP) what = xstrdup(cmdname);
|
pascal@757
|
908 if (!ENABLE_FEATURE_CLEAN_UP) what = cmdname;
|
pascal@757
|
909 @@ -251,7 +250,7 @@
|
pascal@757
|
910 };
|
pascal@757
|
911
|
pascal@757
|
912 int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
pascal@757
|
913 -int start_stop_daemon_main(int argc, char **argv)
|
pascal@757
|
914 +int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
pascal@757
|
915 {
|
pascal@757
|
916 unsigned opt;
|
pascal@757
|
917 char *signame;
|
pascal@757
|
918 @@ -293,7 +292,7 @@
|
pascal@757
|
919 // if (retry_arg)
|
pascal@757
|
920 // retries = xatoi_u(retry_arg);
|
pascal@757
|
921 // )
|
pascal@757
|
922 - argc -= optind;
|
pascal@757
|
923 + //argc -= optind;
|
pascal@757
|
924 argv += optind;
|
pascal@757
|
925
|
pascal@757
|
926 if (userspec) {
|
pascal@757
|
927 @@ -301,13 +300,15 @@
|
pascal@757
|
928 if (errno)
|
pascal@757
|
929 user_id = xuname2uid(userspec);
|
pascal@757
|
930 }
|
pascal@757
|
931 + if (execname)
|
pascal@757
|
932 + xstat(execname, &execstat);
|
pascal@757
|
933
|
pascal@757
|
934 + do_procinit(); /* Both start and stop needs to know current processes */
|
pascal@757
|
935 +
|
pascal@757
|
936 if (opt & CTX_STOP) {
|
pascal@757
|
937 int i = do_stop();
|
pascal@757
|
938 return (opt & OPT_OKNODO) ? 0 : (i <= 0);
|
pascal@757
|
939 }
|
pascal@757
|
940 -
|
pascal@757
|
941 - do_procinit();
|
pascal@757
|
942
|
pascal@757
|
943 if (found) {
|
pascal@757
|
944 if (!quiet)
|
pascal@757
|
945 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-taskset.patch
|
pascal@757
|
946 --- busybox-1.10.1/miscutils/taskset.c Sat Apr 19 06:03:13 2008
|
pascal@757
|
947 +++ busybox-1.10.1-taskset/miscutils/taskset.c Fri Apr 25 18:58:53 2008
|
pascal@757
|
948 @@ -94,8 +94,10 @@
|
pascal@757
|
949 unsigned i;
|
pascal@757
|
950 /* Do not allow zero mask: */
|
pascal@757
|
951 unsigned long long m = xstrtoull_range(aff, 0, 1, ULLONG_MAX);
|
pascal@757
|
952 + enum { CNT_BIT = CPU_SETSIZE < sizeof(m)*8 ? CPU_SETSIZE : sizeof(m)*8 };
|
pascal@757
|
953 +
|
pascal@757
|
954 CPU_ZERO(&mask);
|
pascal@757
|
955 - for (i = 0; i < CPU_SETSIZE; i++) {
|
pascal@757
|
956 + for (i = 0; i < CNT_BIT; i++) {
|
pascal@757
|
957 unsigned long long bit = (1ULL << i);
|
pascal@757
|
958 if (bit & m)
|
pascal@757
|
959 CPU_SET(i, &mask);
|
pascal@757
|
960 http://busybox.net/downloads/fixes-1.10.1/busybox-1.10.1-trylink.patch
|
pascal@757
|
961 --- busybox-1.10.1/scripts/trylink Sat Apr 19 05:50:27 2008
|
pascal@757
|
962 +++ busybox-1.10.1-trylink/scripts/trylink Wed Apr 30 02:10:19 2008
|
pascal@757
|
963 @@ -66,7 +66,7 @@
|
pascal@757
|
964 #if defined(__GLIBC__) && !defined(__UCLIBC__)
|
pascal@757
|
965 syntax error here
|
pascal@757
|
966 #endif
|
pascal@757
|
967 - " >"$tempname"
|
pascal@757
|
968 + " >"$tempname".c
|
pascal@757
|
969 if $CC "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then
|
pascal@757
|
970 echo "$2";
|
pascal@757
|
971 else
|