add NOMMU fixme's; move move_fd from runit_lib to libbb; nuke fd_copy
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 25 Mar 2007 23:21:05 +0000 (23:21 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 25 Mar 2007 23:21:05 +0000 (23:21 -0000)
console-tools/openvt.c
e2fsprogs/fsck.c
include/libbb.h
libbb/xfuncs.c
loginutils/login.c
networking/zcip.c
runit/runit_lib.c
runit/runit_lib.h
runit/runsv.c
runit/runsvdir.c
runit/svlogd.c

index eb9f49fe25931091dccbe42faf81d62030186022..0584584df91910be8e577d604ea2c82eea8e0331 100644 (file)
@@ -22,8 +22,9 @@ int openvt_main(int argc, char **argv)
                bb_show_usage();
        }
        /* check for illegal vt number: < 1 or > 63 */
-       sprintf(vtname, VC_FORMAT, (int)xatoul_range(argv[1], 1, 63));
+       sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
 
+//FIXME NOMMU
        if (fork() == 0) {
                /* child */
                /* leave current vt (controlling tty) */
index ad22fcd7a8b522e0b1411e0620ad378483273f34..c31ab3f1ade529e82a7a661d4a6df4d8f0305ae8 100644 (file)
@@ -667,7 +667,8 @@ static void execute(const char *type, const char *device, const char *mntpt,
        /* Fork and execute the correct program. */
        pid = -1;
        if (!noexecute) {
-               pid = fork(); /* TODO: NOMMU friendly way (vfork)? */
+/* TODO: NOMMU friendly way (vfork)? */
+               pid = fork();
                if (pid < 0)
                        bb_perror_msg_and_die("fork");
                if (pid == 0) {
index 152b87099049cacde88c448941b0d58a778fd6af..aba9316d12bfad4a9c0e7b4ec8cde837da981080 100644 (file)
@@ -250,8 +250,10 @@ extern char bb_process_escape_sequence(const char **ptr);
 /* TODO: sometimes modifies its parameter, which
  * makes it rather inconvenient at times: */
 extern char *bb_get_last_path_component(char *path);
-extern int ndelay_on(int fd);
-extern int ndelay_off(int fd);
+
+int ndelay_on(int fd);
+int ndelay_off(int fd);
+void xmove_fd(int, int);
 
 
 extern DIR *xopendir(const char *path);
@@ -616,6 +618,8 @@ extern int index_in_substr_array(const char * const string_array[], const char *
 extern void print_login_issue(const char *issue_file, const char *tty);
 extern void print_login_prompt(void);
 #ifdef BB_NOMMU
+extern pid_t BUG_fork_is_unavailable_on_nommu(void);
+#define fork() BUG_fork_is_unavailable_on_nommu()
 extern void vfork_daemon_rexec(int nochdir, int noclose, char **argv);
 extern smallint re_execed;
 #endif
index c496f9a220548dcbe3497250a42e58a19ad70e04..1dcdbc065d54f9f870547e230a9d3dc90da684ed 100644 (file)
@@ -133,6 +133,16 @@ int ndelay_off(int fd)
        return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK);
 }
 
+// "Renumber" opened fd
+void xmove_fd(int from, int to)
+{
+       if (from == to)
+               return;
+       if (dup2(from, to) != to)
+               bb_perror_msg_and_die("cannot duplicate file descriptor");
+       close(from);
+}
+
 // Die with an error message if we can't write the entire buffer.
 void xwrite(int fd, const void *buf, size_t count)
 {
index b7428de450cf0a5884372317d44921c62dff4665..791e44d8315644e121e9e367cbdd2569aa091420 100644 (file)
@@ -337,7 +337,7 @@ auth_failed:
        fchown(0, pw->pw_uid, pw->pw_gid);
        fchmod(0, 0600);
 
-       /* TODO: be nommu-friendly, use spawn? */
+/* TODO: be nommu-friendly, use spawn? */
        if (ENABLE_LOGIN_SCRIPTS) {
                char *script = getenv("LOGIN_PRE_SUID_SCRIPT");
                if (script) {
index a8bfee65a0e58b5e72d9ccd07ec1dbfd33cbdd13..c50d5abafef60884e53ab813c1d4f7b6ec6af265 100644 (file)
@@ -272,6 +272,7 @@ int zcip_main(int argc, char *argv[])
        // daemonize now; don't delay system startup
        if (!FOREGROUND) {
                /* bb_daemonize(); - bad, will close fd! */
+//NOMMU
                xdaemon(0, 0);
                bb_info_msg("start, interface %s", intf);
        }
index 0830314df59638d65c085d61a6879e18625c5faf..4762096b4df66b16eab47f2411d20a007e948858 100644 (file)
@@ -61,34 +61,6 @@ int coe(int fd)
 }
 
 
-/*** fd_copy.c ***/
-
-int fd_copy(int to,int from)
-{
-       if (to == from)
-               return 0;
-       if (fcntl(from,F_GETFL,0) == -1)
-               return -1;
-       close(to);
-       if (fcntl(from,F_DUPFD,to) == -1)
-               return -1;
-       return 0;
-}
-
-
-/*** fd_move.c ***/
-
-int fd_move(int to,int from)
-{
-       if (to == from)
-               return 0;
-       if (fd_copy(to,from) == -1)
-               return -1;
-       close(from);
-       return 0;
-}
-
-
 /*** fmt_ptime.c ***/
 
 void fmt_ptime30nul(char *s, struct taia *ta) {
index 7b268e2765826d75fdb68243036187a33b34559e..9fe4166bcc835b70b75d94b7b145abe72490131b 100644 (file)
@@ -40,12 +40,6 @@ extern int coe(int);
 #define direntry struct dirent
 
 
-/*** fd.h ***/
-
-extern int fd_copy(int,int);
-extern int fd_move(int,int);
-
-
 /*** tai.h ***/
 
 struct tai {
index cd806851eadbb86028d33ed80f06e14b2abba55e..0184568474652e06501322b17f4fec0420fadff4 100644 (file)
@@ -251,7 +251,7 @@ static unsigned custom(struct svdir *s, char c)
                                return 0;
                        }
                        if (!pid) {
-                               if (haslog && fd_copy(1, logpipe[1]) == -1)
+                               if (haslog && dup2(logpipe[1], 1) == -1)
                                        warn_cannot("setup stdout for control/?");
                                prog[0] = a;
                                prog[1] = NULL;
@@ -312,13 +312,13 @@ static void startservice(struct svdir *s)
                /* child */
                if (haslog) {
                        if (s->islog) {
-                               if (fd_copy(0, logpipe[0]) == -1)
+                               if (dup2(logpipe[0], 0) == -1)
                                        fatal_cannot("setup filedescriptor for ./log/run");
                                close(logpipe[1]);
                                if (chdir("./log") == -1)
                                        fatal_cannot("change directory to ./log");
                        } else {
-                               if (fd_copy(1, logpipe[1]) == -1)
+                               if (dup2(logpipe[1], 1) == -1)
                                        fatal_cannot("setup filedescriptor for ./run");
                                close(logpipe[0]);
                        }
index 2f54cfef8cd295e585a0ab72f73c6199db2ee57d..cce2c5d9c86980e08a51208ea169234f3c6d479f 100644 (file)
@@ -191,7 +191,7 @@ static int setup_log(void)
        coe(logpipe[0]);
        ndelay_on(logpipe[0]);
        ndelay_on(logpipe[1]);
-       if (fd_copy(2, logpipe[1]) == -1) {
+       if (dup2(logpipe[1], 2) == -1) {
                warnx("cannot set filedescriptor for log");
                return -1;
        }
index e454bace83d68441f2930e5e40c0ccf492566f28..fb834a403d96af19ad195f55444c7da64f13a00c 100644 (file)
@@ -153,12 +153,10 @@ static unsigned processorstart(struct logdir *ld)
                if (verbose)
                        bb_error_msg(INFO"processing: %s/%s", ld->name, ld->fnsave);
                fd = xopen(ld->fnsave, O_RDONLY|O_NDELAY);
-               if (fd_move(0, fd) == -1)
-                       bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name);
+               xmove_fd(fd, 0);
                ld->fnsave[26] = 't';
                fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT);
-               if (fd_move(1, fd) == -1)
-                       bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name);
+               xmove_fd(fd, 1);
                fd = open_read("state");
                if (fd == -1) {
                        if (errno != ENOENT)
@@ -166,17 +164,15 @@ static unsigned processorstart(struct logdir *ld)
                        close(xopen("state", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT));
                        fd = xopen("state", O_RDONLY|O_NDELAY);
                }
-               if (fd_move(4, fd) == -1)
-                       bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name);
+               xmove_fd(fd, 4);
                fd = xopen("newstate", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT);
-               if (fd_move(5, fd) == -1)
-                       bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name);
+               xmove_fd(fd, 5);
 
 // getenv("SHELL")?
                prog[0] = (char*)"sh";
                prog[1] = (char*)"-c";
                prog[2] = ld->processor;
-               prog[3] = '\0';
+               prog[3] = NULL;
                execve("/bin/sh", prog, environ);
                bb_perror_msg_and_die(FATAL"cannot %s processor %s", "run", ld->name);
        }