summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2009-06-14 13:27:50 +0000
committerRalf Baechle <ralf@linux-mips.org>2009-06-14 13:27:50 +0000
commita7c513d8dc2f4dc2f9a7ae91736f2f2870f2c892 (patch)
tree81ecb1f5a85b85335df4aff81c3eca43553a24d7
parent378a483bd88de4c91e34e0646e90b92cd2d03ec9 (diff)
Fix utmp time code
Thanks to using the antiquated time(2) call the microsecond field of the struct utmp being manipulated was never initialized resulting in random values. On some 64-bit systems this also manifested itself in below warnings. axspawn.c: In function ‘cleanup’: axspawn.c:1017: warning: passing argument 1 of ‘time’ from incompatible pointer type /usr/include/time.h:186: note: expected ‘time_t *’ but argument is of type ‘int32_t *’ [...] axspawn.c: In function ‘main’: [...] axspawn.c:1693: warning: passing argument 1 of ‘time’ from incompatible pointer type /usr/include/time.h:186: note: expected ‘time_t *’ but argument is of type ‘int32_t *’ Fixed by changing it to the recommended initialization sequenze based on gettimeofday().
-rw-r--r--ChangeLog1
-rw-r--r--ax25/axspawn.c14
2 files changed, 11 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 5c5c8b0..7977359 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@ ax25-tools (0.0.10)
* An IP address is no longer mandatory for nrattach, kissattach.
* kissparms now allows to send a raw value to the driver and to set
the CRC mode by command line option.
+ * axspawn now records the time at microsecond accuracy in utmp.
-- Ralf Baechle DL5RB <ralf@linux-mips.org> Sat, 6 Jun 2009 17:36:01 +0100
diff --git a/ax25/axspawn.c b/ax25/axspawn.c
index d28130e..a1af4c9 100644
--- a/ax25/axspawn.c
+++ b/ax25/axspawn.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: axspawn.c,v 1.19 2008/11/08 19:07:19 dl9sau Exp $
+ * $Id: axspawn.c,v 1.20 2009/06/14 13:27:51 ralf Exp $
*
* axspawn.c - run a program from ax25d.
*
@@ -1003,8 +1003,10 @@ int get_assoc(struct sockaddr_ax25 *sax25)
void cleanup(char *tty)
{
struct utmp ut, *ut_line;
+ struct timeval tv;
FILE *fp;
+
setutent();
ut.ut_type = LOGIN_PROCESS;
strncpy(ut.ut_id, tty + 3, sizeof(ut.ut_id));
@@ -1014,8 +1016,9 @@ void cleanup(char *tty)
ut_line->ut_type = DEAD_PROCESS;
ut_line->ut_host[0] = '\0';
ut_line->ut_user[0] = '\0';
- time(&ut_line->ut_time);
- pututline(ut_line);
+ gettimeofday(&tv, NULL);
+ ut_line->ut_tv.tv_sec = tv.tv_sec;
+ ut_line->ut_tv.tv_usec = tv.tv_usec;
if ((fp = fopen(_PATH_WTMP, "r+")) != NULL) {
fseek(fp, 0L, SEEK_END);
if (fwrite(ut_line, sizeof(ut), 1, fp) != 1)
@@ -1341,6 +1344,7 @@ int main(int argc, char **argv)
char call[20], user[20], as_user[20];
char buf[2048];
int k, cnt, digits, letters, invalid, ssid, ssidcnt, addrlen;
+ struct timeval tv;
pid_t pid = -1;
char *p;
fd_set fds_read, fds_err;
@@ -1688,7 +1692,9 @@ again:
strncpy(ut_line.ut_id, ptyslave + 8, sizeof(ut_line.ut_id));
strncpy(ut_line.ut_user, "LOGIN", sizeof(ut_line.ut_user));
strncpy(ut_line.ut_host, protocol, sizeof(ut_line.ut_host));
- time(&ut_line.ut_time);
+ gettimeofday(&tv, NULL);
+ ut_line.ut_tv.tv_sec = tv.tv_sec;
+ ut_line.ut_tv.tv_usec = tv.tv_usec;
ut_line.ut_addr = 0;
pututline(&ut_line);
endutent();