status = camqp_connect (conf);
if (status != 0)
{
- struct timespec ts_interval;
ERROR ("amqp plugin: camqp_connect failed. "
"Will sleep for %.3f seconds.",
CDTIME_T_TO_DOUBLE (interval));
- CDTIME_T_TO_TIMESPEC (interval, &ts_interval);
- nanosleep (&ts_interval, /* remaining = */ NULL);
+ nanosleep (&CDTIME_T_TO_TIMESPEC (interval), /* remaining = */ NULL);
continue;
}
status = amqp_simple_wait_frame (conf->connection, &frame);
if (status < 0)
{
- struct timespec ts_interval;
ERROR ("amqp plugin: amqp_simple_wait_frame failed. "
"Will sleep for %.3f seconds.",
CDTIME_T_TO_DOUBLE (interval));
camqp_close_connection (conf);
- CDTIME_T_TO_TIMESPEC (interval, &ts_interval);
- nanosleep (&ts_interval, /* remaining = */ NULL);
+ nanosleep (&CDTIME_T_TO_TIMESPEC (interval), /* remaining = */ NULL);
continue;
}
while (loop == 0)
{
- struct timespec ts_wait = { 0, 0 };
cdtime_t now;
#if HAVE_LIBKSTAT
continue;
}
- CDTIME_T_TO_TIMESPEC (wait_until - now, &ts_wait);
+ struct timespec ts_wait = CDTIME_T_TO_TIMESPEC (wait_until - now);
wait_until = wait_until + interval;
while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) != 0))
&& (cdtime () < rf->rf_next_read)
&& rc == 0)
{
- struct timespec ts = { 0 };
-
- CDTIME_T_TO_TIMESPEC (rf->rf_next_read, &ts);
-
rc = pthread_cond_timedwait (&read_cond, &read_lock,
- &ts);
+ &CDTIME_T_TO_TIMESPEC (rf->rf_next_read));
}
/* Must hold `read_lock' when accessing `rf->rf_type'. */
static int get_utc_time (cdtime_t t, struct tm *t_tm, long *nsec) /* {{{ */
{
- struct timespec t_spec;
- int status;
-
- CDTIME_T_TO_TIMESPEC (t, &t_spec);
+ struct timespec t_spec = CDTIME_T_TO_TIMESPEC (t);
NORMALIZE_TIMESPEC (t_spec);
if (gmtime_r (&t_spec.tv_sec, t_tm) == NULL) {
char errbuf[1024];
- status = errno;
+ int status = errno;
ERROR ("get_utc_time: gmtime_r failed: %s",
sstrerror (status, errbuf, sizeof (errbuf)));
return status;
static int get_local_time (cdtime_t t, struct tm *t_tm, long *nsec) /* {{{ */
{
- struct timespec t_spec;
- int status;
-
- CDTIME_T_TO_TIMESPEC (t, &t_spec);
+ struct timespec t_spec = CDTIME_T_TO_TIMESPEC (t);
NORMALIZE_TIMESPEC (t_spec);
if (localtime_r (&t_spec.tv_sec, t_tm) == NULL) {
char errbuf[1024];
- status = errno;
+ int status = errno;
ERROR ("get_local_time: localtime_r failed: %s",
sstrerror (status, errbuf, sizeof (errbuf)));
return status;
#define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0)
#define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0))
-#define CDTIME_T_TO_TIMEVAL(cdt,tvp) do { \
- (tvp)->tv_sec = (time_t) ((cdt) >> 30); \
- (tvp)->tv_usec = (suseconds_t) ((((cdt) & 0x3fffffff) * 1000000 + (1 << 29)) >> 30); \
-} while (0)
+#define CDTIME_T_TO_TIMEVAL(t) (struct timeval) { \
+ .tv_sec = (time_t) ((t) >> 30), \
+ .tv_usec = (suseconds_t) ((((t) & 0x3fffffff) * 1000000 + (1 << 29)) >> 30), \
+}
#define TIMEVAL_TO_CDTIME_T(tv) US_TO_CDTIME_T(1000000 * (tv)->tv_sec + (tv)->tv_usec)
-#define CDTIME_T_TO_TIMESPEC(cdt,tsp) do { \
- (tsp)->tv_sec = (time_t) ((cdt) >> 30); \
- (tsp)->tv_nsec = (long) ((((cdt) & 0x3fffffff) * 1000000000 + (1 << 29)) >> 30); \
-} while (0)
+#define CDTIME_T_TO_TIMESPEC(t) (struct timespec) { \
+ .tv_sec = (time_t) ((t) >> 30), \
+ .tv_nsec = (long) ((((t) & 0x3fffffff) * 1000000000 + (1 << 29)) >> 30), \
+}
#define TIMESPEC_TO_CDTIME_T(ts) NS_TO_CDTIME_T(1000000000ULL * (ts)->tv_sec + (ts)->tv_nsec)
cdtime_t cdtime (void);
};
for (size_t i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) {
- struct timeval tv;
- struct timespec ts;
-
// cdtime -> s
EXPECT_EQ_UINT64 (cases[i].tt, CDTIME_T_TO_TIME_T (cases[i].t));
EXPECT_EQ_UINT64(cases[i].ms, CDTIME_T_TO_MS (cases[i].t));
// cdtime -> us
- CDTIME_T_TO_TIMEVAL (cases[i].t, &tv);
+ struct timeval tv = CDTIME_T_TO_TIMEVAL (cases[i].t);
EXPECT_EQ_UINT64 (cases[i].tv.tv_sec, tv.tv_sec);
EXPECT_EQ_UINT64 (cases[i].tv.tv_usec, tv.tv_usec);
// cdtime -> ns
- CDTIME_T_TO_TIMESPEC (cases[i].t, &ts);
+ struct timespec ts = CDTIME_T_TO_TIMESPEC (cases[i].t);
EXPECT_EQ_UINT64 (cases[i].ts.tv_sec, ts.tv_sec);
EXPECT_EQ_UINT64 (cases[i].ts.tv_nsec, ts.tv_nsec);
static int dns_sleep_one_interval (void) /* {{{ */
{
- cdtime_t interval;
- struct timespec ts = { 0, 0 };
- int status = 0;
-
- interval = plugin_get_interval ();
- CDTIME_T_TO_TIMESPEC (interval, &ts);
-
- while (42)
+ struct timespec ts = CDTIME_T_TO_TIMESPEC (plugin_get_interval ());
+ while (nanosleep (&ts, &ts) != 0)
{
- struct timespec rem = { 0, 0 };
-
- status = nanosleep (&ts, &rem);
- if (status == 0)
- break;
- else if ((errno == EINTR) || (errno == EAGAIN))
- {
- ts = rem;
+ if ((errno == EINTR) || (errno == EAGAIN))
continue;
- }
- else
- break;
+
+ return (errno);
}
- return (status);
+ return (0);
} /* }}} int dns_sleep_one_interval */
static void *dns_child_loop (__attribute__((unused)) void *dummy) /* {{{ */
while (1) {
/* sem_timedwait() to avoid blocking forever */
- struct timespec ts;
cdtime_t now = cdtime();
cdtime_t safety_period = MS_TO_CDTIME_T(1500);
- CDTIME_T_TO_TIMESPEC(now + safety_period + g_configuration->interval * 2,
- &ts);
- int ret = sem_timedwait(&g_configuration->sema_helper_get_stats, &ts);
+ int ret =
+ sem_timedwait(&g_configuration->sema_helper_get_stats,
+ &CDTIME_T_TO_TIMESPEC(now + safety_period +
+ g_configuration->interval * 2));
if (ret == -1 && errno == ETIMEDOUT) {
ERROR("dpdkstat-helper: sem timedwait()"
vl.values_len = 1; /* Submit stats one at a time */
vl.time = port_read_time;
sstrncpy(vl.plugin, "dpdkstat", sizeof(vl.plugin));
- sstrncpy(vl.plugin_instance, dev_name,
- sizeof(vl.plugin_instance));
+ sstrncpy(vl.plugin_instance, dev_name, sizeof(vl.plugin_instance));
type_end = strrchr(xstats[j].name, '_');
sstrncpy(vl.type, "derive", sizeof(vl.type));
}
- sstrncpy(vl.type_instance, xstats[j].name,
- sizeof(vl.type_instance));
+ sstrncpy(vl.type_instance, xstats[j].name, sizeof(vl.type_instance));
plugin_dispatch_values(&vl);
}
}
/* Kick helper process through SHM */
sem_post(&g_configuration->sema_helper_get_stats);
- struct timespec ts;
cdtime_t now = cdtime();
- CDTIME_T_TO_TIMESPEC(now + g_configuration->interval, &ts);
- ret = sem_timedwait(&g_configuration->sema_stats_in_shm, &ts);
+ ret = sem_timedwait(&g_configuration->sema_stats_in_shm,
+ &CDTIME_T_TO_TIMESPEC(now + g_configuration->interval));
if (ret == -1) {
if (errno == ETIMEDOUT)
DEBUG(
struct sockaddr_un sa_unix = { 0 };
- struct timeval stv_timeout;
cdtime_t cdt_timeout;
sd = socket (PF_UNIX, item->socktype, 0);
if (cdt_timeout < TIME_T_TO_CDTIME_T (2))
cdt_timeout = TIME_T_TO_CDTIME_T (2);
- CDTIME_T_TO_TIMEVAL (cdt_timeout, &stv_timeout);
-
- status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &stv_timeout, sizeof (stv_timeout));
+ status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO,
+ &CDTIME_T_TO_TIMEVAL(cdt_timeout),
+ sizeof(struct timeval));
if (status != 0)
{
SOCK_ERROR ("setsockopt", sa_unix.sun_path);