From 6f074127ef73a3f52887e817c3b3acddc36b103a Mon Sep 17 00:00:00 2001 From: cheloha Date: Tue, 16 Jan 2018 17:07:49 +0000 Subject: [PATCH] Use the monotonic clock to compute the session duration. Ensures the correct duration is logged even if the system time is changed during the session. ok jca@ --- usr.sbin/authpf/authpf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/usr.sbin/authpf/authpf.c b/usr.sbin/authpf/authpf.c index 7e5a1e3d6c3..dc24ec4a008 100644 --- a/usr.sbin/authpf/authpf.c +++ b/usr.sbin/authpf/authpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: authpf.c,v 1.125 2016/03/29 14:53:27 mestre Exp $ */ +/* $OpenBSD: authpf.c,v 1.126 2018/01/16 17:07:49 cheloha Exp $ */ /* * Copyright (C) 1998 - 2007 Bob Beck (beck@openbsd.org). @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -39,6 +38,7 @@ #include #include #include +#include #include #include "pathnames.h" @@ -65,7 +65,7 @@ char luser[LOGIN_NAME_MAX]; /* username */ char ipsrc[256]; /* ip as a string */ char pidfile[PATH_MAX]; /* we save pid in this file. */ -struct timeval Tstart, Tend; /* start and end times of session */ +struct timespec Tstart, Tend; /* start and end times of session */ volatile sig_atomic_t want_death; static void need_death(int signo); @@ -819,12 +819,12 @@ change_filter(int add, const char *luser, const char *ipsrc) goto error; } - gettimeofday(&Tstart, NULL); + clock_gettime(CLOCK_MONOTONIC, &Tstart); syslog(LOG_INFO, "allowing %s, user %s", ipsrc, luser); } else { remove_stale_rulesets(); - gettimeofday(&Tend, NULL); + clock_gettime(CLOCK_MONOTONIC, &Tend); syslog(LOG_INFO, "removed %s, user %s - duration %d seconds", ipsrc, luser, (int)(Tend.tv_sec - Tstart.tv_sec)); } -- 2.20.1