From 02dcf28b5875df173bef8c14a9ddd3d3ce67c5d4 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 1 Sep 2012 14:45:15 +0000 Subject: Rework all non-contributed files that use `struct timezone'. This structure is not part of POSIX. According to POSIX, gettimeofday() has the following prototype: int gettimeofday(struct timeval *restrict tp, void *restrict tzp); Also, POSIX states that gettimeofday() shall return 0 (as long as tzp is not used). Remove dead error handling code. Also use NULL for a nul-pointer instead of integer 0. While there, change all pieces of code that only use tv_sec to use time(3), as this provides less overhead. --- release/picobsd/tinyware/login/pico-login.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'release/picobsd') diff --git a/release/picobsd/tinyware/login/pico-login.c b/release/picobsd/tinyware/login/pico-login.c index 7834623..e540ca8 100644 --- a/release/picobsd/tinyware/login/pico-login.c +++ b/release/picobsd/tinyware/login/pico-login.c @@ -150,12 +150,11 @@ main(argc, argv) extern char **environ; struct group *gr; struct stat st; - struct timeval tp; struct utmpx utmp; int rootok, retries, backoff; int ask, ch, cnt, fflag, hflag, pflag, quietlog, rootlogin, rval; int changepass; - time_t warntime; + time_t now, warntime; uid_t uid, euid; gid_t egid; char *p, *ttyn; @@ -430,8 +429,7 @@ main(argc, argv) if (!quietlog) quietlog = access(_PATH_HUSHLOGIN, F_OK) == 0; - if (pwd->pw_change || pwd->pw_expire) - (void)gettimeofday(&tp, (struct timezone *)NULL); + now = time(NULL); #define DEFAULT_WARN (2L * 7L * 86400L) /* Two weeks */ @@ -439,10 +437,10 @@ main(argc, argv) DEFAULT_WARN); if (pwd->pw_expire) { - if (tp.tv_sec >= pwd->pw_expire) { + if (now >= pwd->pw_expire) { refused("Sorry -- your account has expired", "EXPIRED", 1); - } else if (pwd->pw_expire - tp.tv_sec < warntime && !quietlog) + } else if (pwd->pw_expire - now < warntime && !quietlog) (void)printf("Warning: your account expires on %s", ctime(&pwd->pw_expire)); } @@ -452,12 +450,12 @@ main(argc, argv) changepass = 0; if (pwd->pw_change) { - if (tp.tv_sec >= pwd->pw_change) { + if (now >= pwd->pw_change) { (void)printf("Sorry -- your password has expired.\n"); changepass = 1; syslog(LOG_INFO, "%s Password expired - forcing change", pwd->pw_name); - } else if (pwd->pw_change - tp.tv_sec < warntime && !quietlog) + } else if (pwd->pw_change - now < warntime && !quietlog) (void)printf("Warning: your password expires on %s", ctime(&pwd->pw_change)); } -- cgit v1.1