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