More init fixes. Fixed sync segfault.
authorEric Andersen <andersen@codepoet.org>
Wed, 3 Nov 1999 16:52:50 +0000 (16:52 -0000)
committerEric Andersen <andersen@codepoet.org>
Wed, 3 Nov 1999 16:52:50 +0000 (16:52 -0000)
 -Erik

Changelog
archival/tar.c
busybox.spec
coreutils/sync.c
examples/busybox.spec
init.c
init/init.c
sync.c
tar.c

index aa549bd17d67614fb4ca0ccd9a76dad41a676e56..741b8ebb7614a3403e7aeb3fcb5870f177ae25c8 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -8,6 +8,7 @@
        * Major adjustment of init.c.  Code is now readable IMHO,
            and much more solid.
        * Wrote sed -- weighs only 1.8k (5.8k with full regular expressions!).
+       * Fixed a stupid seg-fault in sync
 
         -Erik Andersen
 
index c7ef3851ccbd7172397a91cfc070710455674f34..cd255f85cee36dfb609e4581a4c997e341265ad8 100644 (file)
@@ -37,8 +37,8 @@
 
 
 static const char tar_usage[] =
-    "Create, extract, or list files from a TAR file\n\n"
-    "usage: tar -[cxtvOf] [tarFileName] [FILE] ...\n"
+    "tar -[cxtvOf] [tarFileName] [FILE] ...\n"
+    "Create, extract, or list files from a tar file\n\n"
     "\tc=create, x=extract, t=list contents, v=verbose,\n"
     "\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
 
@@ -151,10 +151,8 @@ extern int tar_main (int argc, char **argv)
     argc--;
     argv++;
 
-    if (argc < 1) {
-       fprintf (stderr, "%s", tar_usage);
-       exit (FALSE);
-    }
+    if (argc < 1)
+       usage( tar_usage);
 
 
     errorFlag = FALSE;
index f44cdc7a43a066186f1c7b3cd5f3cac0fc6087b9..0cc15d43533298eabebb23e43d8598725d2e4934 100644 (file)
@@ -30,7 +30,7 @@ h=`cat busybox.links`
 
 for i in $h ; do
        mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
-       (cd $RPM_BUILD_ROOT/bin ; ln -s ln `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` ); 
+       (cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` ); 
 done 
 rm -f $RPM_BUILD_ROOT/bin/busybox
 install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
index b9f52c8b08793907f3a914450242223bcec1a5bd..cb4690c0238826f919ac587908217241febf9fd5 100644 (file)
@@ -26,9 +26,9 @@
 extern int
 sync_main(int argc, char * * argv)
 {
-    if ( **(argv+1) == '-' ) {
+    if ( argc>1 && **(argv+1) == '-' ) {
        usage( "sync\nWrite all buffered filesystem blocks to disk.\n");
     }
-    return sync();
+    exit( sync());
 }
 
index f44cdc7a43a066186f1c7b3cd5f3cac0fc6087b9..0cc15d43533298eabebb23e43d8598725d2e4934 100644 (file)
@@ -30,7 +30,7 @@ h=`cat busybox.links`
 
 for i in $h ; do
        mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
-       (cd $RPM_BUILD_ROOT/bin ; ln -s ln `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` ); 
+       (cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` ); 
 done 
 rm -f $RPM_BUILD_ROOT/bin/busybox
 install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
diff --git a/init.c b/init.c
index 34eca8b776fe1ddfcf4bdbc1437d0b9ac0efa263..899e430400e22e582bc968fcff0c68c8f623eca4 100644 (file)
--- a/init.c
+++ b/init.c
 //#define DEBUG_INIT
 
 #define CONSOLE         "/dev/console" /* Logical system console */
-#define VT_PRIMARY      "/dev/tty0"    /* Primary virtual console */
-#define VT_SECONDARY    "/dev/tty1"    /* Virtual console */
-#define VT_LOG          "/dev/tty2"    /* Virtual console */
+#define VT_PRIMARY      "/dev/tty1"    /* Primary virtual console */
+#define VT_SECONDARY    "/dev/tty2"    /* Virtual console */
+#define VT_LOG          "/dev/tty3"    /* Virtual console */
 #define SERIAL_CON0     "/dev/ttyS0"    /* Primary serial console */
 #define SERIAL_CON1     "/dev/ttyS1"    /* Serial console */
 #define SHELL           "/bin/sh"      /* Default shell */
 #define INITSCRIPT      "/etc/init.d/rcS"      /* Initscript. */
 #define PATH_DEFAULT    "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
 
-static char *console = VT_PRIMARY;
-static char *second_terminal = VT_SECONDARY;
-static char *log = "/dev/tty3";
+static char *console = CONSOLE;
+static char *second_console = VT_SECONDARY;
+static char *log = VT_LOG;
 
 
 
@@ -173,23 +173,23 @@ static void console_init()
        }
 #endif
     } else {
-       console = VT_PRIMARY;
-       tried_vtprimary++;
+       console = CONSOLE;
+       tried_devcons++;
     }
 
     while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
