summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-07-15 05:10:13 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-07-15 05:10:13 +0000
commit35c43011c8305b4fdcd5d86da82f4a2e10046048 (patch)
tree572de23cd03e4272e456df008d3004db509c39a4
parentad17f7a16a3b9364bc4fe8114510203c48d87696 (diff)
fix time differencies computations (orig from alan@parsys.co.uk, but
don't use difftime(3), it returns double) use <sys/queue.h> for queue maintanance
-rw-r--r--libexec/talkd/table.c51
-rw-r--r--libexec/talkd/talkd.c5
-rw-r--r--libexec/talkd/talkd.h3
3 files changed, 29 insertions, 30 deletions
diff --git a/libexec/talkd/table.c b/libexec/talkd/table.c
index 50a21728aa3..f007a7c54c4 100644
--- a/libexec/talkd/table.c
+++ b/libexec/talkd/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.2 1996/04/28 23:56:20 mickey Exp $ */
+/* $OpenBSD: table.c,v 1.3 1996/07/15 05:10:11 mickey Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -35,7 +35,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)table.c 5.7 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: table.c,v 1.2 1996/04/28 23:56:20 mickey Exp $";
+static char rcsid[] = "$Id: table.c,v 1.3 1996/07/15 05:10:11 mickey Exp $";
#endif /* not lint */
/*
@@ -49,6 +49,7 @@ static char rcsid[] = "$Id: table.c,v 1.2 1996/04/28 23:56:20 mickey Exp $";
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
+#include <sys/queue.h>
#include <protocols/talkd.h>
#include <syslog.h>
#include <unistd.h>
@@ -59,8 +60,6 @@ static char rcsid[] = "$Id: table.c,v 1.2 1996/04/28 23:56:20 mickey Exp $";
#define MAX_ID 16000 /* << 2^15 so I don't have sign troubles */
-#define NIL ((TABLE_ENTRY *)0)
-
struct timeval tp;
struct timezone txp;
@@ -68,15 +67,23 @@ typedef struct table_entry TABLE_ENTRY;
struct table_entry {
CTL_MSG request;
- long time;
- TABLE_ENTRY *next;
- TABLE_ENTRY *last;
+ time_t time;
+ TAILQ_ENTRY(table_entry) list;
};
-TABLE_ENTRY *table = NIL;
+TAILQ_HEAD(, table_entry) table;
static void delete __P((register TABLE_ENTRY *));
/*
+ * Init the table
+ */
+void
+init_table()
+{
+ TAILQ_INIT(&table);
+}
+
+/*
* Look in the table for an invitation that matches the current
* request looking for an invitation
*/
@@ -91,8 +98,8 @@ find_match(request)
current_time = tp.tv_sec;
if (debug)
print_request("find_match", request);
- for (ptr = table; ptr != NIL; ptr = ptr->next) {
- if ((ptr->time - current_time) > MAX_LIFE) {
+ for (ptr = table.tqh_first; ptr != NULL; ptr = ptr->list.tqe_next) {
+ if ((current_time - ptr->time) > MAX_LIFE) {
/* the entry is too old */
if (debug)
print_request("deleting expired entry",
@@ -132,8 +139,8 @@ find_request(request)
*/
if (debug)
print_request("find_request", request);
- for (ptr = table; ptr != NIL; ptr = ptr->next) {
- if ((ptr->time - current_time) > MAX_LIFE) {
+ for (ptr = table.tqh_first; ptr != NULL; ptr = ptr->list.tqe_next) {
+ if ((current_time - ptr->time) > MAX_LIFE) {
/* the entry is too old */
if (debug)
print_request("deleting expired entry",
@@ -171,17 +178,13 @@ insert_table(request, response)
response->id_num = htonl(request->id_num);
/* insert a new entry into the top of the list */
ptr = (TABLE_ENTRY *)malloc(sizeof(TABLE_ENTRY));
- if (ptr == NIL) {
+ if (ptr == NULL) {
syslog(LOG_ERR, "insert_table: Out of memory");
_exit(1);
}
ptr->time = current_time;
ptr->request = *request;
- ptr->next = table;
- if (ptr->next != NIL)
- ptr->next->last = ptr;
- ptr->last = NIL;
- table = ptr;
+ TAILQ_INSERT_HEAD(&table, ptr, list);
}
/*
@@ -208,16 +211,15 @@ delete_invite(id_num)
{
register TABLE_ENTRY *ptr;
- ptr = table;
if (debug)
syslog(LOG_DEBUG, "delete_invite(%d)", id_num);
- for (ptr = table; ptr != NIL; ptr = ptr->next) {
+ for (ptr = table.tqh_first; ptr != NULL; ptr = ptr->list.tqe_next) {
if (ptr->request.id_num == id_num)
break;
if (debug)
print_request("", &ptr->request);
}
- if (ptr != NIL) {
+ if (ptr != NULL) {
delete(ptr);
return (SUCCESS);
}
@@ -234,11 +236,6 @@ delete(ptr)
if (debug)
print_request("delete", &ptr->request);
- if (table == ptr)
- table = ptr->next;
- else if (ptr->last != NIL)
- ptr->last->next = ptr->next;
- if (ptr->next != NIL)
- ptr->next->last = ptr->last;
+ TAILQ_REMOVE(&table, ptr, list);
free((char *)ptr);
}
diff --git a/libexec/talkd/talkd.c b/libexec/talkd/talkd.c
index fbeee46df40..eecec53f9c0 100644
--- a/libexec/talkd/talkd.c
+++ b/libexec/talkd/talkd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: talkd.c,v 1.2 1996/04/28 23:56:22 mickey Exp $ */
+/* $OpenBSD: talkd.c,v 1.3 1996/07/15 05:10:12 mickey Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -41,7 +41,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)talkd.c 5.8 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: talkd.c,v 1.2 1996/04/28 23:56:22 mickey Exp $";
+static char rcsid[] = "$Id: talkd.c,v 1.3 1996/07/15 05:10:12 mickey Exp $";
#endif /* not lint */
/*
@@ -93,6 +93,7 @@ main(argc, argv)
}
if (argc > 1 && strcmp(argv[1], "-d") == 0)
debug = 1;
+ init_table();
signal(SIGALRM, timeout);
alarm(TIMEOUT);
for (;;) {
diff --git a/libexec/talkd/talkd.h b/libexec/talkd/talkd.h
index 0ff2ea1259b..283f21bc01f 100644
--- a/libexec/talkd/talkd.h
+++ b/libexec/talkd/talkd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: talkd.h,v 1.1 1996/04/28 23:57:46 mickey Exp $ */
+/* $OpenBSD: talkd.h,v 1.2 1996/07/15 05:10:12 mickey Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@@ -38,6 +38,7 @@ extern int debug;
extern char hostname[];
/* table.c */
+void init_table __P((void));
CTL_MSG *find_request __P((CTL_MSG *));
CTL_MSG *find_match __P((CTL_MSG *));
void insert_table __P((CTL_MSG *, CTL_RESPONSE *));