* NEWS, src/faillog.c, man/faillog.8.xml: Add --root option.
* NEWS, src/lastlog.c, man/lastlog.8.xml: Likewise. * src/faillog.c: Add Prog variable, and prefix error messages with Prog rather than "faillog". * src/lastlog.c: Likewise. * src/lastlog.c: Split usage in smaller messages.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
|
||||
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
||||
* Copyright (c) 2000 - 2006, Tomasz Kłoczko
|
||||
* Copyright (c) 2007 - 2009, Nicolas François
|
||||
* Copyright (c) 2007 - 2011, Nicolas François
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -44,6 +44,8 @@
|
||||
#include <assert.h>
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
/*@-exitarg@*/
|
||||
#include "exitcodes.h"
|
||||
|
||||
/*
|
||||
* Needed for MkLinux DR1/2/2.1 - J.
|
||||
@@ -55,6 +57,7 @@
|
||||
/*
|
||||
* Global variables
|
||||
*/
|
||||
const char *Prog; /* Program name */
|
||||
static FILE *lastlogfile; /* lastlog file stream */
|
||||
static unsigned long umin; /* if uflg and has_umin, only display users with uid >= umin */
|
||||
static bool has_umin = false;
|
||||
@@ -73,14 +76,18 @@ static bool bflg = false; /* print excludes most recent days */
|
||||
|
||||
static /*@noreturn@*/void usage (int status)
|
||||
{
|
||||
fputs (_("Usage: lastlog [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -b, --before DAYS print only lastlog records older than DAYS\n"
|
||||
" -h, --help display this help message and exit\n"
|
||||
" -t, --time DAYS print only lastlog records more recent than DAYS\n"
|
||||
" -u, --user LOGIN print lastlog record of the specified LOGIN\n"
|
||||
"\n"), (EXIT_SUCCESS != status) ? stderr : stdout);
|
||||
FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
|
||||
(void) fprintf (usageout,
|
||||
_("Usage: %s [options]\n"
|
||||
"\n"
|
||||
"Options:\n"),
|
||||
Prog);
|
||||
(void) fputs (_(" -b, --before DAYS print only lastlog records older than DAYS\n"), usageout);
|
||||
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
|
||||
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
||||
(void) fputs (_(" -t, --time DAYS print only lastlog records more recent than DAYS\n"), usageout);
|
||||
(void) fputs (_(" -u, --user LOGIN print lastlog record of the specified LOGIN\n"), usageout);
|
||||
(void) fputs ("\n", usageout);
|
||||
exit (status);
|
||||
}
|
||||
|
||||
@@ -113,8 +120,8 @@ static void print_one (/*@null@*/const struct passwd *pw)
|
||||
*/
|
||||
if (fread ((char *) &ll, sizeof (ll), 1, lastlogfile) != 1) {
|
||||
fprintf (stderr,
|
||||
_("lastlog: Failed to get the entry for UID %lu\n"),
|
||||
(unsigned long int)pw->pw_uid);
|
||||
_("%s: Failed to get the entry for UID %lu\n"),
|
||||
Prog, (unsigned long int)pw->pw_uid);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
@@ -189,21 +196,30 @@ static void print (void)
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/*
|
||||
* Get the program name. The program name is used as a prefix to
|
||||
* most error messages.
|
||||
*/
|
||||
Prog = Basename (argv[0]);
|
||||
|
||||
(void) setlocale (LC_ALL, "");
|
||||
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
(void) textdomain (PACKAGE);
|
||||
|
||||
process_root_flag ("-R", argc, argv);
|
||||
|
||||
{
|
||||
int c;
|
||||
static struct option const longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"time", required_argument, NULL, 't'},
|
||||
{"before", required_argument, NULL, 'b'},
|
||||
{"root", required_argument, NULL, 'R'},
|
||||
{"user", required_argument, NULL, 'u'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c = getopt_long (argc, argv, "ht:b:u:", longopts,
|
||||
while ((c = getopt_long (argc, argv, "ht:b:R:u:", longopts,
|
||||
NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
@@ -215,7 +231,7 @@ int main (int argc, char **argv)
|
||||
if (getulong (optarg, &days) == 0) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
"lastlog", optarg);
|
||||
Prog, optarg);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
seconds = (time_t) days * DAY;
|
||||
@@ -228,13 +244,15 @@ int main (int argc, char **argv)
|
||||
if (getulong (optarg, &inverse_days) == 0) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
"lastlog", optarg);
|
||||
Prog, optarg);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
inverse_seconds = (time_t) inverse_days * DAY;
|
||||
bflg = true;
|
||||
break;
|
||||
}
|
||||
case 'R': /* no-op, handled in process_root_flag () */
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
const struct passwd *pwent;
|
||||
@@ -258,8 +276,8 @@ int main (int argc, char **argv)
|
||||
&umin, &has_umin,
|
||||
&umax, &has_umax) == 0) {
|
||||
fprintf (stderr,
|
||||
_("lastlog: Unknown user or range: %s\n"),
|
||||
optarg);
|
||||
_("%s: Unknown user or range: %s\n"),
|
||||
Prog, optarg);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -272,8 +290,8 @@ int main (int argc, char **argv)
|
||||
}
|
||||
if (argc > optind) {
|
||||
fprintf (stderr,
|
||||
_("lastlog: unexpected argument: %s\n"),
|
||||
argv[optind]);
|
||||
_("%s: unexpected argument: %s\n"),
|
||||
Prog, argv[optind]);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -287,8 +305,8 @@ int main (int argc, char **argv)
|
||||
/* Get the lastlog size */
|
||||
if (fstat (fileno (lastlogfile), &statbuf) != 0) {
|
||||
fprintf (stderr,
|
||||
_("lastlog: Cannot get the size of %s: %s\n"),
|
||||
LASTLOG_FILE, strerror (errno));
|
||||
_("%s: Cannot get the size of %s: %s\n"),
|
||||
Prog, LASTLOG_FILE, strerror (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user