hexedit: fixes to "goto address" code
[oweals/busybox.git] / console-tools / openvt.c
index 6f58916e7b61c5b3b16b4ff60c91b14d53e71f64..423122fe9e1ecf152122f551b839f82efa8e004f 100644 (file)
@@ -5,8 +5,31 @@
  *  busyboxed by Quy Tonthat <quy@signal3.com>
  *  hacked by Tito <farmatito@tiscali.it>
  *
- * 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.
  */
+//config:config OPENVT
+//config:      bool "openvt (7 kb)"
+//config:      default y
+//config:      select PLATFORM_LINUX
+//config:      help
+//config:      This program is used to start a command on an unused
+//config:      virtual terminal.
+
+//applet:IF_OPENVT(APPLET(openvt, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_OPENVT) += openvt.o
+
+//usage:#define openvt_trivial_usage
+//usage:       "[-c N] [-sw] [PROG ARGS]"
+//usage:#define openvt_full_usage "\n\n"
+//usage:       "Start PROG on a new virtual terminal\n"
+//usage:     "\n       -c N    Use specified VT"
+//usage:     "\n       -s      Switch to the VT"
+/* //usage:     "\n    -l      Run PROG as login shell (by prepending '-')" */
+//usage:     "\n       -w      Wait for PROG to exit"
+//usage:
+//usage:#define openvt_example_usage
+//usage:       "openvt 2 /bin/ash\n"
 
 #include <linux/vt.h>
 #include "libbb.h"
@@ -76,7 +99,7 @@ static int find_free_vtno(void)
        /*xfunc_error_retval = 3; - do we need compat? */
        if (ioctl(fd, VT_OPENQRY, &vtno) != 0 || vtno <= 0)
                bb_perror_msg_and_die("can't find open VT");
-// Not really needed, grep for DAEMON_ONLY_SANITIZE
+// Not really needed, grep for DAEMON_CLOSE_EXTRA_FDS
 //     if (fd > 2)
 //             close(fd);
        return vtno;
@@ -97,8 +120,7 @@ static NOINLINE void vfork_child(char **argv)
                //bb_error_msg("our pgrp %d", getpgrp());
                //bb_error_msg("VT's sid %d", tcgetsid(0));
                //bb_error_msg("VT's pgrp %d", tcgetpgrp(0));
-               BB_EXECVP(argv[0], argv);
-               bb_perror_msg_and_die("can't execute '%s'", argv[0]);
+               BB_EXECVP_or_die(argv);
        }
 }
 
@@ -133,7 +155,7 @@ int openvt_main(int argc UNUSED_PARAM, char **argv)
        /* Grab new VT */
        sprintf(vtname, VC_FORMAT, vtno);
        /* (Try to) clean up stray open fds above fd 2 */
-       bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL);
+       bb_daemon_helper(DAEMON_CLOSE_EXTRA_FDS);
        close(STDIN_FILENO);
        /*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
        xopen(vtname, O_RDWR);
@@ -145,9 +167,7 @@ int openvt_main(int argc UNUSED_PARAM, char **argv)
 
        if (!argv[0]) {
                argv--;
-               argv[0] = getenv("SHELL");
-               if (!argv[0])
-                       argv[0] = (char *) DEFAULT_SHELL;
+               argv[0] = (char *) get_shell_name();
                /*argv[1] = NULL; - already is */
        }