-       /* Can't open selected console -- try vt1 */
-       if (!tried_vtprimary) {
-           tried_vtprimary++;
-           console = VT_PRIMARY;
-           continue;
-       }
        /* Can't open selected console -- try /dev/console */
        if (!tried_devcons) {
            tried_devcons++;
            console = CONSOLE;
            continue;
        }
+       /* Can't open selected console -- try vt1 */
+       if (!tried_vtprimary) {
+           tried_vtprimary++;
+           console = VT_PRIMARY;
+           continue;
+       }
        break;
     }
     if (fd < 0)
@@ -449,7 +449,7 @@ extern int init_main(int argc, char **argv)
            pid1 = run(tty0_commands, console, wait_for_enter);
        }
        if (pid2 == 0 && tty1_commands) {
-           pid2 = run(tty1_commands, second_terminal, TRUE);
+           pid2 = run(tty1_commands, second_console, TRUE);
        }
        wpid = wait(&status);
        if (wpid > 0 ) {
index 34eca8b776fe1ddfcf4bdbc1437d0b9ac0efa263..899e430400e22e582bc968fcff0c68c8f623eca4 100644 (file)
 //#define DEBUG_INIT
 
 #define CONSOLE         "/dev/console" /* Logical system console */
-#define VT_PRIMARY      "/dev/tty0"    /* Primary virtual console */
-#define VT_SECONDARY    "/dev/tty1"    /* Virtual console */
-#define VT_LOG          "/dev/tty2"    /* Virtual console */
+#define VT_PRIMARY      "/dev/tty1"    /* Primary virtual console */
+#define VT_SECONDARY    "/dev/tty2"    /* Virtual console */
+#define VT_LOG          "/dev/tty3"    /* Virtual console */
 #define SERIAL_CON0     "/dev/ttyS0"    /* Primary serial console */
 #define SERIAL_CON1     "/dev/ttyS1"    /* Serial console */
 #define SHELL           "/bin/sh"      /* Default shell */
 #define INITSCRIPT      "/etc/init.d/rcS"      /* Initscript. */
 #define PATH_DEFAULT    "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
 
-static char *console = VT_PRIMARY;
-static char *second_terminal = VT_SECONDARY;
-static char *log = "/dev/tty3";
+static char *console = CONSOLE;
+static char *second_console = VT_SECONDARY;
+static char *log = VT_LOG;
 
 
 
@@ -173,23 +173,23 @@ static void console_init()
        }
 #endif
     } else {
-       console = VT_PRIMARY;
-       tried_vtprimary++;
+       console = CONSOLE;
+       tried_devcons++;
     }
 
     while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
-       /* Can't open selected console -- try vt1 */
-       if (!tried_vtprimary) {
-           tried_vtprimary++;
-           console = VT_PRIMARY;
-           continue;
-       }
        /* Can't open selected console -- try /dev/console */
        if (!tried_devcons) {
            tried_devcons++;
            console = CONSOLE;
            continue;
        }
+       /* Can't open selected console -- try vt1 */
+       if (!tried_vtprimary) {
+           tried_vtprimary++;
+           console = VT_PRIMARY;
+           continue;
+       }
        break;
     }
     if (fd < 0)
@@ -449,7 +449,7 @@ extern int init_main(int argc, char **argv)
            pid1 = run(tty0_commands, console, wait_for_enter);
        }
        if (pid2 == 0 && tty1_commands) {
-           pid2 = run(tty1_commands, second_terminal, TRUE);
+           pid2 = run(tty1_commands, second_console, TRUE);
        }
        wpid = wait(&status);
        if (wpid > 0 ) {
diff --git a/sync.c b/sync.c
index b9f52c8b08793907f3a914450242223bcec1a5bd..cb4690c0238826f919ac587908217241febf9fd5 100644 (file)
--- a/sync.c
+++ b/sync.c
@@ -26,9 +26,9 @@
 extern int
 sync_main(int argc, char * * argv)
 {
-    if ( **(argv+1) == '-' ) {
+    if ( argc>1 && **(argv+1) == '-' ) {
        usage( "sync\nWrite all buffered filesystem blocks to disk.\n");
     }
-    return sync();
+    exit( sync());
 }
 
diff --git a/tar.c b/tar.c
index c7ef3851ccbd7172397a91cfc070710455674f34..cd255f85cee36dfb609e4581a4c997e341265ad8 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -37,8 +37,8 @@
 
 
 static const char tar_usage[] =
-    "Create, extract, or list files from a TAR file\n\n"
-    "usage: tar -[cxtvOf] [tarFileName] [FILE] ...\n"
+    "tar -[cxtvOf] [tarFileName] [FILE] ...\n"
+    "Create, extract, or list files from a tar file\n\n"
     "\tc=create, x=extract, t=list contents, v=verbose,\n"
     "\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
 
@@ -151,10 +151,8 @@ extern int tar_main (int argc, char **argv)
     argc--;
     argv++;
 
-    if (argc < 1) {
-       fprintf (stderr, "%s", tar_usage);
-       exit (FALSE);
-    }
+    if (argc < 1)
+       usage( tar_usage);
 
 
     errorFlag = FALSE;