All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] some fixes last(1)
@ 2015-03-25  9:40 Ruediger Meier
  2015-03-25  9:40 ` [PATCH 1/2] last: fix first (current) runlevel line Ruediger Meier
  2015-03-25  9:40 ` [PATCH 2/2] last, fix race when comparing time stamps Ruediger Meier
  0 siblings, 2 replies; 3+ messages in thread
From: Ruediger Meier @ 2015-03-25  9:40 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

This is pull request #184 on github
https://github.com/karelzak/util-linux/pull/184

Ruediger Meier (2):
  last: fix first (current) runlevel line
  last, fix race when comparing time stamps

 login-utils/last.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

-- 
1.8.4.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] last: fix first (current) runlevel line
  2015-03-25  9:40 [PATCH 0/2] some fixes last(1) Ruediger Meier
@ 2015-03-25  9:40 ` Ruediger Meier
  2015-03-25  9:40 ` [PATCH 2/2] last, fix race when comparing time stamps Ruediger Meier
  1 sibling, 0 replies; 3+ messages in thread
From: Ruediger Meier @ 2015-03-25  9:40 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Since 744c7fec lastrch was not set to current time anymore, but we need it.

 # broken:
 $ ./last -x | grep -m 2 runlevel
 runlevel (to lvl 5)   3.11.10-25-deskt Wed Feb 18 13:11 - 01:00 (-16484+-12:-11)
 runlevel (to lvl 5)   3.11.10-25-deskt Thu Jan 22 16:50 - 13:11 (26+20:21)

 # fixed:
 $ ./last -x | grep -m 2 runlevel
 runlevel (to lvl 5)   3.11.10-25-deskt Wed Feb 18 13:11   still running
 runlevel (to lvl 5)   3.11.10-25-deskt Thu Jan 22 16:50 - 13:11 (26+20:21)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 login-utils/last.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/login-utils/last.c b/login-utils/last.c
index 9682764..4a165c2 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -638,7 +638,7 @@ static void process_wtmp_file(const struct last_control *ctl,
 	/*
 	 * Fill in 'lastdate'
 	 */
-	lastdate = lastdown;
+	lastdate = lastrch = lastdown;
 
 	/*
 	 * Install signal handlers
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] last, fix race when comparing time stamps
  2015-03-25  9:40 [PATCH 0/2] some fixes last(1) Ruediger Meier
  2015-03-25  9:40 ` [PATCH 1/2] last: fix first (current) runlevel line Ruediger Meier
@ 2015-03-25  9:40 ` Ruediger Meier
  1 sibling, 0 replies; 3+ messages in thread
From: Ruediger Meier @ 2015-03-25  9:40 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

It is just luck if two time() calls happen within the same
second. Introduced in 31d28e09.

Actually I don't like adding another global variable but this
way we avoid bigger refactoring. IMO it's questionable why
lastdate, lastdown, etc. are initialized with current time() at
all. It looks unsafe to print "still running" always when
logout_time = now.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 login-utils/last.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/login-utils/last.c b/login-utils/last.c
index 4a165c2..8d82c10 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -138,6 +138,7 @@ static struct last_timefmt timefmts[] = {
 /* Global variables */
 static unsigned int recsdone;	/* Number of records listed */
 static time_t lastdate;		/* Last date we've seen */
+static time_t currentdate;	/* date when we started processing the file */
 
 /* --time-format=option parser */
 static int which_time_format(const char *optarg)
@@ -372,7 +373,7 @@ static void trim_trailing_spaces(char *s)
  */
 static int list(const struct last_control *ctl, struct utmp *p, time_t logout_time, int what)
 {
-	time_t		secs, utmp_time, now;
+	time_t		secs, utmp_time;
 	char		logintime[LAST_TIMESTAMP_LEN];
 	char		logouttime[LAST_TIMESTAMP_LEN];
 	char		length[LAST_TIMESTAMP_LEN];
@@ -428,8 +429,7 @@ static int list(const struct last_control *ctl, struct utmp *p, time_t logout_ti
 	hours = (secs / 3600) % 24;
 	days  = secs / 86400;
 
-	now = time(NULL);
-	if (logout_time == now) {
+	if (logout_time == currentdate) {
 		if (ctl->time_fmt > LAST_TIMEFTM_SHORT_CTIME) {
 			sprintf(logouttime, "  still running");
 			length[0] = 0;
@@ -638,7 +638,7 @@ static void process_wtmp_file(const struct last_control *ctl,
 	/*
 	 * Fill in 'lastdate'
 	 */
-	lastdate = lastrch = lastdown;
+	lastdate = currentdate = lastrch = lastdown;
 
 	/*
 	 * Install signal handlers
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-25  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25  9:40 [PATCH 0/2] some fixes last(1) Ruediger Meier
2015-03-25  9:40 ` [PATCH 1/2] last: fix first (current) runlevel line Ruediger Meier
2015-03-25  9:40 ` [PATCH 2/2] last, fix race when comparing time stamps Ruediger Meier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.