last: Use EXIT_* and err()
Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
This commit is contained in:
parent
3851ebe8f8
commit
db797f24f1
|
@ -29,6 +29,7 @@
|
|||
/*
|
||||
* last
|
||||
*/
|
||||
#include <err.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
|
@ -147,7 +148,7 @@ main(int argc, char **argv) {
|
|||
case '?':
|
||||
default:
|
||||
fputs(_("usage: last [-#] [-f file] [-t tty] [-h hostname] [user ...]\n"), stderr);
|
||||
exit(1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
for (argv += optind; *argv; ++argv) {
|
||||
#define COMPATIBILITY
|
||||
|
@ -158,7 +159,8 @@ main(int argc, char **argv) {
|
|||
addarg(USER_TYPE, *argv);
|
||||
}
|
||||
wtmp();
|
||||
exit(0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static char *utmp_ctime(struct utmp *u)
|
||||
|
@ -235,13 +237,15 @@ wtmp(void) {
|
|||
(void)signal(SIGQUIT, onintr);
|
||||
|
||||
if ((fd = open(file,O_RDONLY)) < 0)
|
||||
exit(1);
|
||||
err(EXIT_FAILURE, _("%s: open failed"), file);
|
||||
|
||||
fstat(fd, &st);
|
||||
utl_len = st.st_size;
|
||||
utl = mmap(NULL, utl_len, PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE|MAP_FILE, fd, 0);
|
||||
if (utl == NULL)
|
||||
exit(1);
|
||||
err(EXIT_FAILURE, _("%s: mmap failed"), file);
|
||||
|
||||
listnr = utl_len/sizeof(struct utmp);
|
||||
|
||||
if(listnr)
|
||||
|
@ -345,28 +349,28 @@ want(struct utmp *bp, int check) {
|
|||
bp->ut_line[4] = '\0';
|
||||
}
|
||||
if (!arglist)
|
||||
return(YES);
|
||||
return YES;
|
||||
|
||||
for (step = arglist; step; step = step->next)
|
||||
switch(step->type) {
|
||||
case HOST_TYPE:
|
||||
if (!strncmp(step->name, bp->ut_host, HMAX))
|
||||
return(YES);
|
||||
return YES;
|
||||
break;
|
||||
case TTY_TYPE:
|
||||
if (!strncmp(step->name, bp->ut_line, LMAX))
|
||||
return(YES);
|
||||
return YES;
|
||||
break;
|
||||
case USER_TYPE:
|
||||
if (!strncmp(step->name, bp->ut_name, NMAX))
|
||||
return(YES);
|
||||
return YES;
|
||||
break;
|
||||
case INET_TYPE:
|
||||
if (bp->ut_addr == inet_addr(step->name))
|
||||
return(YES);
|
||||
return YES;
|
||||
break;
|
||||
}
|
||||
return(NO);
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -416,10 +420,9 @@ hostconv(char *arg) {
|
|||
return;
|
||||
if (first) {
|
||||
first = 0;
|
||||
if (gethostname(name, sizeof(name))) {
|
||||
perror(_("last: gethostname"));
|
||||
exit(1);
|
||||
}
|
||||
if (gethostname(name, sizeof(name)))
|
||||
err(EXIT_FAILURE, _("gethostname failed"));
|
||||
|
||||
hostdot = strchr(name, '.');
|
||||
}
|
||||
if (hostdot && !strcmp(hostdot, argdot))
|
||||
|
@ -447,11 +450,12 @@ ttyconv(char *arg) {
|
|||
(void)strcpy(mval, "tty");
|
||||
(void)strcpy(mval + 3, arg);
|
||||
}
|
||||
return(mval);
|
||||
return mval;
|
||||
}
|
||||
if (!strncmp(arg, "/dev/", sizeof("/dev/") - 1))
|
||||
return(arg + 5);
|
||||
return(arg);
|
||||
return arg + 5;
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -465,6 +469,6 @@ onintr(int signo) {
|
|||
ct = utmp_ctime(&utmpbuf);
|
||||
printf(_("\ninterrupted %10.10s %5.5s \n"), ct, ct + 11);
|
||||
if (signo == SIGINT)
|
||||
_exit(1);
|
||||
(void)fflush(stdout); /* fix required for rsh */
|
||||
_exit(EXIT_FAILURE);
|
||||
fflush(stdout); /* fix required for rsh */
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue