X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=console-tools%2Fopenvt.c;h=d9f49bbead77d4203b86ed82fab081295ae5288b;hb=d1b6078e5d614993de2a858e85f1dc06cfe5539b;hp=269dfc01a48997c37b8aba2ad3e07ebb74d00ae5;hpb=0a3b0106ab62950a3486ca33a7e3c9ee6d0e0fca;p=oweals%2Fbusybox.git diff --git a/console-tools/openvt.c b/console-tools/openvt.c index 269dfc01a..d9f49bbea 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c @@ -32,34 +32,22 @@ #include "busybox.h" -#define VTNAME "/dev/tty%d" - int openvt_main(int argc, char **argv) { - int pid; int fd; - int vtno; - char vtname[sizeof VTNAME + 2]; + char vtname[sizeof VC_FORMAT + 2]; if (argc < 3) bb_show_usage(); - if (!isdigit(argv[1][0])) - bb_show_usage(); - - vtno = (int) atol(argv[1]); - - /* if (vtno <= 0 || vtno > 63) */ - if (vtno <= 0 || vtno > 12) - bb_error_msg_and_die("Illegal vt number (%d)", vtno); - - sprintf(vtname, VTNAME, vtno); + /* check for Illegal vt number: < 1 or > 12 */ + sprintf(vtname, VC_FORMAT,(int)bb_xgetlarg(argv[1], 10, 1, 12)); argv+=2; argc-=2; - if((pid = fork()) == 0) { + if(fork() == 0) { /* leave current vt */ #ifdef ESIX_5_3_2_D @@ -68,19 +56,16 @@ int openvt_main(int argc, char **argv) if (setsid() < 0) { #endif - bb_perror_msg_and_die("Unable to set new session"); + bb_perror_msg_and_die("Unable to set new session"); } close(0); /* so that new vt becomes stdin */ /* and grab new one */ - if ((fd = open(vtname, O_RDWR)) == -1) - bb_perror_msg_and_die("could not open %s", vtname); + fd = bb_xopen(vtname, O_RDWR); /* Reassign stdout and sterr */ - close(1); - close(2); - dup(fd); - dup(fd); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); execvp(argv[0], argv); _exit(1);