From 73c9b25d2d0e40a657073489311a4ecd1643362c Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 3 Jun 2008 18:13:54 +0000 Subject: It is too easy to create things in the same second; use a timespec instead. --- cmd.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'cmd.c') diff --git a/cmd.c b/cmd.c index 2fb90069..430a2410 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.39 2008-06-03 16:55:09 nicm Exp $ */ +/* $Id: cmd.c,v 1.40 2008-06-03 18:13:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -253,18 +254,18 @@ struct session * cmd_lookup_session(const char *sname) { struct session *s, *newest = NULL; - time_t tim; + struct timespec *ts; u_int i; - tim = 0; + ts = NULL; for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { s = ARRAY_ITEM(&sessions, i); if (s == NULL || fnmatch(sname, s->name, 0) != 0) continue; - if (s->tim > tim) { + if (ts == NULL || timespeccmp(&s->ts, ts, >)) { newest = s; - tim = s->tim; + ts = &s->ts; } } @@ -305,7 +306,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *cname, const char *sname) struct client *c; struct msg_command_data *data = ctx->msgdata; u_int i; - time_t tim; + struct timespec *ts; if (cname != NULL) { if ((c = cmd_lookup_client(cname)) == NULL) { @@ -342,12 +343,12 @@ cmd_find_session(struct cmd_ctx *ctx, const char *cname, const char *sname) return (s); } - tim = 0; + ts = NULL; for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { s = ARRAY_ITEM(&sessions, i); - if (s != NULL && s->tim > tim) { + if (s != NULL && (ts == NULL || timespeccmp(&s->ts, ts, >))) { newest = ARRAY_ITEM(&sessions, i); - tim = s->tim; + ts = &s->ts; } } if (newest == NULL) -- cgit