1 /* vi: set sw=4 ts=4: */
3 * openvt.c - open a vt to run a command.
5 * busyboxed by Quy Tonthat <quy@signal3.com>
6 * hacked by Tito <farmatito@tiscali.it>
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 /* getopt not needed */
18 #include <sys/types.h>
23 int openvt_main(int argc, char **argv)
26 char vtname[sizeof(VC_FORMAT) + 2];
32 /* check for Illegal vt number: < 1 or > 12 */
33 sprintf(vtname, VC_FORMAT, (int)bb_xgetlarg(argv[1], 10, 1, 12));
36 /* leave current vt */
38 bb_perror_msg_and_die("setsid");
40 close(0); /* so that new vt becomes stdin */
42 /* and grab new one */
43 fd = bb_xopen(vtname, O_RDWR);
45 /* Reassign stdout and sterr */
46 dup2(fd, STDOUT_FILENO);
47 dup2(fd, STDERR_FILENO);
49 execvp(argv[2], &argv[2]);