Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/loginutils/vlock.c

    r1765 r2725  
    11/* vi: set sw=4 ts=4: */
    2 
    32/*
    43 * vlock implementation for busybox
     
    76 * Written by spoon <spon@ix.netcom.com>
    87 *
    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.
    109 */
    1110
     
    1817
    1918#include "libbb.h"
     19
     20#ifdef __linux__
    2021#include <sys/vt.h>
    2122
    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)
     23static void release_vt(int signo UNUSED_PARAM)
    2924{
    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);
    3128}
    3229
    33 static void acquire_vt(int signo)
     30static void acquire_vt(int signo UNUSED_PARAM)
    3431{
    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);
    3634}
     35#endif
    3736
    38 static void restore_terminal(void)
     37int vlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     38int vlock_main(int argc UNUSED_PARAM, char **argv)
    3939{
    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;
    4347
    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");
    5251
    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);
    5662
    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
    6072
    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);
    6277
    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);
    9380    ovtm = vtm;
     81    /* "console switches are controlled by us, not kernel!" */
    9482    vtm.mode = VT_PROCESS;
    9583    vtm.relsig = SIGUSR1;
    9684    vtm.acqsig = SIGUSR2;
    97     ioctl(vfd, VT_SETMODE, &vtm);
     85    ioctl(STDIN_FILENO, VT_SETMODE, &vtm);
     86#endif
    9887
    9988    tcgetattr(STDIN_FILENO, &oterm);
     
    10392    term.c_lflag &= ~ISIG;
    10493    term.c_lflag &= ~(ECHO | ECHOCTL);
    105     tcsetattr(STDIN_FILENO, TCSANOW, &term);
     94    tcsetattr_stdin_TCSANOW(&term);
    10695
    10796    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);
    109100        if (correct_password(pw)) {
    110101            break;
     
    113104        puts("Password incorrect");
    114105    } 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);
    117112}
Note: See TracChangeset for help on using the changeset viewer.