diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-25 23:21:05 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-25 23:21:05 +0000 |
commit | cad04ef4f3435e56181a81c896912543be34ea3c (patch) | |
tree | 71e46e02914c97077eaa77e12a726b29240b27f6 | |
parent | 10f8f5f4433a88b9cf9048d38a45838aa6e2abf6 (diff) | |
download | busybox-w32-cad04ef4f3435e56181a81c896912543be34ea3c.tar.gz busybox-w32-cad04ef4f3435e56181a81c896912543be34ea3c.tar.bz2 busybox-w32-cad04ef4f3435e56181a81c896912543be34ea3c.zip |
add NOMMU fixme's; move move_fd from runit_lib to libbb; nuke fd_copy
-rw-r--r-- | console-tools/openvt.c | 3 | ||||
-rw-r--r-- | e2fsprogs/fsck.c | 3 | ||||
-rw-r--r-- | include/libbb.h | 8 | ||||
-rw-r--r-- | libbb/xfuncs.c | 10 | ||||
-rw-r--r-- | loginutils/login.c | 2 | ||||
-rw-r--r-- | networking/zcip.c | 1 | ||||
-rw-r--r-- | runit/runit_lib.c | 28 | ||||
-rw-r--r-- | runit/runit_lib.h | 6 | ||||
-rw-r--r-- | runit/runsv.c | 6 | ||||
-rw-r--r-- | runit/runsvdir.c | 2 | ||||
-rw-r--r-- | runit/svlogd.c | 14 |
11 files changed, 31 insertions, 52 deletions
diff --git a/console-tools/openvt.c b/console-tools/openvt.c index eb9f49fe2..0584584df 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c | |||
@@ -22,8 +22,9 @@ int openvt_main(int argc, char **argv) | |||
22 | bb_show_usage(); | 22 | bb_show_usage(); |
23 | } | 23 | } |
24 | /* check for illegal vt number: < 1 or > 63 */ | 24 | /* check for illegal vt number: < 1 or > 63 */ |
25 | sprintf(vtname, VC_FORMAT, (int)xatoul_range(argv[1], 1, 63)); | 25 | sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63)); |
26 | 26 | ||
27 | //FIXME NOMMU | ||
27 | if (fork() == 0) { | 28 | if (fork() == 0) { |
28 | /* child */ | 29 | /* child */ |
29 | /* leave current vt (controlling tty) */ | 30 | /* leave current vt (controlling tty) */ |
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index ad22fcd7a..c31ab3f1a 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
@@ -667,7 +667,8 @@ static void execute(const char *type, const char *device, const char *mntpt, | |||
667 | /* Fork and execute the correct program. */ | 667 | /* Fork and execute the correct program. */ |
668 | pid = -1; | 668 | pid = -1; |
669 | if (!noexecute) { | 669 | if (!noexecute) { |
670 | pid = fork(); /* TODO: NOMMU friendly way (vfork)? */ | 670 | /* TODO: NOMMU friendly way (vfork)? */ |
671 | pid = fork(); | ||
671 | if (pid < 0) | 672 | if (pid < 0) |
672 | bb_perror_msg_and_die("fork"); | 673 | bb_perror_msg_and_die("fork"); |
673 | if (pid == 0) { | 674 | if (pid == 0) { |
diff --git a/include/libbb.h b/include/libbb.h index 152b87099..aba9316d1 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -250,8 +250,10 @@ extern char bb_process_escape_sequence(const char **ptr); | |||
250 | /* TODO: sometimes modifies its parameter, which | 250 | /* TODO: sometimes modifies its parameter, which |
251 | * makes it rather inconvenient at times: */ | 251 | * makes it rather inconvenient at times: */ |
252 | extern char *bb_get_last_path_component(char *path); | 252 | extern char *bb_get_last_path_component(char *path); |
253 | extern int ndelay_on(int fd); | 253 | |
254 | extern int ndelay_off(int fd); | 254 | int ndelay_on(int fd); |
255 | int ndelay_off(int fd); | ||
256 | void xmove_fd(int, int); | ||
255 | 257 | ||
256 | 258 | ||
257 | extern DIR *xopendir(const char *path); | 259 | extern DIR *xopendir(const char *path); |
@@ -616,6 +618,8 @@ extern int index_in_substr_array(const char * const string_array[], const char * | |||
616 | extern void print_login_issue(const char *issue_file, const char *tty); | 618 | extern void print_login_issue(const char *issue_file, const char *tty); |
617 | extern void print_login_prompt(void); | 619 | extern void print_login_prompt(void); |
618 | #ifdef BB_NOMMU | 620 | #ifdef BB_NOMMU |
621 | extern pid_t BUG_fork_is_unavailable_on_nommu(void); | ||
622 | #define fork() BUG_fork_is_unavailable_on_nommu() | ||
619 | extern void vfork_daemon_rexec(int nochdir, int noclose, char **argv); | 623 | extern void vfork_daemon_rexec(int nochdir, int noclose, char **argv); |
620 | extern smallint re_execed; | 624 | extern smallint re_execed; |
621 | #endif | 625 | #endif |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index c496f9a22..1dcdbc065 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -133,6 +133,16 @@ int ndelay_off(int fd) | |||
133 | return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); | 133 | return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); |
134 | } | 134 | } |
135 | 135 | ||
136 | // "Renumber" opened fd | ||
137 | void xmove_fd(int from, int to) | ||
138 | { | ||
139 | if (from == to) | ||
140 | return; | ||
141 | if (dup2(from, to) != to) | ||
142 | bb_perror_msg_and_die("cannot duplicate file descriptor"); | ||
143 | close(from); | ||
144 | } | ||
145 | |||
136 | // Die with an error message if we can't write the entire buffer. | 146 | // Die with an error message if we can't write the entire buffer. |
137 | void xwrite(int fd, const void *buf, size_t count) | 147 | void xwrite(int fd, const void *buf, size_t count) |
138 | { | 148 | { |
diff --git a/loginutils/login.c b/loginutils/login.c index b7428de45..791e44d83 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -337,7 +337,7 @@ auth_failed: | |||
337 | fchown(0, pw->pw_uid, pw->pw_gid); | 337 | fchown(0, pw->pw_uid, pw->pw_gid); |
338 | fchmod(0, 0600); | 338 | fchmod(0, 0600); |
339 | 339 | ||
340 | /* TODO: be nommu-friendly, use spawn? */ | 340 | /* TODO: be nommu-friendly, use spawn? */ |
341 | if (ENABLE_LOGIN_SCRIPTS) { | 341 | if (ENABLE_LOGIN_SCRIPTS) { |
342 | char *script = getenv("LOGIN_PRE_SUID_SCRIPT"); | 342 | char *script = getenv("LOGIN_PRE_SUID_SCRIPT"); |
343 | if (script) { | 343 | if (script) { |
diff --git a/networking/zcip.c b/networking/zcip.c index a8bfee65a..c50d5abaf 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
@@ -272,6 +272,7 @@ int zcip_main(int argc, char *argv[]) | |||
272 | // daemonize now; don't delay system startup | 272 | // daemonize now; don't delay system startup |
273 | if (!FOREGROUND) { | 273 | if (!FOREGROUND) { |
274 | /* bb_daemonize(); - bad, will close fd! */ | 274 | /* bb_daemonize(); - bad, will close fd! */ |
275 | //NOMMU | ||
275 | xdaemon(0, 0); | 276 | xdaemon(0, 0); |
276 | bb_info_msg("start, interface %s", intf); | 277 | bb_info_msg("start, interface %s", intf); |
277 | } | 278 | } |
diff --git a/runit/runit_lib.c b/runit/runit_lib.c index 0830314df..4762096b4 100644 --- a/runit/runit_lib.c +++ b/runit/runit_lib.c | |||
@@ -61,34 +61,6 @@ int coe(int fd) | |||
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | /*** fd_copy.c ***/ | ||
65 | |||
66 | int fd_copy(int to,int from) | ||
67 | { | ||
68 | if (to == from) | ||
69 | return 0; | ||
70 | if (fcntl(from,F_GETFL,0) == -1) | ||
71 | return -1; | ||
72 | close(to); | ||
73 | if (fcntl(from,F_DUPFD,to) == -1) | ||
74 | return -1; | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | |||
79 | /*** fd_move.c ***/ | ||
80 | |||
81 | int fd_move(int to,int from) | ||
82 | { | ||
83 | if (to == from) | ||
84 | return 0; | ||
85 | if (fd_copy(to,from) == -1) | ||
86 | return -1; | ||
87 | close(from); | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | |||
92 | /*** fmt_ptime.c ***/ | 64 | /*** fmt_ptime.c ***/ |
93 | 65 | ||
94 | void fmt_ptime30nul(char *s, struct taia *ta) { | 66 | void fmt_ptime30nul(char *s, struct taia *ta) { |
diff --git a/runit/runit_lib.h b/runit/runit_lib.h index 7b268e276..9fe4166bc 100644 --- a/runit/runit_lib.h +++ b/runit/runit_lib.h | |||
@@ -40,12 +40,6 @@ extern int coe(int); | |||
40 | #define direntry struct dirent | 40 | #define direntry struct dirent |
41 | 41 | ||
42 | 42 | ||
43 | /*** fd.h ***/ | ||
44 | |||
45 | extern int fd_copy(int,int); | ||
46 | extern int fd_move(int,int); | ||
47 | |||
48 | |||
49 | /*** tai.h ***/ | 43 | /*** tai.h ***/ |
50 | 44 | ||
51 | struct tai { | 45 | struct tai { |
diff --git a/runit/runsv.c b/runit/runsv.c index cd806851e..018456847 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -251,7 +251,7 @@ static unsigned custom(struct svdir *s, char c) | |||
251 | return 0; | 251 | return 0; |
252 | } | 252 | } |
253 | if (!pid) { | 253 | if (!pid) { |
254 | if (haslog && fd_copy(1, logpipe[1]) == -1) | 254 | if (haslog && dup2(logpipe[1], 1) == -1) |
255 | warn_cannot("setup stdout for control/?"); | 255 | warn_cannot("setup stdout for control/?"); |
256 | prog[0] = a; | 256 | prog[0] = a; |
257 | prog[1] = NULL; | 257 | prog[1] = NULL; |
@@ -312,13 +312,13 @@ static void startservice(struct svdir *s) | |||
312 | /* child */ | 312 | /* child */ |
313 | if (haslog) { | 313 | if (haslog) { |
314 | if (s->islog) { | 314 | if (s->islog) { |
315 | if (fd_copy(0, logpipe[0]) == -1) | 315 | if (dup2(logpipe[0], 0) == -1) |
316 | fatal_cannot("setup filedescriptor for ./log/run"); | 316 | fatal_cannot("setup filedescriptor for ./log/run"); |
317 | close(logpipe[1]); | 317 | close(logpipe[1]); |
318 | if (chdir("./log") == -1) | 318 | if (chdir("./log") == -1) |
319 | fatal_cannot("change directory to ./log"); | 319 | fatal_cannot("change directory to ./log"); |
320 | } else { | 320 | } else { |
321 | if (fd_copy(1, logpipe[1]) == -1) | 321 | if (dup2(logpipe[1], 1) == -1) |
322 | fatal_cannot("setup filedescriptor for ./run"); | 322 | fatal_cannot("setup filedescriptor for ./run"); |
323 | close(logpipe[0]); | 323 | close(logpipe[0]); |
324 | } | 324 | } |
diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 2f54cfef8..cce2c5d9c 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c | |||
@@ -191,7 +191,7 @@ static int setup_log(void) | |||
191 | coe(logpipe[0]); | 191 | coe(logpipe[0]); |
192 | ndelay_on(logpipe[0]); | 192 | ndelay_on(logpipe[0]); |
193 | ndelay_on(logpipe[1]); | 193 | ndelay_on(logpipe[1]); |
194 | if (fd_copy(2, logpipe[1]) == -1) { | 194 | if (dup2(logpipe[1], 2) == -1) { |
195 | warnx("cannot set filedescriptor for log"); | 195 | warnx("cannot set filedescriptor for log"); |
196 | return -1; | 196 | return -1; |
197 | } | 197 | } |
diff --git a/runit/svlogd.c b/runit/svlogd.c index e454bace8..fb834a403 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
@@ -153,12 +153,10 @@ static unsigned processorstart(struct logdir *ld) | |||
153 | if (verbose) | 153 | if (verbose) |
154 | bb_error_msg(INFO"processing: %s/%s", ld->name, ld->fnsave); | 154 | bb_error_msg(INFO"processing: %s/%s", ld->name, ld->fnsave); |
155 | fd = xopen(ld->fnsave, O_RDONLY|O_NDELAY); | 155 | fd = xopen(ld->fnsave, O_RDONLY|O_NDELAY); |
156 | if (fd_move(0, fd) == -1) | 156 | xmove_fd(fd, 0); |
157 | bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name); | ||
158 | ld->fnsave[26] = 't'; | 157 | ld->fnsave[26] = 't'; |
159 | fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); | 158 | fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); |
160 | if (fd_move(1, fd) == -1) | 159 | xmove_fd(fd, 1); |
161 | bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name); | ||
162 | fd = open_read("state"); | 160 | fd = open_read("state"); |
163 | if (fd == -1) { | 161 | if (fd == -1) { |
164 | if (errno != ENOENT) | 162 | if (errno != ENOENT) |
@@ -166,17 +164,15 @@ static unsigned processorstart(struct logdir *ld) | |||
166 | close(xopen("state", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT)); | 164 | close(xopen("state", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT)); |
167 | fd = xopen("state", O_RDONLY|O_NDELAY); | 165 | fd = xopen("state", O_RDONLY|O_NDELAY); |
168 | } | 166 | } |
169 | if (fd_move(4, fd) == -1) | 167 | xmove_fd(fd, 4); |
170 | bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name); | ||
171 | fd = xopen("newstate", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); | 168 | fd = xopen("newstate", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); |
172 | if (fd_move(5, fd) == -1) | 169 | xmove_fd(fd, 5); |
173 | bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name); | ||
174 | 170 | ||
175 | // getenv("SHELL")? | 171 | // getenv("SHELL")? |
176 | prog[0] = (char*)"sh"; | 172 | prog[0] = (char*)"sh"; |
177 | prog[1] = (char*)"-c"; | 173 | prog[1] = (char*)"-c"; |
178 | prog[2] = ld->processor; | 174 | prog[2] = ld->processor; |
179 | prog[3] = '\0'; | 175 | prog[3] = NULL; |
180 | execve("/bin/sh", prog, environ); | 176 | execve("/bin/sh", prog, environ); |
181 | bb_perror_msg_and_die(FATAL"cannot %s processor %s", "run", ld->name); | 177 | bb_perror_msg_and_die(FATAL"cannot %s processor %s", "run", ld->name); |
182 | } | 178 | } |