Bump to version 1.22.1
[platform/upstream/busybox.git] / util-linux / script.c
index 4e0deb4..8fb991d 100644 (file)
@@ -6,10 +6,22 @@
  *
  * Based on code from util-linux v 2.12r
  * Copyright (c) 1980
- *     The Regents of the University of California.  All rights reserved.
+ * The Regents of the University of California.  All rights reserved.
  *
- * Licensed under GPLv2 or later, see file License in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
+
+//usage:#define script_trivial_usage
+//usage:       "[-afq" IF_SCRIPTREPLAY("t") "] [-c PROG] [OUTFILE]"
+//usage:#define script_full_usage "\n\n"
+//usage:       "       -a      Append output"
+//usage:     "\n       -c PROG Run PROG, not shell"
+//usage:     "\n       -f      Flush output after each write"
+//usage:     "\n       -q      Quiet"
+//usage:       IF_SCRIPTREPLAY(
+//usage:     "\n       -t      Send timing to stderr"
+//usage:       )
+
 #include "libbb.h"
 
 int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -36,16 +48,17 @@ int script_main(int argc UNUSED_PARAM, char **argv)
                OPT_t = (1 << 4),
        };
 
+#if ENABLE_LONG_OPTS
        static const char getopt_longopts[] ALIGN1 =
                "append\0"  No_argument       "a"
                "command\0" Required_argument "c"
                "flush\0"   No_argument       "f"
                "quiet\0"   No_argument       "q"
-               IF_SCRIPTREPLAY("timing\0"  No_argument       "t")
+               IF_SCRIPTREPLAY("timing\0" No_argument "t")
                ;
 
-       if (ENABLE_GETOPT_LONG)
-               applet_long_options = getopt_longopts;
+       applet_long_options = getopt_longopts;
+#endif
 
        opt_complementary = "?1"; /* max one arg */
        opt = getopt32(argv, "ac:fq" IF_SCRIPTREPLAY("t") , &shell_arg);
@@ -64,10 +77,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
        if (!(opt & OPT_q)) {
                printf("Script started, file is %s\n", fname);
        }
-       shell = getenv("SHELL");
-       if (shell == NULL) {
-               shell = DEFAULT_SHELL;
-       }
+       shell = get_shell_name();
 
        pty = xgetpty(pty_line);
 
@@ -87,10 +97,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
 
        /* TODO: SIGWINCH? pass window size changes down to slave? */
 
-       child_pid = vfork();
-       if (child_pid < 0) {
-               bb_perror_msg_and_die("vfork");
-       }
+       child_pid = xvfork();
 
        if (child_pid) {
                /* parent */