blob: c050ba19efda0899e04246913ba9d9abb07a2bee [file] [log] [blame]
Glenn L McGrathec0c48c2002-09-16 03:16:06 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrathec0c48c2002-09-16 03:16:06 +00002/*
Glenn L McGrathebdc8b42002-09-16 03:47:48 +00003 * openvt.c - open a vt to run a command.
Glenn L McGrathec0c48c2002-09-16 03:16:06 +00004 *
Glenn L McGrathebdc8b42002-09-16 03:47:48 +00005 * busyboxed by Quy Tonthat <quy@signal3.com>
Glenn L McGrath0a3b0102003-05-13 16:31:15 +00006 * hacked by Tito <farmatito@tiscali.it>
Glenn L McGrathebdc8b42002-09-16 03:47:48 +00007 *
Bernhard Reutner-Fischerb1629b12006-05-19 19:29:19 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Glenn L McGrathec0c48c2002-09-16 03:16:06 +00009 */
10
11/* getopt not needed */
12
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000013#include "libbb.h"
Glenn L McGrathec0c48c2002-09-16 03:16:06 +000014
Denis Vlasenko06af2162007-02-03 17:28:39 +000015int openvt_main(int argc, char **argv);
Glenn L McGrathec0c48c2002-09-16 03:16:06 +000016int openvt_main(int argc, char **argv)
17{
Rob Landleyead19302006-03-10 23:16:25 +000018 char vtname[sizeof(VC_FORMAT) + 2];
Glenn L McGrath0a3b0102003-05-13 16:31:15 +000019
Denis Vlasenko53091ec2007-03-26 13:35:09 +000020 if (argc < 3)
Rob Landleyead19302006-03-10 23:16:25 +000021 bb_show_usage();
Denis Vlasenko53091ec2007-03-26 13:35:09 +000022
Denis Vlasenko13858992006-10-08 12:49:22 +000023 /* check for illegal vt number: < 1 or > 63 */
Denis Vlasenkocad04ef2007-03-25 23:21:05 +000024 sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
Glenn L McGrathec0c48c2002-09-16 03:16:06 +000025
Denis Vlasenko53091ec2007-03-26 13:35:09 +000026 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
27 /* grab new one */
28 close(0);
29 xopen(vtname, O_RDWR);
30 dup2(0, STDOUT_FILENO);
31 dup2(0, STDERR_FILENO);
Glenn L McGrathec0c48c2002-09-16 03:16:06 +000032
Denis Vlasenko53091ec2007-03-26 13:35:09 +000033 BB_EXECVP(argv[2], &argv[2]);
34 _exit(1);
Glenn L McGrathec0c48c2002-09-16 03:16:06 +000035}