aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-05-08 15:26:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-05-08 15:26:06 +0000
commita3087ca7495e33b19b122869d17defeb9c933d19 (patch)
treefa652fe429d78c0b2fad2c42c52c98e92bb3288d
parent0abe9d96eee3bcdcdd766a863eb711ec004f2f4f (diff)
downloadbusybox-w32-a3087ca7495e33b19b122869d17defeb9c933d19.tar.gz
busybox-w32-a3087ca7495e33b19b122869d17defeb9c933d19.tar.bz2
busybox-w32-a3087ca7495e33b19b122869d17defeb9c933d19.zip
Apply post-1.10.1 patches
Bump version to 1.10.2
-rw-r--r--Makefile2
-rw-r--r--archival/libunarchive/get_header_tar.c5
-rw-r--r--coreutils/echo.c16
-rw-r--r--debianutils/start_stop_daemon.c91
-rw-r--r--include/libbb.h40
-rw-r--r--libbb/lineedit.c19
-rw-r--r--libbb/procps.c2
-rw-r--r--libbb/xfuncs.c12
-rw-r--r--miscutils/taskset.c4
-rw-r--r--networking/httpd.c5
-rwxr-xr-xscripts/trylink2
-rw-r--r--util-linux/mdev.c366
12 files changed, 308 insertions, 256 deletions
diff --git a/Makefile b/Makefile
index e18726fca..4feab0e6c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
1VERSION = 1 1VERSION = 1
2PATCHLEVEL = 10 2PATCHLEVEL = 10
3SUBLEVEL = 1 3SUBLEVEL = 2
4EXTRAVERSION = 4EXTRAVERSION =
5NAME = Unnamed 5NAME = Unnamed
6 6
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index 54c8f7665..b1a797a08 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -112,7 +112,7 @@ char get_header_tar(archive_handle_t *archive_handle)
112 archive_handle->offset += 512; 112 archive_handle->offset += 512;
113 113
114 /* If there is no filename its an empty header */ 114 /* If there is no filename its an empty header */
115 if (tar.name[0] == 0) { 115 if (tar.name[0] == 0 && tar.prefix[0] == 0) {
116 if (end) { 116 if (end) {
117 /* This is the second consecutive empty header! End of archive! 117 /* This is the second consecutive empty header! End of archive!
118 * Read until the end to empty the pipe from gz or bz2 118 * Read until the end to empty the pipe from gz or bz2
@@ -211,9 +211,12 @@ char get_header_tar(archive_handle_t *archive_handle)
211 /* getOctal trashes subsequent field, therefore we call it 211 /* getOctal trashes subsequent field, therefore we call it
212 * on fields in reverse order */ 212 * on fields in reverse order */
213 if (tar.devmajor[0]) { 213 if (tar.devmajor[0]) {
214 char t = tar.prefix[0];
215 /* we trash prefix[0] here, but we DO need it later! */
214 unsigned minor = GET_OCTAL(tar.devminor); 216 unsigned minor = GET_OCTAL(tar.devminor);
215 unsigned major = GET_OCTAL(tar.devmajor); 217 unsigned major = GET_OCTAL(tar.devmajor);
216 file_header->device = makedev(major, minor); 218 file_header->device = makedev(major, minor);
219 tar.prefix[0] = t;
217 } 220 }
218 file_header->link_target = NULL; 221 file_header->link_target = NULL;
219 if (!linkname && parse_names && tar.linkname[0]) { 222 if (!linkname && parse_names && tar.linkname[0]) {
diff --git a/coreutils/echo.c b/coreutils/echo.c
index fd6c950ea..cc9b9e6f4 100644
--- a/coreutils/echo.c
+++ b/coreutils/echo.c
@@ -27,10 +27,8 @@
27 27
28/* This is a NOFORK applet. Be very careful! */ 28/* This is a NOFORK applet. Be very careful! */
29 29
30/* argc is unused, but removing it precludes compiler from 30/* NB: can be used by shell even if not enabled as applet */
31 * using call -> jump optimization */
32 31
33int echo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34int echo_main(int argc ATTRIBUTE_UNUSED, char **argv) 32int echo_main(int argc ATTRIBUTE_UNUSED, char **argv)
35{ 33{
36 const char *arg; 34 const char *arg;
@@ -110,15 +108,19 @@ int echo_main(int argc ATTRIBUTE_UNUSED, char **argv)
110 } 108 }
111#if !ENABLE_FEATURE_FANCY_ECHO 109#if !ENABLE_FEATURE_FANCY_ECHO
112 /* SUSv3 specifies that octal escapes must begin with '0'. */ 110 /* SUSv3 specifies that octal escapes must begin with '0'. */
113 if ( (((unsigned char)*arg) - '1') >= 7) 111 if ( ((int)(unsigned char)(*arg) - '0') >= 8) /* '8' or bigger */
114#endif 112#endif
115 { 113 {
116 /* Since SUSv3 mandates a first digit of 0, 4-digit octals 114 /* Since SUSv3 mandates a first digit of 0, 4-digit octals
117 * of the form \0### are accepted. */ 115 * of the form \0### are accepted. */
118 if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) { 116 if (*arg == '0') {
119 arg++; 117 /* NB: don't turn "...\0" into "...\" */
118 if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) {
119 arg++;
120 }
120 } 121 }
121 /* bb_process_escape_sequence can handle nul correctly */ 122 /* bb_process_escape_sequence handles NUL correctly
123 * ("...\" case). */
122 c = bb_process_escape_sequence(&arg); 124 c = bb_process_escape_sequence(&arg);
123 } 125 }
124 } 126 }
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 6f4b6b2bb..4e816bd19 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -11,7 +11,6 @@
11/* NB: we have a problem here with /proc/NN/exe usage, similar to 11/* NB: we have a problem here with /proc/NN/exe usage, similar to
12 * one fixed in killall/pidof */ 12 * one fixed in killall/pidof */
13 13
14#include <getopt.h>
15#include <sys/resource.h> 14#include <sys/resource.h>
16 15
17/* Override ENABLE_FEATURE_PIDFILE */ 16/* Override ENABLE_FEATURE_PIDFILE */
@@ -33,6 +32,7 @@ struct globals {
33 int user_id; 32 int user_id;
34 smallint quiet; 33 smallint quiet;
35 smallint signal_nr; 34 smallint signal_nr;
35 struct stat execstat;
36}; 36};
37#define G (*(struct globals*)&bb_common_bufsiz1) 37#define G (*(struct globals*)&bb_common_bufsiz1)
38#define found (G.found ) 38#define found (G.found )
@@ -43,6 +43,7 @@ struct globals {
43#define user_id (G.user_id ) 43#define user_id (G.user_id )
44#define quiet (G.quiet ) 44#define quiet (G.quiet )
45#define signal_nr (G.signal_nr ) 45#define signal_nr (G.signal_nr )
46#define execstat (G.execstat )
46#define INIT_G() \ 47#define INIT_G() \
47 do { \ 48 do { \
48 user_id = -1; \ 49 user_id = -1; \
@@ -50,25 +51,21 @@ struct globals {
50 } while (0) 51 } while (0)
51 52
52 53
53static int pid_is_exec(pid_t pid, const char *name) 54static int pid_is_exec(pid_t pid)
54{ 55{
56 struct stat st;
55 char buf[sizeof("/proc//exe") + sizeof(int)*3]; 57 char buf[sizeof("/proc//exe") + sizeof(int)*3];
56 char *execbuf;
57 int n;
58 58
59 sprintf(buf, "/proc/%u/exe", pid); 59 sprintf(buf, "/proc/%u/exe", pid);
60 n = strlen(name) + 1; 60 if (stat(buf, &st) < 0)
61 execbuf = xzalloc(n + 1); 61 return 0;
62 readlink(buf, execbuf, n); 62 if (st.st_dev == execstat.st_dev
63 /* if readlink fails because link target is longer than strlen(name), 63 && st.st_ino == execstat.st_ino)
64 * execbuf still contains "", and strcmp will return !0. */ 64 return 1;
65 n = strcmp(execbuf, name); 65 return 0;
66 if (ENABLE_FEATURE_CLEAN_UP)
67 free(execbuf);
68 return !n; /* nonzero (true) if execbuf == name */
69} 66}
70 67
71static int pid_is_user(int pid, int uid) 68static int pid_is_user(int pid)
72{ 69{
73 struct stat sb; 70 struct stat sb;
74 char buf[sizeof("/proc/") + sizeof(int)*3]; 71 char buf[sizeof("/proc/") + sizeof(int)*3];
@@ -76,42 +73,39 @@ static int pid_is_user(int pid, int uid)
76 sprintf(buf, "/proc/%u", pid); 73 sprintf(buf, "/proc/%u", pid);
77 if (stat(buf, &sb) != 0) 74 if (stat(buf, &sb) != 0)
78 return 0; 75 return 0;
79 return (sb.st_uid == uid); 76 return (sb.st_uid == user_id);
80} 77}
81 78
82static int pid_is_cmd(pid_t pid, const char *name) 79static int pid_is_cmd(pid_t pid)
83{ 80{
84 char fname[sizeof("/proc//stat") + sizeof(int)*3]; 81 char buf[256]; /* is it big enough? */
85 char *buf; 82 char *p, *pe;
86 int r = 0; 83
87 84 sprintf(buf, "/proc/%u/stat", pid);
88 sprintf(fname, "/proc/%u/stat", pid); 85 if (open_read_close(buf, buf, sizeof(buf) - 1) < 0)
89 buf = xmalloc_open_read_close(fname, NULL); 86 return 0;
90 if (buf) { 87 buf[sizeof(buf) - 1] = '\0'; /* paranoia */
91 char *p = strchr(buf, '('); 88 p = strchr(buf, '(');
92 if (p) { 89 if (!p)
93 char *pe = strrchr(++p, ')'); 90 return 0;
94 if (pe) { 91 pe = strrchr(++p, ')');
95 *pe = '\0'; 92 if (!pe)
96 r = !strcmp(p, name); 93 return 0;
97 } 94 *pe = '\0';
98 } 95 return !strcmp(p, cmdname);
99 free(buf);
100 }
101 return r;
102} 96}
103 97
104static void check(int pid) 98static void check(int pid)
105{ 99{
106 struct pid_list *p; 100 struct pid_list *p;
107 101
108 if (execname && !pid_is_exec(pid, execname)) { 102 if (execname && !pid_is_exec(pid)) {
109 return; 103 return;
110 } 104 }
111 if (userspec && !pid_is_user(pid, user_id)) { 105 if (userspec && !pid_is_user(pid)) {
112 return; 106 return;
113 } 107 }
114 if (cmdname && !pid_is_cmd(pid, cmdname)) { 108 if (cmdname && !pid_is_cmd(pid)) {
115 return; 109 return;
116 } 110 }
117 p = xmalloc(sizeof(*p)); 111 p = xmalloc(sizeof(*p));
@@ -148,9 +142,16 @@ static void do_procinit(void)
148 procdir = xopendir("/proc"); 142 procdir = xopendir("/proc");
149 143
150 pid = 0; 144 pid = 0;
151 while ((entry = readdir(procdir)) != NULL) { 145 while(1) {
146 errno = 0; /* clear any previous error */
147 entry = readdir(procdir);
148// TODO: check for exact errno(s) which mean that we got stale entry
149 if (errno) /* Stale entry, process has died after opendir */
150 continue;
151 if (!entry) /* EOF, no more entries */
152 break;
152 pid = bb_strtou(entry->d_name, NULL, 10); 153 pid = bb_strtou(entry->d_name, NULL, 10);
153 if (errno) 154 if (errno) /* NaN */
154 continue; 155 continue;
155 check(pid); 156 check(pid);
156 } 157 }
@@ -165,8 +166,6 @@ static int do_stop(void)
165 struct pid_list *p; 166 struct pid_list *p;
166 int killed = 0; 167 int killed = 0;
167 168
168 do_procinit();
169
170 if (cmdname) { 169 if (cmdname) {
171 if (ENABLE_FEATURE_CLEAN_UP) what = xstrdup(cmdname); 170 if (ENABLE_FEATURE_CLEAN_UP) what = xstrdup(cmdname);
172 if (!ENABLE_FEATURE_CLEAN_UP) what = cmdname; 171 if (!ENABLE_FEATURE_CLEAN_UP) what = cmdname;
@@ -251,7 +250,7 @@ enum {
251}; 250};
252 251
253int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 252int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
254int start_stop_daemon_main(int argc, char **argv) 253int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
255{ 254{
256 unsigned opt; 255 unsigned opt;
257 char *signame; 256 char *signame;
@@ -293,7 +292,7 @@ int start_stop_daemon_main(int argc, char **argv)
293// if (retry_arg) 292// if (retry_arg)
294// retries = xatoi_u(retry_arg); 293// retries = xatoi_u(retry_arg);
295// ) 294// )
296 argc -= optind; 295 //argc -= optind;
297 argv += optind; 296 argv += optind;
298 297
299 if (userspec) { 298 if (userspec) {
@@ -301,14 +300,16 @@ int start_stop_daemon_main(int argc, char **argv)
301 if (errno) 300 if (errno)
302 user_id = xuname2uid(userspec); 301 user_id = xuname2uid(userspec);
303 } 302 }
303 if (execname)
304 xstat(execname, &execstat);
305
306 do_procinit(); /* Both start and stop needs to know current processes */
304 307
305 if (opt & CTX_STOP) { 308 if (opt & CTX_STOP) {
306 int i = do_stop(); 309 int i = do_stop();
307 return (opt & OPT_OKNODO) ? 0 : (i <= 0); 310 return (opt & OPT_OKNODO) ? 0 : (i <= 0);
308 } 311 }
309 312
310 do_procinit();
311
312 if (found) { 313 if (found) {
313 if (!quiet) 314 if (!quiet)
314 printf("%s already running\n%d\n", execname, found->pid); 315 printf("%s already running\n%d\n", execname, found->pid);
diff --git a/include/libbb.h b/include/libbb.h
index 9f208b390..859b3bcf4 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -288,20 +288,20 @@ enum {
288 * SIGSYS Bad argument to routine 288 * SIGSYS Bad argument to routine
289 * SIGTRAP Trace/breakpoint trap 289 * SIGTRAP Trace/breakpoint trap
290 */ 290 */
291 BB_FATAL_SIGS = 0 291 BB_FATAL_SIGS = (int)(0
292 + (1 << SIGHUP) 292 + (1LL << SIGHUP)
293 + (1 << SIGINT) 293 + (1LL << SIGINT)
294 + (1 << SIGTERM) 294 + (1LL << SIGTERM)
295 + (1 << SIGPIPE) // Write to pipe with no readers 295 + (1LL << SIGPIPE) // Write to pipe with no readers
296 + (1 << SIGQUIT) // Quit from keyboard 296 + (1LL << SIGQUIT) // Quit from keyboard
297 + (1 << SIGABRT) // Abort signal from abort(3) 297 + (1LL << SIGABRT) // Abort signal from abort(3)
298 + (1 << SIGALRM) // Timer signal from alarm(2) 298 + (1LL << SIGALRM) // Timer signal from alarm(2)
299 + (1 << SIGVTALRM) // Virtual alarm clock 299 + (1LL << SIGVTALRM) // Virtual alarm clock
300 + (1 << SIGXCPU) // CPU time limit exceeded 300 + (1LL << SIGXCPU) // CPU time limit exceeded
301 + (1 << SIGXFSZ) // File size limit exceeded 301 + (1LL << SIGXFSZ) // File size limit exceeded
302 + (1 << SIGUSR1) // Yes kids, these are also fatal! 302 + (1LL << SIGUSR1) // Yes kids, these are also fatal!
303 + (1 << SIGUSR2) 303 + (1LL << SIGUSR2)
304 + 0, 304 + 0),
305}; 305};
306void bb_signals(int sigs, void (*f)(int)); 306void bb_signals(int sigs, void (*f)(int));
307/* Unlike signal() and bb_signals, sets handler with sigaction() 307/* Unlike signal() and bb_signals, sets handler with sigaction()
@@ -995,16 +995,16 @@ extern int update_passwd(const char *filename, const char *username,
995/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */ 995/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
996int get_terminal_width_height(int fd, int *width, int *height); 996int get_terminal_width_height(int fd, int *width, int *height);
997 997
998int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); 998int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
999void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); 999void ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
1000#if ENABLE_IOCTL_HEX2STR_ERROR 1000#if ENABLE_IOCTL_HEX2STR_ERROR
1001int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name); 1001int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name);
1002void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name); 1002void bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name);
1003#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request) 1003#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request)
1004#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp,#request) 1004#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp,#request)
1005#else 1005#else
1006int bb_ioctl_or_warn(int fd, int request, void *argp); 1006int bb_ioctl_or_warn(int fd, unsigned request, void *argp);
1007void bb_xioctl(int fd, int request, void *argp); 1007void bb_xioctl(int fd, unsigned request, void *argp);
1008#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp) 1008#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
1009#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp) 1009#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp)
1010#endif 1010#endif
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index b25386bc0..b05319a9d 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -518,8 +518,8 @@ static void exe_n_cwd_tab_completion(char *command, int type)
518 518
519 for (i = 0; i < npaths; i++) { 519 for (i = 0; i < npaths; i++) {
520 dir = opendir(paths[i]); 520 dir = opendir(paths[i]);
521 if (!dir) /* Don't print an error */ 521 if (!dir)
522 continue; 522 continue; /* don't print an error */
523 523
524 while ((next = readdir(dir)) != NULL) { 524 while ((next = readdir(dir)) != NULL) {
525 int len1; 525 int len1;
@@ -529,18 +529,21 @@ static void exe_n_cwd_tab_completion(char *command, int type)
529 if (strncmp(str_found, pfind, strlen(pfind))) 529 if (strncmp(str_found, pfind, strlen(pfind)))
530 continue; 530 continue;
531 /* not see .name without .match */ 531 /* not see .name without .match */
532 if (*str_found == '.' && *pfind == 0) { 532 if (*str_found == '.' && *pfind == '\0') {
533 if (NOT_LONE_CHAR(paths[i], '/') || str_found[1]) 533 if (NOT_LONE_CHAR(paths[i], '/') || str_found[1])
534 continue; 534 continue;
535 str_found = ""; /* only "/" */ 535 str_found = ""; /* only "/" */
536 } 536 }
537 found = concat_path_file(paths[i], str_found); 537 found = concat_path_file(paths[i], str_found);
538 /* hmm, remover in progress? */ 538 /* hmm, remove in progress? */
539 if (lstat(found, &st) < 0) 539 /* NB: stat() first so that we see is it a directory;
540 * but if that fails, use lstat() so that
541 * we still match dangling links */
542 if (stat(found, &st) && lstat(found, &st))
540 goto cont; 543 goto cont;
541 /* find with dirs? */ 544 /* find with dirs? */
542 if (paths[i] != dirbuf) 545 if (paths[i] != dirbuf)
543 strcpy(found, next->d_name); /* only name */ 546 strcpy(found, next->d_name); /* only name */
544 547
545 len1 = strlen(found); 548 len1 = strlen(found);
546 found = xrealloc(found, len1 + 2); 549 found = xrealloc(found, len1 + 2);
@@ -548,7 +551,7 @@ static void exe_n_cwd_tab_completion(char *command, int type)
548 found[len1+1] = '\0'; 551 found[len1+1] = '\0';
549 552
550 if (S_ISDIR(st.st_mode)) { 553 if (S_ISDIR(st.st_mode)) {
551 /* name is directory */ 554 /* name is a directory */
552 if (found[len1-1] != '/') { 555 if (found[len1-1] != '/') {
553 found[len1] = '/'; 556 found[len1] = '/';
554 } 557 }
@@ -566,7 +569,7 @@ static void exe_n_cwd_tab_completion(char *command, int type)
566 closedir(dir); 569 closedir(dir);
567 } 570 }
568 if (paths != path1) { 571 if (paths != path1) {
569 free(paths[0]); /* allocated memory only in first member */ 572 free(paths[0]); /* allocated memory is only in first member */
570 free(paths); 573 free(paths);
571 } 574 }
572#undef dirbuf 575#undef dirbuf
diff --git a/libbb/procps.c b/libbb/procps.c
index f67f7dcde..8946917a2 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -258,7 +258,7 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags)
258 &sp->start_time, 258 &sp->start_time,
259 &vsz, 259 &vsz,
260 &rss); 260 &rss);
261 if (n != 10) 261 if (n != 11)
262 break; 262 break;
263 /* vsz is in bytes and we want kb */ 263 /* vsz is in bytes and we want kb */
264 sp->vsz = vsz >> 10; 264 sp->vsz = vsz >> 10;
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index ca7f94173..84b9f922b 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -704,7 +704,7 @@ int get_terminal_width_height(int fd, int *width, int *height)
704 return ret; 704 return ret;
705} 705}
706 706
707void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) 707void ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...)
708{ 708{
709 va_list p; 709 va_list p;
710 710
@@ -717,7 +717,7 @@ void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,..
717 } 717 }
718} 718}
719 719
720int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) 720int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...)
721{ 721{
722 va_list p; 722 va_list p;
723 int ret = ioctl(fd, request, argp); 723 int ret = ioctl(fd, request, argp);
@@ -731,7 +731,7 @@ int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...)
731} 731}
732 732
733#if ENABLE_IOCTL_HEX2STR_ERROR 733#if ENABLE_IOCTL_HEX2STR_ERROR
734int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name) 734int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name)
735{ 735{
736 int ret; 736 int ret;
737 737
@@ -740,13 +740,13 @@ int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name)
740 bb_simple_perror_msg(ioctl_name); 740 bb_simple_perror_msg(ioctl_name);
741 return ret; 741 return ret;
742} 742}
743void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name) 743void bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name)
744{ 744{
745 if (ioctl(fd, request, argp) < 0) 745 if (ioctl(fd, request, argp) < 0)
746 bb_simple_perror_msg_and_die(ioctl_name); 746 bb_simple_perror_msg_and_die(ioctl_name);
747} 747}
748#else 748#else
749int bb_ioctl_or_warn(int fd, int request, void *argp) 749int bb_ioctl_or_warn(int fd, unsigned request, void *argp)
750{ 750{
751 int ret; 751 int ret;
752 752
@@ -755,7 +755,7 @@ int bb_ioctl_or_warn(int fd, int request, void *argp)
755 bb_perror_msg("ioctl %#x failed", request); 755 bb_perror_msg("ioctl %#x failed", request);
756 return ret; 756 return ret;
757} 757}
758void bb_xioctl(int fd, int request, void *argp) 758void bb_xioctl(int fd, unsigned request, void *argp)
759{ 759{
760 if (ioctl(fd, request, argp) < 0) 760 if (ioctl(fd, request, argp) < 0)
761 bb_perror_msg_and_die("ioctl %#x failed", request); 761 bb_perror_msg_and_die("ioctl %#x failed", request);
diff --git a/miscutils/taskset.c b/miscutils/taskset.c
index bf98ea15d..f23b7ffc6 100644
--- a/miscutils/taskset.c
+++ b/miscutils/taskset.c
@@ -94,8 +94,10 @@ int taskset_main(int argc ATTRIBUTE_UNUSED, char **argv)
94 unsigned i; 94 unsigned i;
95 /* Do not allow zero mask: */ 95 /* Do not allow zero mask: */
96 unsigned long long m = xstrtoull_range(aff, 0, 1, ULLONG_MAX); 96 unsigned long long m = xstrtoull_range(aff, 0, 1, ULLONG_MAX);
97 enum { CNT_BIT = CPU_SETSIZE < sizeof(m)*8 ? CPU_SETSIZE : sizeof(m)*8 };
98
97 CPU_ZERO(&mask); 99 CPU_ZERO(&mask);
98 for (i = 0; i < CPU_SETSIZE; i++) { 100 for (i = 0; i < CNT_BIT; i++) {
99 unsigned long long bit = (1ULL << i); 101 unsigned long long bit = (1ULL << i);
100 if (bit & m) 102 if (bit & m)
101 CPU_SET(i, &mask); 103 CPU_SET(i, &mask);
diff --git a/networking/httpd.c b/networking/httpd.c
index 5e6037cbe..2c5455bf7 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1457,6 +1457,11 @@ static void send_cgi_and_exit(
1457 } 1457 }
1458 } 1458 }
1459#endif 1459#endif
1460 /* restore default signal dispositions for CGI process */
1461 signal(SIGCHLD, SIG_DFL);
1462 signal(SIGPIPE, SIG_DFL);
1463 signal(SIGHUP, SIG_DFL);
1464
1460 execv(fullpath, argv); 1465 execv(fullpath, argv);
1461 if (verbose) 1466 if (verbose)
1462 bb_perror_msg("exec %s", fullpath); 1467 bb_perror_msg("exec %s", fullpath);
diff --git a/scripts/trylink b/scripts/trylink
index 89e36b7e9..2322fbac6 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -66,7 +66,7 @@ check_libc_is_glibc() {
66 #if defined(__GLIBC__) && !defined(__UCLIBC__) 66 #if defined(__GLIBC__) && !defined(__UCLIBC__)
67 syntax error here 67 syntax error here
68 #endif 68 #endif
69 " >"$tempname" 69 " >"$tempname".c
70 if $CC "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then 70 if $CC "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then
71 echo "$2"; 71 echo "$2";
72 else 72 else
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 0edaf1047..f0a885482 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -12,6 +12,8 @@
12#include "libbb.h" 12#include "libbb.h"
13#include "xregex.h" 13#include "xregex.h"
14 14
15#define ENABLE_FEATURE_MDEV_RENAME_REGEXP 1
16
15struct globals { 17struct globals {
16 int root_major, root_minor; 18 int root_major, root_minor;
17}; 19};
@@ -21,7 +23,21 @@ struct globals {
21 23
22#define MAX_SYSFS_DEPTH 3 /* prevent infinite loops in /sys symlinks */ 24#define MAX_SYSFS_DEPTH 3 /* prevent infinite loops in /sys symlinks */
23 25
26/* We use additional 64+ bytes in make_device() */
27#define SCRATCH_SIZE 80
28
29static char *next_field(char *s)
30{
31 char *end = skip_non_whitespace(s);
32 s = skip_whitespace(end);
33 *end = '\0';
34 if (*s == '\0')
35 s = NULL;
36 return s;
37}
38
24/* mknod in /dev based on a path like "/sys/block/hda/hda1" */ 39/* mknod in /dev based on a path like "/sys/block/hda/hda1" */
40/* NB: "mdev -s" may call us many times, do not leak memory/fds! */
25static void make_device(char *path, int delete) 41static void make_device(char *path, int delete)
26{ 42{
27 const char *device_name; 43 const char *device_name;
@@ -29,7 +45,7 @@ static void make_device(char *path, int delete)
29 int mode = 0660; 45 int mode = 0660;
30 uid_t uid = 0; 46 uid_t uid = 0;
31 gid_t gid = 0; 47 gid_t gid = 0;
32 char *temp = path + strlen(path); 48 char *dev_maj_min = path + strlen(path);
33 char *command = NULL; 49 char *command = NULL;
34 char *alias = NULL; 50 char *alias = NULL;
35 51
@@ -42,156 +58,178 @@ static void make_device(char *path, int delete)
42 * also depend on path having writeable space after it. 58 * also depend on path having writeable space after it.
43 */ 59 */
44 if (!delete) { 60 if (!delete) {
45 strcat(path, "/dev"); 61 strcpy(dev_maj_min, "/dev");
46 len = open_read_close(path, temp + 1, 64); 62 len = open_read_close(path, dev_maj_min + 1, 64);
47 *temp++ = 0; 63 *dev_maj_min++ = '\0';
48 if (len < 1) { 64 if (len < 1) {
49 if (ENABLE_FEATURE_MDEV_EXEC) 65 if (!ENABLE_FEATURE_MDEV_EXEC)
50 /* no "dev" file, so just try to run script */
51 *temp = 0;
52 else
53 return; 66 return;
67 /* no "dev" file, so just try to run script */
68 *dev_maj_min = '\0';
54 } 69 }
55 } 70 }
56 71
57 /* Determine device name, type, major and minor */ 72 /* Determine device name, type, major and minor */
58 device_name = bb_basename(path); 73 device_name = bb_basename(path);
59 type = (path[5] == 'c' ? S_IFCHR : S_IFBLK); 74 /* http://kernel.org/doc/pending/hotplug.txt says that only
75 * "/sys/block/..." is for block devices. "sys/bus" etc is not! */
76 type = (strncmp(&path[5], "block/", 6) == 0 ? S_IFBLK : S_IFCHR);
60 77
61 if (ENABLE_FEATURE_MDEV_CONF) { 78 if (ENABLE_FEATURE_MDEV_CONF) {
62 FILE *fp; 79 FILE *fp;
63 char *line, *vline; 80 char *line, *val, *next;
64 unsigned lineno = 0; 81 unsigned lineno = 0;
65 82
66 /* If we have a config file, look up the user settings */ 83 /* If we have config file, look up user settings */
67 fp = fopen_or_warn("/etc/mdev.conf", "r"); 84 fp = fopen_or_warn("/etc/mdev.conf", "r");
68 if (!fp) 85 if (!fp)
69 goto end_parse; 86 goto end_parse;
70 87
71 while ((vline = line = xmalloc_getline(fp)) != NULL) { 88 while ((line = xmalloc_getline(fp)) != NULL) {
72 int field; 89 regmatch_t off[1+9*ENABLE_FEATURE_MDEV_RENAME_REGEXP];
73
74 /* A pristine copy for command execution. */
75 char *orig_line;
76 if (ENABLE_FEATURE_MDEV_EXEC)
77 orig_line = xstrdup(line);
78 90
79 ++lineno; 91 ++lineno;
92 trim(line);
93 if (!line[0])
94 goto next_line;
95
96 /* Fields: regex uid:gid mode [alias] [cmd] */
97
98 /* 1st field: regex to match this device */
99 next = next_field(line);
100 {
101 regex_t match;
102 int result;
103
104 /* Is this it? */
105 xregcomp(&match, line, REG_EXTENDED);
106 result = regexec(&match, device_name, ARRAY_SIZE(off), off, 0);
107 regfree(&match);
108
109 //bb_error_msg("matches:");
110 //for (int i = 0; i < ARRAY_SIZE(off); i++) {
111 // if (off[i].rm_so < 0) continue;
112 // bb_error_msg("match %d: '%.*s'\n", i,
113 // (int)(off[i].rm_eo - off[i].rm_so),
114 // device_name + off[i].rm_so);
115 //}
116
117 /* If not this device, skip rest of line */
118 /* (regexec returns whole pattern as "range" 0) */
119 if (result || off[0].rm_so || off[0].rm_eo != strlen(device_name))
120 goto next_line;
121 }
80 122
81 /* Three fields: regex, uid:gid, mode */ 123 /* This line matches: stop parsing the file
82 for (field = 0; field < (3 + ENABLE_FEATURE_MDEV_RENAME + ENABLE_FEATURE_MDEV_EXEC); ++field) { 124 * after parsing the rest of fields */
83
84 /* Find a non-empty field */
85 char *val;
86 do {
87 val = strtok(vline, " \t");
88 vline = NULL;
89 } while (val && !*val);
90 if (!val) {
91 if (field)
92 break;
93 else
94 goto next_line;
95 }
96
97 if (field == 0) {
98
99 /* Regex to match this device */
100 regex_t match;
101 regmatch_t off;
102 int result;
103
104 /* Is this it? */
105 xregcomp(&match, val, REG_EXTENDED);
106 result = regexec(&match, device_name, 1, &off, 0);
107 regfree(&match);
108
109 /* If not this device, skip rest of line */
110 if (result || off.rm_so || off.rm_eo != strlen(device_name))
111 goto next_line;
112
113 } else if (field == 1) {
114
115 /* uid:gid device ownership */
116 struct passwd *pass;
117 struct group *grp;
118
119 char *str_uid = val;
120 char *str_gid = strchr(val, ':');
121 if (str_gid)
122 *str_gid = '\0', ++str_gid;
123
124 /* Parse UID */
125 pass = getpwnam(str_uid);
126 if (pass)
127 uid = pass->pw_uid;
128 else
129 uid = strtoul(str_uid, NULL, 10);
130
131 /* parse GID */
132 grp = getgrnam(str_gid);
133 if (grp)
134 gid = grp->gr_gid;
135 else
136 gid = strtoul(str_gid, NULL, 10);
137
138 } else if (field == 2) {
139
140 /* Mode device permissions */
141 mode = strtoul(val, NULL, 8);
142
143 } else if (ENABLE_FEATURE_MDEV_RENAME && field == 3) {
144
145 if (*val != '>')
146 ++field;
147 else
148 alias = xstrdup(val + 1);
149
150 }
151
152 if (ENABLE_FEATURE_MDEV_EXEC && field == 3 + ENABLE_FEATURE_MDEV_RENAME) {
153 125
154 /* Optional command to run */ 126 /* 2nd field: uid:gid - device ownership */
155 const char *s = "@$*"; 127 if (!next) /* field must exist */
156 const char *s2 = strchr(s, *val); 128 bb_error_msg_and_die("bad line %u", lineno);
129 val = next;
130 next = next_field(val);
131 {
132 struct passwd *pass;
133 struct group *grp;
134 char *str_uid = val;
135 char *str_gid = strchrnul(val, ':');
136
137 if (*str_gid)
138 *str_gid++ = '\0';
139 /* Parse UID */
140 pass = getpwnam(str_uid);
141 if (pass)
142 uid = pass->pw_uid;
143 else
144 uid = strtoul(str_uid, NULL, 10);
145 /* Parse GID */
146 grp = getgrnam(str_gid);
147 if (grp)
148 gid = grp->gr_gid;
149 else
150 gid = strtoul(str_gid, NULL, 10);
151 }
157 152
158 if (!s2) { 153 /* 3rd field: mode - device permissions */
159 /* Force error */ 154 if (!next) /* field must exist */
160 field = 1; 155 bb_error_msg_and_die("bad line %u", lineno);
161 break; 156 val = next;
157 next = next_field(val);
158 mode = strtoul(val, NULL, 8);
159
160 /* 4th field (opt): >alias */
161 if (ENABLE_FEATURE_MDEV_RENAME) {
162 if (!next)
163 break;
164 if (*next == '>') {
165#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
166 char *s, *p;
167 unsigned i, n;
168#endif
169 val = next;
170 next = next_field(val);
171#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
172 /* substitute %1..9 with off[1..9], if any */
173 n = 0;
174 s = val;
175 while (*s && *s++ == '%')
176 n++;
177
178 p = alias = xzalloc(strlen(val) + n * strlen(device_name));
179 s = val + 1;
180 while (*s) {
181 *p = *s;
182 if ('%' == *s) {
183 i = (s[1] - '0');
184 if (i <= 9 && off[i].rm_so >= 0) {
185 n = off[i].rm_eo - off[i].rm_so;
186 strncpy(p, device_name + off[i].rm_so, n);
187 p += n - 1;
188 s++;
189 }
190 }
191 p++;
192 s++;
162 } 193 }
163 194#else
164 /* Correlate the position in the "@$*" with the delete 195 alias = xstrdup(val + 1);
165 * step so that we get the proper behavior. 196#endif
166 */
167 if ((s2 - s + 1) & (1 << delete))
168 command = xstrdup(orig_line + (val + 1 - line));
169 } 197 }
170 } 198 }
171 199
172 /* Did everything parse happily? */ 200 /* The rest (opt): command to run */
173 if (field <= 2) 201 if (!next)
174 bb_error_msg_and_die("bad line %u", lineno); 202 break;
175 203 val = next;
204 if (ENABLE_FEATURE_MDEV_EXEC) {
205 const char *s = "@$*";
206 const char *s2 = strchr(s, *val);
207
208 if (!s2)
209 bb_error_msg_and_die("bad line %u", lineno);
210
211 /* Correlate the position in the "@$*" with the delete
212 * step so that we get the proper behavior:
213 * @cmd: run on create
214 * $cmd: run on delete
215 * *cmd: run on both
216 */
217 if ((s2 - s + 1) /*1/2/3*/ & /*1/2*/ (1 + delete)) {
218 command = xstrdup(val + 1);
219 }
220 }
221 /* end of field parsing */
222 break; /* we found matching line, stop */
176 next_line: 223 next_line:
177 free(line); 224 free(line);
178 if (ENABLE_FEATURE_MDEV_EXEC) 225 } /* end of "while line is read from /etc/mdev.conf" */
179 free(orig_line);
180 }
181
182 if (ENABLE_FEATURE_CLEAN_UP)
183 fclose(fp);
184 226
185 end_parse: /* nothing */ ; 227 free(line); /* in case we used "break" to get here */
228 fclose(fp);
186 } 229 }
230 end_parse:
187 231
188 if (!delete) { 232 if (!delete && sscanf(dev_maj_min, "%u:%u", &major, &minor) == 2) {
189 if (sscanf(temp, "%d:%d", &major, &minor) != 2) {
190 if (ENABLE_FEATURE_MDEV_EXEC)
191 goto skip_creation;
192 else
193 return;
194 }
195 233
196 if (ENABLE_FEATURE_MDEV_RENAME) 234 if (ENABLE_FEATURE_MDEV_RENAME)
197 unlink(device_name); 235 unlink(device_name);
@@ -208,39 +246,44 @@ static void make_device(char *path, int delete)
208 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 246 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
209 char *dest; 247 char *dest;
210 248
211 temp = strrchr(alias, '/'); 249 /* ">bar/": rename to bar/device_name */
212 if (temp) { 250 /* ">bar[/]baz": rename to bar[/]baz */
213 if (temp[1] != '\0') 251 dest = strrchr(alias, '/');
214 /* given a file name, so rename it */ 252 if (dest) { /* ">bar/[baz]" ? */
215 *temp = '\0'; 253 *dest = '\0'; /* mkdir bar */
216 bb_make_directory(alias, 0755, FILEUTILS_RECUR); 254 bb_make_directory(alias, 0755, FILEUTILS_RECUR);
217 dest = concat_path_file(alias, device_name); 255 *dest = '/';
218 } else 256 if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
219 dest = alias; 257 dest = alias;
258 alias = concat_path_file(alias, device_name);
259 free(dest);
260 }
261 }
220 262
221 rename(device_name, dest); // TODO: xrename? 263 /* recreate device_name as a symlink to moved device node */
222 symlink(dest, device_name); 264 if (rename(device_name, alias) == 0) {
265 symlink(alias, device_name);
266 }
223 267
224 if (alias != dest) 268 free(alias);
225 free(alias);
226 free(dest);
227 } 269 }
228 } 270 }
229 skip_creation: /* nothing */ ;
230 } 271 }
272
231 if (ENABLE_FEATURE_MDEV_EXEC && command) { 273 if (ENABLE_FEATURE_MDEV_EXEC && command) {
232 /* setenv will leak memory, so use putenv */ 274 /* setenv will leak memory, use putenv/unsetenv/free */
233 char *s = xasprintf("MDEV=%s", device_name); 275 char *s = xasprintf("MDEV=%s", device_name);
234 putenv(s); 276 putenv(s);
235 if (system(command) == -1) 277 if (system(command) == -1)
236 bb_perror_msg_and_die("cannot run %s", command); 278 bb_perror_msg_and_die("can't run '%s'", command);
237 s[4] = '\0'; 279 s[4] = '\0';
238 unsetenv(s); 280 unsetenv(s);
239 free(s); 281 free(s);
240 free(command); 282 free(command);
241 } 283 }
284
242 if (delete) 285 if (delete)
243 remove_file(device_name, FILEUTILS_FORCE); 286 unlink(device_name);
244} 287}
245 288
246/* File callback for /sys/ traversal */ 289/* File callback for /sys/ traversal */
@@ -249,14 +292,15 @@ static int fileAction(const char *fileName,
249 void *userData, 292 void *userData,
250 int depth ATTRIBUTE_UNUSED) 293 int depth ATTRIBUTE_UNUSED)
251{ 294{
252 size_t len = strlen(fileName) - 4; 295 size_t len = strlen(fileName) - 4; /* can't underflow */
253 char *scratch = userData; 296 char *scratch = userData;
254 297
255 if (strcmp(fileName + len, "/dev")) 298 /* len check is for paranoid reasons */
299 if (strcmp(fileName + len, "/dev") || len >= PATH_MAX)
256 return FALSE; 300 return FALSE;
257 301
258 strcpy(scratch, fileName); 302 strcpy(scratch, fileName);
259 scratch[len] = 0; 303 scratch[len] = '\0';
260 make_device(scratch, 0); 304 make_device(scratch, 0);
261 305
262 return TRUE; 306 return TRUE;
@@ -287,12 +331,6 @@ static void load_firmware(const char *const firmware, const char *const sysfs_pa
287 int cnt; 331 int cnt;
288 int firmware_fd, loading_fd, data_fd; 332 int firmware_fd, loading_fd, data_fd;
289 333
290 /* check for $FIRMWARE from kernel */
291 /* XXX: dont bother: open(NULL) works same as open("no-such-file")
292 * if (!firmware)
293 * return;
294 */
295
296 /* check for /lib/firmware/$FIRMWARE */ 334 /* check for /lib/firmware/$FIRMWARE */
297 xchdir("/lib/firmware"); 335 xchdir("/lib/firmware");
298 firmware_fd = xopen(firmware, O_RDONLY); 336 firmware_fd = xopen(firmware, O_RDONLY);
@@ -304,16 +342,15 @@ static void load_firmware(const char *const firmware, const char *const sysfs_pa
304 xchdir(sysfs_path); 342 xchdir(sysfs_path);
305 for (cnt = 0; cnt < 30; ++cnt) { 343 for (cnt = 0; cnt < 30; ++cnt) {
306 loading_fd = open("loading", O_WRONLY); 344 loading_fd = open("loading", O_WRONLY);
307 if (loading_fd == -1) 345 if (loading_fd != -1)
308 sleep(1); 346 goto loading;
309 else 347 sleep(1);
310 break;
311 } 348 }
312 if (loading_fd == -1) 349 goto out;
313 goto out;
314 350
351 loading:
315 /* tell kernel we're loading by `echo 1 > /sys/$DEVPATH/loading` */ 352 /* tell kernel we're loading by `echo 1 > /sys/$DEVPATH/loading` */
316 if (write(loading_fd, "1", 1) != 1) 353 if (full_write(loading_fd, "1", 1) != 1)
317 goto out; 354 goto out;
318 355
319 /* load firmware by `cat /lib/firmware/$FIRMWARE > /sys/$DEVPATH/data */ 356 /* load firmware by `cat /lib/firmware/$FIRMWARE > /sys/$DEVPATH/data */
@@ -324,9 +361,9 @@ static void load_firmware(const char *const firmware, const char *const sysfs_pa
324 361
325 /* tell kernel result by `echo [0|-1] > /sys/$DEVPATH/loading` */ 362 /* tell kernel result by `echo [0|-1] > /sys/$DEVPATH/loading` */
326 if (cnt > 0) 363 if (cnt > 0)
327 write(loading_fd, "0", 1); 364 full_write(loading_fd, "0", 1);
328 else 365 else
329 write(loading_fd, "-1", 2); 366 full_write(loading_fd, "-1", 2);
330 367
331 out: 368 out:
332 if (ENABLE_FEATURE_CLEAN_UP) { 369 if (ENABLE_FEATURE_CLEAN_UP) {
@@ -341,16 +378,14 @@ int mdev_main(int argc, char **argv)
341{ 378{
342 char *action; 379 char *action;
343 char *env_path; 380 char *env_path;
344 RESERVE_CONFIG_BUFFER(temp,PATH_MAX); 381 RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
345 382
346 xchdir("/dev"); 383 xchdir("/dev");
347 384
348 if (argc == 2 && !strcmp(argv[1],"-s")) { 385 if (argc == 2 && !strcmp(argv[1], "-s")) {
349
350 /* Scan: 386 /* Scan:
351 * mdev -s 387 * mdev -s
352 */ 388 */
353
354 struct stat st; 389 struct stat st;
355 390
356 xstat("/", &st); 391 xstat("/", &st);
@@ -366,26 +401,27 @@ int mdev_main(int argc, char **argv)
366 fileAction, dirAction, temp, 0); 401 fileAction, dirAction, temp, 0);
367 402
368 } else { 403 } else {
369
370 /* Hotplug: 404 /* Hotplug:
371 * env ACTION=... DEVPATH=... mdev 405 * env ACTION=... DEVPATH=... mdev
372 * ACTION can be "add" or "remove" 406 * ACTION can be "add" or "remove"
373 * DEVPATH is like "/block/sda" or "/class/input/mice" 407 * DEVPATH is like "/block/sda" or "/class/input/mice"
374 */ 408 */
375
376 action = getenv("ACTION"); 409 action = getenv("ACTION");
377 env_path = getenv("DEVPATH"); 410 env_path = getenv("DEVPATH");
378 if (!action || !env_path) 411 if (!action || !env_path)
379 bb_show_usage(); 412 bb_show_usage();
380 413
381 sprintf(temp, "/sys%s", env_path); 414 snprintf(temp, PATH_MAX, "/sys%s", env_path);
382 if (!strcmp(action, "remove")) 415 if (!strcmp(action, "remove"))
383 make_device(temp, 1); 416 make_device(temp, 1);
384 else if (!strcmp(action, "add")) { 417 else if (!strcmp(action, "add")) {
385 make_device(temp, 0); 418 make_device(temp, 0);
386 419
387 if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) 420 if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) {
388 load_firmware(getenv("FIRMWARE"), temp); 421 char *fw = getenv("FIRMWARE");
422 if (fw)
423 load_firmware(fw, temp);
424 }
389 } 425 }
390 } 426 }
391 427