summaryrefslogtreecommitdiff
path: root/console-tools/openvt.c
diff options
context:
space:
mode:
Diffstat (limited to 'console-tools/openvt.c')
-rw-r--r--console-tools/openvt.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/console-tools/openvt.c b/console-tools/openvt.c
index 0584584..882563b 100644
--- a/console-tools/openvt.c
+++ b/console-tools/openvt.c
@@ -15,30 +15,21 @@
int openvt_main(int argc, char **argv);
int openvt_main(int argc, char **argv)
{
- int fd;
char vtname[sizeof(VC_FORMAT) + 2];
- if (argc < 3) {
+ if (argc < 3)
bb_show_usage();
- }
+
/* check for illegal vt number: < 1 or > 63 */
sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
-//FIXME NOMMU
- if (fork() == 0) {
- /* child */
- /* leave current vt (controlling tty) */
- setsid();
- /* and grab new one */
- fd = xopen(vtname, O_RDWR);
- /* Reassign stdin, stdout and sterr */
- dup2(fd, STDIN_FILENO);
- dup2(fd, STDOUT_FILENO);
- dup2(fd, STDERR_FILENO);
- while (fd > 2) close(fd--);
+ bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
+ /* grab new one */
+ close(0);
+ xopen(vtname, O_RDWR);
+ dup2(0, STDOUT_FILENO);
+ dup2(0, STDERR_FILENO);
- BB_EXECVP(argv[2], &argv[2]);
- _exit(1);
- }
- return EXIT_SUCCESS;
+ BB_EXECVP(argv[2], &argv[2]);
+ _exit(1);
}