|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
/*
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
Parse command line options for vlock, the VT locking program for linux.
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
Copyright (C) 1994-1998 Michael K. Johnson <johnsonm@redhat.com>
|
|
Packit Service |
50ad14 |
Copyright (C) 2002, 2005 Dmitry V. Levin <ldv@altlinux.org>
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
50ad14 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
50ad14 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit Service |
50ad14 |
(at your option) any later version.
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
50ad14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
50ad14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
50ad14 |
GNU General Public License for more details.
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
50ad14 |
along with this program; if not, write to the Free Software
|
|
Packit Service |
50ad14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit Service |
50ad14 |
*/
|
|
Packit Service |
50ad14 |
#include "config.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
#include <stdio.h>
|
|
Packit Service |
50ad14 |
#include <stdlib.h>
|
|
Packit Service |
50ad14 |
#include <errno.h>
|
|
Packit Service |
50ad14 |
#include <getopt.h>
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
#include "vlock.h"
|
|
Packit Service |
50ad14 |
#include "nls.h"
|
|
Packit Service |
50ad14 |
#include "version.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
/*
|
|
Packit Service |
50ad14 |
* This determines whether the default behavior is to lock only the
|
|
Packit Service |
50ad14 |
* current VT or all of them.
|
|
Packit Service |
50ad14 |
* 0 means current, 1 means all.
|
|
Packit Service |
50ad14 |
*/
|
|
Packit Service |
50ad14 |
int o_lock_all;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
const char *
|
|
Packit Service |
50ad14 |
locked_name(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
return o_lock_all ? "console" : (is_vt ? "VC" : "tty");
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
static void __attribute__((__noreturn__))
|
|
Packit Service |
50ad14 |
show_usage(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
fprintf(stderr,
|
|
Packit Service |
50ad14 |
_("Try `%s --help' for more information.\n"),
|
|
Packit Service |
50ad14 |
program_invocation_short_name);
|
|
Packit Service |
50ad14 |
exit(1);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
static void __attribute__((__noreturn__))
|
|
Packit Service |
50ad14 |
show_help(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
printf(_("%s: locks virtual consoles, saving your current session.\n"
|
|
Packit Service |
50ad14 |
"Usage: %s [options]\n"
|
|
Packit Service |
50ad14 |
" Where [options] are any of:\n"
|
|
Packit Service |
50ad14 |
"-c or --current: lock only this virtual console, allowing user to\n"
|
|
Packit Service |
50ad14 |
" switch to other virtual consoles.\n"
|
|
Packit Service |
50ad14 |
"-a or --all: lock all virtual consoles by preventing other users\n"
|
|
Packit Service |
50ad14 |
" from switching virtual consoles.\n"
|
|
Packit Service |
50ad14 |
"-v or --version: Print the version number of vlock and exit.\n"
|
|
Packit Service |
50ad14 |
"-h or --help: Print this help message and exit.\n"),
|
|
Packit Service |
50ad14 |
progname, progname);
|
|
Packit Service |
50ad14 |
exit(0);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
void parse(int ac, char *const av[])
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
static struct option long_options[] = {
|
|
Packit Service |
50ad14 |
{ "current", 0, 0, 'c' },
|
|
Packit Service |
50ad14 |
{ "all", 0, 0, 'a' },
|
|
Packit Service |
50ad14 |
{ "version", 0, 0, 'v' },
|
|
Packit Service |
50ad14 |
{ "help", 0, 0, 'h' },
|
|
Packit Service |
50ad14 |
{ 0, 0, 0, 0 },
|
|
Packit Service |
50ad14 |
};
|
|
Packit Service |
50ad14 |
int c;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
while ((c = getopt_long(ac, av, "acvh", long_options, 0)) != -1) {
|
|
Packit Service |
50ad14 |
switch (c) {
|
|
Packit Service |
50ad14 |
case 'c':
|
|
Packit Service |
50ad14 |
o_lock_all = 0;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'a':
|
|
Packit Service |
50ad14 |
o_lock_all = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'v':
|
|
Packit Service |
50ad14 |
fprintf(stderr, "%s\n", VERSION);
|
|
Packit Service |
50ad14 |
exit(EXIT_SUCCESS);
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'h':
|
|
Packit Service |
50ad14 |
show_help();
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
default:
|
|
Packit Service |
50ad14 |
show_usage();
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
}
|