Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/console-tools/openvt.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/console-tools/openvt.c
r821 r1770 11 11 /* getopt not needed */ 12 12 13 #include <stdio.h> 14 #include <stdlib.h> 15 #include <unistd.h> 16 #include <fcntl.h> 17 #include <string.h> 18 #include <sys/types.h> 19 #include <ctype.h> 13 #include "libbb.h" 20 14 21 #include "busybox.h" 22 15 int openvt_main(int argc, char **argv); 23 16 int openvt_main(int argc, char **argv) 24 17 { 25 int fd;26 18 char vtname[sizeof(VC_FORMAT) + 2]; 27 19 20 if (argc < 3) 21 bb_show_usage(); 28 22 29 if (argc < 3) { 30 bb_show_usage(); 31 } 32 /* check for Illegal vt number: < 1 or > 12 */ 33 sprintf(vtname, VC_FORMAT, (int)bb_xgetlarg(argv[1], 10, 1, 12)); 23 /* check for illegal vt number: < 1 or > 63 */ 24 sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63)); 34 25 35 if (fork() == 0) {36 /* leave current vt*/37 if (setsid() < 0) {38 bb_perror_msg_and_die("setsid");39 }40 close(0); /* so that new vt becomes stdin */26 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); 41 32 42 /* and grab new one */ 43 fd = bb_xopen(vtname, O_RDWR); 44 45 /* Reassign stdout and sterr */ 46 dup2(fd, STDOUT_FILENO); 47 dup2(fd, STDERR_FILENO); 48 49 execvp(argv[2], &argv[2]); 50 _exit(1); 51 } 52 return EXIT_SUCCESS; 33 BB_EXECVP(argv[2], &argv[2]); 34 _exit(1); 53 35 }
Note:
See TracChangeset
for help on using the changeset viewer.