SUBDIRS = libopm
bin_PROGRAMS = hopm
-AM_CPPFLAGS = -DHOPM_PREFIX="\"$(prefix)\"" -DHOPM_ETCDIR="\"$(sysconfdir)\"" -DHOPM_LOGDIR="\"$(localstatedir)/log\"" -DHOPM_BINPATH="\"$(bindir)/hopm\""
+AM_CPPFLAGS = -DHOPM_PREFIX="\"$(prefix)\"" -DHOPM_ETCDIR="\"$(sysconfdir)\"" -DHOPM_LOGDIR="\"$(localstatedir)/log\"" -DHOPM_BINPATH="\"$(bindir)/hopm\"" -I$(top_srcdir)/src/libopm/src/
AM_YFLAGS = -d
hopm_SOURCES = compat.c \
#include "list.h"
#include "log.h"
#include "dnsbl.h"
+#include "opm_gettime.h"
#define FIREDNS_TRIES 3
return -1;
}
- time(&s->start);
+ s->start = opm_gettime();
firedns_fdinuse++;
firedns_errno = FDNS_ERR_NONE;
if (ufds == NULL)
ufds = xcalloc(sizeof(*ufds) * OptionsItem.dns_fdlimit);
- time(&timenow);
+ timenow = opm_gettime();
LIST_FOREACH_SAFE(node, node_next, CONNECTIONS.head)
{
#include "negcache.h"
#include "memory.h"
#include "main.h"
+#include "opm_gettime.h"
/*
static void
irc_connect(void)
{
- time_t present;
-
- time(&present);
-
/* Only try to reconnect every IRCItem.reconnectinterval seconds */
- if ((present - IRC_LASTRECONNECT) < IRCItem.reconnectinterval)
+ if ((opm_gettime() - IRC_LASTRECONNECT) < IRCItem.reconnectinterval)
{
/* Sleep to avoid excessive CPU */
sleep(1);
return;
}
- time(&IRC_LASTRECONNECT);
- time(&IRC_LAST);
+ IRC_LASTRECONNECT =
+ IRC_LAST = opm_gettime();
irc_init();
IRCItem.username,
IRCItem.username,
IRCItem.realname);
- time(&IRC_LAST);
+ IRC_LAST = opm_gettime();
}
/* irc_parse
if (OPT_DEBUG >= 2)
log_printf("IRC READ -> %s", IRC_RAW);
- time(&IRC_LAST);
+ IRC_LAST = opm_gettime();
/* Store a copy of IRC_RAW for the handlers (for functions that need PROOF) */
strlcpy(msg, IRC_RAW, sizeof(msg));
void
irc_timer(void)
{
- time_t present, delta;
-
- time(&present);
-
- delta = present - IRC_LAST;
+ time_t delta = opm_gettime() - IRC_LAST;
/* No data in IRCItem.readtimeout seconds */
if (delta >= IRCItem.readtimeout)
irc_close();
/* Make sure we don't do this again for a while */
- time(&IRC_LAST);
+ IRC_LAST = opm_gettime();
}
else if (delta >= IRCItem.readtimeout / 2)
{
noinst_LTLIBRARIES = libopm.la
-libopm_la_SOURCES = config.c \
- config.h \
- libopm.c \
- libopm.h \
- list.c \
- list.h \
- memory.c \
- memory.h \
- opm_common.h \
- opm_error.h \
- opm.h \
- opm_types.h \
- proxy.c \
+libopm_la_SOURCES = config.c \
+ config.h \
+ libopm.c \
+ libopm.h \
+ list.c \
+ list.h \
+ memory.c \
+ memory.h \
+ opm_common.h \
+ opm_error.h \
+ opm.h \
+ opm_gettime.c \
+ opm_gettime.h \
+ opm_types.h \
+ proxy.c \
proxy.h
libopm_la_LIBADD = @LTLIBOBJS@
#include "opm_error.h"
#include "opm_types.h"
#include "opm_common.h"
+#include "opm_gettime.h"
#include "list.h"
#include "proxy.h"
if (LIST_SIZE(&scanner->scans) == 0)
return;
- time(&present);
+ present = opm_gettime();
timeout = *(int *)libopm_config(scanner->config, OPM_CONFIG_TIMEOUT);
LIST_FOREACH_SAFE(node1, next1, scanner->scans.head)
#endif
conn->state = OPM_STATE_ESTABLISHED;
- time(&conn->creation); /* Stamp creation time, for timeout */
+ conn->creation = opm_gettime(); /* Stamp creation time, for timeout */
}
/* check_poll
--- /dev/null
+/*
+ * Copyright (c) 2014-2021 ircd-hybrid development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include <stdlib.h>
+
+#include "opm_gettime.h"
+
+time_t
+opm_gettime(void)
+{
+ struct timespec ts;
+
+#ifdef CLOCK_MONOTONIC_RAW
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts) == 0)
+#elif CLOCK_MONOTONIC
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
+#else
+ if (clock_gettime(CLOCK_REALTIME, &ts) == 0)
+#endif
+ return ts.tv_sec;
+
+ exit(EXIT_FAILURE);
+ return -1;
+}
--- /dev/null
+/*
+ * Copyright (c) 2014-2021 ircd-hybrid development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#ifndef OPM_GETTIME_H
+#define OPM_GETTIME_H
+
+#include <time.h>
+
+extern time_t opm_gettime(void);
+#endif
+
#include "config.h"
#include "memory.h"
#include "log.h"
+#include "opm_gettime.h"
extern unsigned int OPT_DEBUG;
{
struct negcache_item *n = pnode->data;
- if (time(NULL) - n->seen <= OptionsItem.negcache)
+ if (opm_gettime() - n->seen <= OptionsItem.negcache)
return n;
}
return; /* Malformed IP address or already added to the trie */
struct negcache_item *n = xcalloc(sizeof(*n));
- n->seen = time(NULL);
+ n->seen = opm_gettime();
pnode->data = n;
list_add(pnode, &n->node, &negcache_list);
negcache_rebuild(void)
{
node_t *node, *node_next;
+ time_t present = opm_gettime();
LIST_FOREACH_SAFE(node, node_next, negcache_list.head)
{
patricia_node_t *pnode = node->data;
struct negcache_item *n = pnode->data;
- if (n->seen + OptionsItem.negcache < time(NULL))
+ if (n->seen + OptionsItem.negcache < present)
{
if (OPT_DEBUG >= 2)
log_printf("NEGCACHE -> Deleting expired negcache node for %s added at %lu",
#include "scan.h"
#include "memory.h"
#include "stats.h"
+#include "opm_gettime.h"
static list_t COMMANDS; /* List of active commands */
command->tab = tab;
command->irc_nick = xstrdup(irc_nick);
command->target = target;
-
- time(&command->added);
+ command->added = opm_gettime();
return command;
}
{
static unsigned int interval;
node_t *node, *node_next;
- time_t present;
+ time_t present = opm_gettime();
/* Only perform command removal every OptionsItem.command_interval seconds */
if (interval++ < OptionsItem.command_interval)
else
interval = 0;
- time(&present);
-
LIST_FOREACH_SAFE(node, node_next, COMMANDS.head)
{
struct Command *command = node->data;
#include "misc.h"
#include "config.h"
#include "stats.h"
-#include "libopm/src/opm_types.h"
+#include "opm_types.h"
+#include "opm_gettime.h"
static time_t STATS_UPTIME;
static unsigned int STATS_CONNECTIONS;
void
stats_init(void)
{
- time(&STATS_UPTIME);
+ STATS_UPTIME = opm_gettime();
}
/* stats_openproxy
void
stats_output(const char *target)
{
- time_t present;
- time_t uptime;
+ time_t uptime = opm_gettime() - STATS_UPTIME;
node_t *p;
- time(&present);
- uptime = present - STATS_UPTIME;
-
irc_send("PRIVMSG %s :Uptime: %s", target, time_dissect(uptime));
LIST_FOREACH(p, OpmItem.blacklists.head)