* src/lastlog.c: Use EXIT_FAILURE / EXIT_SUCCESS for exit()
* src/lastlog.c: Added splint annotations. * src/lastlog.c: Avoid global pwent. * src/lastlog.c: Cast ID to ulongs and use ulong formats for IDs. * src/lastlog.c: Avoid assignment in comparisons. * src/lastlog.c: Ignore fclose() return value since the file is only opened for reading.
This commit is contained in:
parent
77c1b2a369
commit
87e15d7b82
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* src/lastlog.c: Use EXIT_FAILURE / EXIT_SUCCESS for exit()
|
||||||
|
* src/lastlog.c: Added splint annotations.
|
||||||
|
* src/lastlog.c: Avoid global pwent.
|
||||||
|
* src/lastlog.c: Cast ID to ulongs and use ulong formats for IDs.
|
||||||
|
* src/lastlog.c: Avoid assignment in comparisons.
|
||||||
|
* src/lastlog.c: Ignore fclose() return value since the file is
|
||||||
|
only opened for reading.
|
||||||
|
|
||||||
2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
|
2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/newgrp.c: Added assertion to guide splint (and me).
|
* src/newgrp.c: Added assertion to guide splint (and me).
|
||||||
|
@ -70,7 +70,6 @@ static struct stat statbuf; /* fstat buffer for file size */
|
|||||||
static bool uflg = false; /* print only an user of range of users */
|
static bool uflg = false; /* print only an user of range of users */
|
||||||
static bool tflg = false; /* print is restricted to most recent days */
|
static bool tflg = false; /* print is restricted to most recent days */
|
||||||
static bool bflg = false; /* print excludes most recent days */
|
static bool bflg = false; /* print excludes most recent days */
|
||||||
static struct passwd *pwent;
|
|
||||||
|
|
||||||
#define NOW (time ((time_t *) 0))
|
#define NOW (time ((time_t *) 0))
|
||||||
|
|
||||||
@ -84,10 +83,10 @@ static void usage (void)
|
|||||||
" -t, --time DAYS print only lastlog records more recent than DAYS\n"
|
" -t, --time DAYS print only lastlog records more recent than DAYS\n"
|
||||||
" -u, --user LOGIN print lastlog record of the specified LOGIN\n"
|
" -u, --user LOGIN print lastlog record of the specified LOGIN\n"
|
||||||
"\n"), stderr);
|
"\n"), stderr);
|
||||||
exit (1);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_one (const struct passwd *pw)
|
static void print_one (/*@null@*/const struct passwd *pw)
|
||||||
{
|
{
|
||||||
static bool once = false;
|
static bool once = false;
|
||||||
char *cp;
|
char *cp;
|
||||||
@ -116,9 +115,9 @@ static void print_one (const struct passwd *pw)
|
|||||||
*/
|
*/
|
||||||
if (fread ((char *) &ll, sizeof (ll), 1, lastlogfile) != 1) {
|
if (fread ((char *) &ll, sizeof (ll), 1, lastlogfile) != 1) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("lastlog: Failed to get the entry for UID %d\n"),
|
_("lastlog: Failed to get the entry for UID %lu\n"),
|
||||||
pw->pw_uid);
|
(unsigned long int)pw->pw_uid);
|
||||||
exit (1);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Outsize of the lastlog file.
|
/* Outsize of the lastlog file.
|
||||||
@ -173,6 +172,7 @@ static void print_one (const struct passwd *pw)
|
|||||||
|
|
||||||
static void print (void)
|
static void print (void)
|
||||||
{
|
{
|
||||||
|
const struct passwd *pwent;
|
||||||
if (uflg && has_umin && has_umax && (umin == umax)) {
|
if (uflg && has_umin && has_umax && (umin == umax)) {
|
||||||
print_one (getpwuid ((uid_t)umin));
|
print_one (getpwuid ((uid_t)umin));
|
||||||
} else {
|
} else {
|
||||||
@ -222,6 +222,8 @@ int main (int argc, char **argv)
|
|||||||
bflg = true;
|
bflg = true;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
|
{
|
||||||
|
const struct passwd *pwent;
|
||||||
/*
|
/*
|
||||||
* The user can be:
|
* The user can be:
|
||||||
* - a login name
|
* - a login name
|
||||||
@ -244,10 +246,11 @@ int main (int argc, char **argv)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("lastlog: Unknown user or range: %s\n"),
|
_("lastlog: Unknown user or range: %s\n"),
|
||||||
optarg);
|
optarg);
|
||||||
exit (1);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
usage ();
|
usage ();
|
||||||
break;
|
break;
|
||||||
@ -261,9 +264,10 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lastlogfile = fopen (LASTLOG_FILE, "r")) == (FILE *) 0) {
|
lastlogfile = fopen (LASTLOG_FILE, "r");
|
||||||
|
if (NULL == lastlogfile) {
|
||||||
perror (LASTLOG_FILE);
|
perror (LASTLOG_FILE);
|
||||||
exit (1);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the lastlog size */
|
/* Get the lastlog size */
|
||||||
@ -271,12 +275,12 @@ int main (int argc, char **argv)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("lastlog: Cannot get the size of %s: %s\n"),
|
_("lastlog: Cannot get the size of %s: %s\n"),
|
||||||
LASTLOG_FILE, strerror (errno));
|
LASTLOG_FILE, strerror (errno));
|
||||||
exit (1);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
print ();
|
print ();
|
||||||
|
|
||||||
fclose (lastlogfile);
|
(void) fclose (lastlogfile);
|
||||||
exit (0);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user