&& length
&& dcgi_playing->sofar >= 0) {
/* Try to put the next refresh at the start of the next track. */
- time(&now);
+ xtime(&now);
fin = now + length - dcgi_playing->sofar + config->gap;
if(now + refresh > fin)
refresh = fin - now;
#include "mime.h"
#include "sendmail.h"
#include "charset.h"
+#include "syscalls.h"
extern disorder_client *dcgi_client;
extern char *dcgi_cookie;
|| (nsamples > 0
&& contains(pheap_first(&packets), next_timestamp))) {
if(monitor) {
- time_t now = time(0);
+ time_t now = xtime(0);
if(now >= lastlog + 60) {
int offset = nsamples - minbuffer;
gint *timeout) {
const struct eclient_source *esource = (struct eclient_source *)source;
D(("gtkclient_prepare"));
- if(time(0) > esource->last_poll + 10)
+ if(xtime(0) > esource->last_poll + 10)
return TRUE; /* timed out */
*timeout = 3000/*milliseconds*/;
return FALSE; /* please poll */
mode |= DISORDER_POLL_READ;
if(revents & (G_IO_OUT|G_IO_HUP|G_IO_ERR))
mode |= DISORDER_POLL_WRITE;
- time(&esource->last_poll);
+ xtime(&esource->last_poll);
disorder_eclient_polled(esource->client, mode);
return TRUE; /* ??? not documented */
}
else {
if(!last_playing)
return NULL;
- time(&now);
+ xtime(&now);
l = playing_track->sofar + (now - last_playing);
}
byte_xasprintf(&played, "%ld:%02ld/%s", l / 60, l % 60, length);
}
actual_playing_track = q;
queue_playing_changed();
- time(&last_playing);
+ xtime(&last_playing);
}
/** @brief Schedule an update to the queue
#include "hash.h"
#include "mem.h"
#include "log.h"
+#include "syscalls.h"
#include "cache.h"
/** @brief The global cache */
c = xmalloc(sizeof *c);
c->type = type;
c->value = value;
- time(&c->birth);
+ xtime(&c->birth);
hash_add(h, key, c, HASH_INSERT_OR_REPLACE);
}
if(h
&& (c = hash_find(h, key))
&& c->type == type
- && !expired(c, time(0)))
+ && !expired(c, xtime(0)))
return c->value;
else
return 0;
time_t now;
if(h) {
- time(&now);
+ xtime(&now);
hash_foreach(h, expiry_callback, &now);
}
}
#include "configuration.h"
#include "kvp.h"
#include "trackdb.h"
+#include "syscalls.h"
/** @brief Hash function used in signing HMAC */
#define ALGO GCRY_MD_SHA1
static void newkey(void) {
time_t now;
- time(&now);
+ xtime(&now);
memcpy(old_signing_key, signing_key, HASHSIZE);
gcry_randomize(signing_key, HASHSIZE, GCRY_STRONG_RANDOM);
signing_key_validity_limit = now + config->cookie_key_lifetime;
return 0;
}
/* make sure we have a valid signing key */
- time(&now);
+ xtime(&now);
if(now >= signing_key_validity_limit)
newkey();
/* construct the subject */
/* Extract the username */
user = xstrndup(c1 + 1, c2 - (c1 + 1));
/* check expiry */
- time(&now);
+ xtime(&now);
if(now >= t) {
error(0, "cookie has expired");
return 0;
/* Queue up a byte to send */
if(c->state == state_log
&& c->output.nvec == 0
- && time(&now) - c->last_prod > LOG_PROD_INTERVAL) {
+ && xtime(&now) - c->last_prod > LOG_PROD_INTERVAL) {
put(c, "x", 1);
c->last_prod = now;
}
time_t now;
char date[128];
- time(&now);
+ xtime(&now);
gmtime_r(&now, &ut);
strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S +0000", &ut);
gcry_create_nonce(idbuf, sizeof idbuf);
mustnotbeminus1("gettimeofday", gettimeofday(tv, tz));
}
+time_t xtime(time_t *whenp) {
+ struct timeval tv;
+
+ xgettimeofday(&tv, NULL);
+ if(whenp)
+ *whenp = tv.tv_sec;
+ return tv.tv_sec;
+}
+
/*
Local Variables:
c-basic-offset:2
void xfclose(FILE *);
int xnice(int);
void xgettimeofday(struct timeval *, struct timezone *);
+time_t xtime(time_t *when);
/* the above all call @fatal@ if the system call fails */
void nonblock(int fd);
/* this is a real track */
t_changed += kvp_set(&t, "_alias_for", 0);
t_changed += kvp_set(&t, "_path", path);
- time(&now);
+ xtime(&now);
if(ret == DB_NOTFOUND) {
/* It's a new track; record the time */
byte_xasprintf(¬iced, "%lld", (long long)now);
kvp_set(&k, "email", email);
if(confirmation)
kvp_set(&k, "confirmation", confirmation);
- snprintf(s, sizeof s, "%jd", (intmax_t)time(0));
+ snprintf(s, sizeof s, "%jd", (intmax_t)xtime(0));
kvp_set(&k, "created", s);
return trackdb_putdata(trackdb_usersdb, user, k, tid, flags);
}
}
static void test_dateparse(void) {
- time_t now = time(0);
+ time_t now = xtime(0);
check_date(now, "%Y-%m-%d %H:%M:%S", localtime);
#if 0 /* see dateparse.c */
check_date(now, "%Y-%m-%d %H:%M:%S %Z", localtime);
ev_source *ev;
ev = ev_new();
- w.tv_sec = time(0) + 2;
+ w.tv_sec = xtime(0) + 2;
w.tv_usec = 0;
ev_timeout(ev, &t1, &w, callback1, 0);
- w.tv_sec = time(0) + 3;
+ w.tv_sec = xtime(0) + 3;
w.tv_usec = 0;
ev_timeout(ev, &t2, &w, callback2, 0);
- w.tv_sec = time(0) + 4;
+ w.tv_sec = xtime(0) + 4;
w.tv_usec = 0;
ev_timeout(ev, &t3, &w, callback3, 0);
check_integer(ev_run(ev), 1);
struct kvp *prefs) {
const char *s;
char **track_tags;
- time_t last, now = time(0);
+ time_t last, now = xtime(0);
/* Reject tracks not in any collection (race between edit config and
* rescan) */
}
info("process ID %lu", (unsigned long)getpid());
fix_path();
- srand(time(0)); /* don't start the same every time */
+ srand(xtime(0)); /* don't start the same every time */
/* gcrypt initialization */
if(!gcry_check_version(NULL))
disorder_fatal(0, "gcry_check_version failed");
}
/* It's become the playing track */
playing = q;
- time(&playing->played);
+ xtime(&playing->played);
playing->state = playing_started;
notify_play(playing->track, playing->submitter);
eventlog("playing", playing->track,
q = queue_add(config->scratch.s[r], who, WHERE_START, origin_scratch);
}
notify_scratch(playing->track, playing->submitter, who,
- time(0) - playing->played);
+ xtime(0) - playing->played);
}
}
error(0, "player indicates it cannot pause");
return -1;
}
- time(&playing->lastpaused);
+ xtime(&playing->lastpaused);
playing->uptopause = played;
playing->lastresumed = 0;
break;
return;
}
play_resume(playing->pl, playing->data);
- time(&playing->lastresumed);
+ xtime(&playing->lastresumed);
break;
case DISORDER_PLAYER_RAW:
memset(&sm, 0, sizeof sm);
q->origin = origin;
q->pid = -1;
queue_id(q);
- time(&q->when);
+ xtime(&q->when);
switch(where) {
case WHERE_START:
queue_insert_entry(&qhead, q);
if(n < config->player.n) {
nnew += !!trackdb_notice(track, path);
++ntracks;
- if(ntracks % 100 == 0 && time(0) > last_report + 10) {
+ if(ntracks % 100 == 0 && xtime(0) > last_report + 10) {
info("rescanning %s, %ld tracks so far", c->root, ntracks);
- time(&last_report);
+ xtime(&last_report);
}
}
}
return;
recheck_track(&cs, t);
++nrc;
- if(nrc % 100 == 0 && time(0) > last_report + 10) {
+ if(nrc % 100 == 0 && xtime(0) > last_report + 10) {
if(c)
info("rechecking %s, %ld tracks so far", c->root, nrc);
else
info("rechecking all tracks, %ld tracks so far", nrc);
- time(&last_report);
+ xtime(&last_report);
}
}
if(c)
static void expire_noticed(void) {
time_t now;
- time(&now);
+ xtime(&now);
trackdb_expire_noticed(now - config->noticed_history * 86400);
}
}
when.tv_usec = 0;
/* The action might be in the past */
- if(when.tv_sec < time(0)) {
+ if(when.tv_sec < xtime(0)) {
const char *priority = kvp_get(actiondata, "priority");
if(priority && !strcmp(priority, "junk")) {
when.tv_sec = atoll(kvp_get(actiondata, "when"));
when.tv_usec = 0;
/* Reject events in the past */
- if(when.tv_sec <= time(0)) {
+ if(when.tv_sec <= xtime(0)) {
error(0, "new scheduled event is in the past");
return 0;
}
if(q->uptopause == -1) /* Don't know how far thru. */
sofar = -1;
else if(q->lastresumed) /* Has been paused and resumed. */
- sofar = q->uptopause + time(0) - q->lastresumed;
+ sofar = q->uptopause + xtime(0) - q->lastresumed;
else /* Currently paused. */
sofar = q->uptopause;
} else /* Never been paused. */
- sofar = time(0) - q->played;
+ sofar = xtime(0) - q->played;
q->sofar = sofar;
}
}
queue_fix_sofar(playing);
if((l = trackdb_get(playing->track, "_length"))
&& (length = atol(l))) {
- time(&when);
+ xtime(&when);
when += length - playing->sofar + config->gap;
}
} else
/* Nothing is playing but playing is enabled, so whatever is
* first in the queue can be expected to start immediately. */
- time(&when);
+ xtime(&when);
}
for(q = qhead.next; q != &qhead; q = q->next) {
/* fill in estimated start time */
return;
}
sink_printf(ev_writer_sink(c->w), "%"PRIxMAX" %s\n",
- (uintmax_t)time(0), msg);
+ (uintmax_t)xtime(0), msg);
}
static int c_log(struct conn *c,
sink_writes(ev_writer_sink(c->w), "254 OK\n");
/* pump out initial state */
- time(&now);
+ xtime(&now);
sink_printf(ev_writer_sink(c->w), "%"PRIxMAX" state %s\n",
(uintmax_t)now,
playing_is_enabled() ? "enable_play" : "disable_play");
if(d->lo)
sink_printf(ev_writer_sink(d->w),
"%"PRIxMAX" rights_changed %s\n",
- (uintmax_t)time(0),
+ (uintmax_t)xtime(0),
quoteutf8(new_rights));
}
}
if(!last_reminder)
last_reminder = hash_new(sizeof (time_t));
last = hash_find(last_reminder, vec[0]);
- time(&now);
+ xtime(&now);
if(last && now < *last + config->reminder_interval) {
error(0, "sent a password reminder to '%s' too recently", vec[0]);
sink_writes(ev_writer_sink(c->w), "550 Cannot send a reminder email\n");
strcpy(sm.id, playing->id);
sm.data = playing->played / (uaudio_rate * uaudio_channels);
speaker_send(1, &sm);
- time(&last_report);
+ xtime(&last_report);
}
}
}
}
/* If we've not reported our state for a second do so now. */
- if(force_report || time(0) > last_report)
+ if(force_report || xtime(0) > last_report)
report();
}
}