aboutsummaryrefslogtreecommitdiff
path: root/console-tools
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-09-16 03:16:06 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-09-16 03:16:06 +0000
commitec0c48cb296185c5af585c9f9a7213cd4177dbb5 (patch)
tree49aee82f58bf99c33065595d20efc1ed08a03e3c /console-tools
parent6714862bdd2ee83d0e0f42cdbf4752629376b81e (diff)
downloadbusybox-w32-ec0c48cb296185c5af585c9f9a7213cd4177dbb5.tar.gz
busybox-w32-ec0c48cb296185c5af585c9f9a7213cd4177dbb5.tar.bz2
busybox-w32-ec0c48cb296185c5af585c9f9a7213cd4177dbb5.zip
openvt applet by Quy Tonthat
Diffstat (limited to 'console-tools')
-rw-r--r--console-tools/Makefile.in1
-rw-r--r--console-tools/config.in1
-rw-r--r--console-tools/openvt.c84
3 files changed, 86 insertions, 0 deletions
diff --git a/console-tools/Makefile.in b/console-tools/Makefile.in
index bc0335643..c2c1bad6a 100644
--- a/console-tools/Makefile.in
+++ b/console-tools/Makefile.in
@@ -30,6 +30,7 @@ CONSOLETOOLS_DIR-$(CONFIG_DUMPKMAP) += dumpkmap.o
30CONSOLETOOLS_DIR-$(CONFIG_LOADACM) += loadacm.o 30CONSOLETOOLS_DIR-$(CONFIG_LOADACM) += loadacm.o
31CONSOLETOOLS_DIR-$(CONFIG_LOADFONT) += loadfont.o 31CONSOLETOOLS_DIR-$(CONFIG_LOADFONT) += loadfont.o
32CONSOLETOOLS_DIR-$(CONFIG_LOADKMAP) += loadkmap.o 32CONSOLETOOLS_DIR-$(CONFIG_LOADKMAP) += loadkmap.o
33CONSOLETOOLS_DIR-$(CONFIG_OPENVT) += openvt.o
33CONSOLETOOLS_DIR-$(CONFIG_RESET) += reset.o 34CONSOLETOOLS_DIR-$(CONFIG_RESET) += reset.o
34CONSOLETOOLS_DIR-$(CONFIG_SETKEYCODES) += setkeycodes.o 35CONSOLETOOLS_DIR-$(CONFIG_SETKEYCODES) += setkeycodes.o
35 36
diff --git a/console-tools/config.in b/console-tools/config.in
index 53d5ac6b4..2ea96aec4 100644
--- a/console-tools/config.in
+++ b/console-tools/config.in
@@ -12,6 +12,7 @@ bool 'dumpkmap' CONFIG_DUMPKMAP
12bool 'loadacm' CONFIG_LOADACM 12bool 'loadacm' CONFIG_LOADACM
13bool 'loadfont' CONFIG_LOADFONT 13bool 'loadfont' CONFIG_LOADFONT
14bool 'loadkmap' CONFIG_LOADKMAP 14bool 'loadkmap' CONFIG_LOADKMAP
15bool 'openvt' CONFIG_OPENVT
15bool 'reset' CONFIG_RESET 16bool 'reset' CONFIG_RESET
16bool 'setkeycodes' CONFIG_SETKEYCODES 17bool 'setkeycodes' CONFIG_SETKEYCODES
17 18
diff --git a/console-tools/openvt.c b/console-tools/openvt.c
new file mode 100644
index 000000000..3373edd29
--- /dev/null
+++ b/console-tools/openvt.c
@@ -0,0 +1,84 @@
1/* vi: set sw=4 ts=4: */
2
3/*
4 * openvt.c - open a vt to run a command.
5 *
6 * busyboxed by Quy Tonthat <quy@signal3.com>
7 */
8
9/* getopt not needed */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <fcntl.h>
15#include <string.h>
16#include <sys/types.h>
17#include "busybox.h"
18
19#define VTNAME "/dev/tty%d"
20
21int openvt_main(int argc, char **argv)
22{
23 int pid;
24 int fd;
25 int vtno;
26 char vtname[sizeof VTNAME + 2];
27 char * cmd = NULL;
28 char * cmd_args = NULL;
29
30 if (argc < 3)
31 show_usage();
32
33 if (!isdigit(argv[1][0]))
34 show_usage();
35
36 vtno = (int) atol(argv[1]);
37
38 /* if (vtno <= 0 || vtno > 63) */
39 if (vtno <= 0 || vtno > 12)
40 error_msg_and_die("Illegal vt number (%d)", vtno);
41
42 sprintf(vtname, VTNAME, vtno);
43
44 cmd = argv[2];
45 cmd_args = xmalloc(80);
46 cmd_args[0] = '\0';
47
48 if((pid = fork()) == 0) {
49 /* leave current vt */
50
51#ifdef ESIX_5_3_2_D
52 if (setpgrp() < 0) {
53#else
54 if (setsid() < 0) {
55#endif
56
57 perror_msg_and_die("Unable to set new session");
58 }
59 close(0); /* so that new vt becomes stdin */
60
61 /* and grab new one */
62 if ((fd = open(vtname, O_RDWR)) == -1)
63 perror_msg_and_die("could not open %s", vtname);
64
65 /* Reassign stdout and sterr */
66 close(1);
67 close(2);
68 dup(fd);
69 dup(fd);
70
71 execvp(cmd, &argv[2]);
72 /*execlp(cmd, cmd_args);*/
73 _exit(1);
74 }
75 return EXIT_SUCCESS;
76}
77
78/*
79Local Variables:
80c-file-style: "linux"
81c-basic-offset: 4
82tab-width: 4
83End:
84*/