Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/loginutils/vlock.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/loginutils/vlock.c
r1765 r2725 1 1 /* vi: set sw=4 ts=4: */ 2 3 2 /* 4 3 * vlock implementation for busybox … … 7 6 * Written by spoon <spon@ix.netcom.com> 8 7 * 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 9 */ 11 10 … … 18 17 19 18 #include "libbb.h" 19 20 #ifdef __linux__ 20 21 #include <sys/vt.h> 21 22 22 static struct passwd *pw; 23 static struct vt_mode ovtm; 24 static struct termios oterm; 25 static int vfd; 26 static unsigned long o_lock_all; 27 28 static void release_vt(int signo) 23 static void release_vt(int signo UNUSED_PARAM) 29 24 { 30 ioctl(vfd, VT_RELDISP, !o_lock_all); 25 /* If -a, param is 0, which means: 26 * "no, kernel, we don't allow console switch away from us!" */ 27 ioctl(STDIN_FILENO, VT_RELDISP, (unsigned long) !option_mask32); 31 28 } 32 29 33 static void acquire_vt(int signo )30 static void acquire_vt(int signo UNUSED_PARAM) 34 31 { 35 ioctl(vfd, VT_RELDISP, VT_ACKACQ); 32 /* ACK to kernel that switch to console is successful */ 33 ioctl(STDIN_FILENO, VT_RELDISP, VT_ACKACQ); 36 34 } 35 #endif 37 36 38 static void restore_terminal(void) 37 int vlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 38 int vlock_main(int argc UNUSED_PARAM, char **argv) 39 39 { 40 ioctl(vfd, VT_SETMODE, &ovtm); 41 tcsetattr(STDIN_FILENO, TCSANOW, &oterm); 42 } 40 #ifdef __linux__ 41 struct vt_mode vtm; 42 struct vt_mode ovtm; 43 #endif 44 struct termios term; 45 struct termios oterm; 46 struct passwd *pw; 43 47 44 int vlock_main(int argc, char **argv); 45 int vlock_main(int argc, char **argv) 46 { 47 sigset_t sig; 48 struct sigaction sa; 49 struct vt_mode vtm; 50 struct termios term; 51 uid_t uid = getuid(); 48 pw = xgetpwuid(getuid()); 49 opt_complementary = "=0"; /* no params! */ 50 getopt32(argv, "a"); 52 51 53 pw = getpwuid(uid); 54 if (pw == NULL) 55 bb_error_msg_and_die("unknown uid %d", uid); 52 /* Ignore some signals so that we don't get killed by them */ 53 bb_signals(0 54 + (1 << SIGTSTP) 55 + (1 << SIGTTIN) 56 + (1 << SIGTTOU) 57 + (1 << SIGHUP ) 58 + (1 << SIGCHLD) /* paranoia :) */ 59 + (1 << SIGQUIT) 60 + (1 << SIGINT ) 61 , SIG_IGN); 56 62 57 if (argc > 2) { 58 bb_show_usage(); 59 } 63 #ifdef __linux__ 64 /* We will use SIGUSRx for console switch control: */ 65 /* 1: set handlers */ 66 signal_SA_RESTART_empty_mask(SIGUSR1, release_vt); 67 signal_SA_RESTART_empty_mask(SIGUSR2, acquire_vt); 68 /* 2: unmask them */ 69 sig_unblock(SIGUSR1); 70 sig_unblock(SIGUSR2); 71 #endif 60 72 61 o_lock_all = getopt32(argv, "a"); 73 /* Revert stdin/out to our controlling tty 74 * (or die if we have none) */ 75 xmove_fd(xopen(CURRENT_TTY, O_RDWR), STDIN_FILENO); 76 xdup2(STDIN_FILENO, STDOUT_FILENO); 62 77 63 vfd = xopen(CURRENT_TTY, O_RDWR); 64 65 xioctl(vfd, VT_GETMODE, &vtm); 66 67 /* mask a bunch of signals */ 68 sigprocmask(SIG_SETMASK, NULL, &sig); 69 sigdelset(&sig, SIGUSR1); 70 sigdelset(&sig, SIGUSR2); 71 sigaddset(&sig, SIGTSTP); 72 sigaddset(&sig, SIGTTIN); 73 sigaddset(&sig, SIGTTOU); 74 sigaddset(&sig, SIGHUP); 75 sigaddset(&sig, SIGCHLD); 76 sigaddset(&sig, SIGQUIT); 77 sigaddset(&sig, SIGINT); 78 79 sigemptyset(&(sa.sa_mask)); 80 sa.sa_flags = SA_RESTART; 81 sa.sa_handler = release_vt; 82 sigaction(SIGUSR1, &sa, NULL); 83 sa.sa_handler = acquire_vt; 84 sigaction(SIGUSR2, &sa, NULL); 85 86 /* need to handle some signals so that we don't get killed by them */ 87 sa.sa_handler = SIG_IGN; 88 sigaction(SIGHUP, &sa, NULL); 89 sigaction(SIGQUIT, &sa, NULL); 90 sigaction(SIGINT, &sa, NULL); 91 sigaction(SIGTSTP, &sa, NULL); 92 78 #ifdef __linux__ 79 xioctl(STDIN_FILENO, VT_GETMODE, &vtm); 93 80 ovtm = vtm; 81 /* "console switches are controlled by us, not kernel!" */ 94 82 vtm.mode = VT_PROCESS; 95 83 vtm.relsig = SIGUSR1; 96 84 vtm.acqsig = SIGUSR2; 97 ioctl(vfd, VT_SETMODE, &vtm); 85 ioctl(STDIN_FILENO, VT_SETMODE, &vtm); 86 #endif 98 87 99 88 tcgetattr(STDIN_FILENO, &oterm); … … 103 92 term.c_lflag &= ~ISIG; 104 93 term.c_lflag &= ~(ECHO | ECHOCTL); 105 tcsetattr (STDIN_FILENO, TCSANOW,&term);94 tcsetattr_stdin_TCSANOW(&term); 106 95 107 96 do { 108 printf("Virtual Console%s locked by %s.\n", (o_lock_all) ? "s" : "", pw->pw_name); 97 printf("Virtual console%s locked by %s.\n", 98 option_mask32 /*o_lock_all*/ ? "s" : "", 99 pw->pw_name); 109 100 if (correct_password(pw)) { 110 101 break; … … 113 104 puts("Password incorrect"); 114 105 } while (1); 115 restore_terminal(); 116 fflush_stdout_and_exit(0); 106 107 #ifdef __linux__ 108 ioctl(STDIN_FILENO, VT_SETMODE, &ovtm); 109 #endif 110 tcsetattr_stdin_TCSANOW(&oterm); 111 fflush_stdout_and_exit(EXIT_SUCCESS); 117 112 }
Note:
See TracChangeset
for help on using the changeset viewer.