CPPFLAGS += -I$(cmdline_dir)
CPPFLAGS += @osl_cppflags@
+LDFLAGS += @clock_gettime_ldflags@
+
man_pages := $(patsubst %, $(man_dir)/%.1, @executables@)
autocrap := config.h.in configure
/** \file afh.c Paraslash's standalone audio format handler tool. */
#include <regex.h>
-#include <sys/time.h>
#include "para.h"
#include "string.h"
/** \file afh_common.c Common audio format handler functions. */
#include <sys/mman.h> /* mmap */
-#include <sys/time.h> /* gettimeofday */
#include <sys/types.h>
#include <regex.h>
#include <regex.h>
#include <sys/types.h>
#include <alsa/asoundlib.h>
-#include <sys/time.h>
#include "para.h"
#include "fd.h"
#include <regex.h>
#include <signal.h>
-#include <sys/time.h>
#include <sys/types.h>
#include <osl.h>
localtime_r(&nmmd->mtime, &mtime_tm);
strftime(mtime, 29, "%b %d %Y", &mtime_tm);
}
- gettimeofday(¤t_time, NULL);
+ clock_get_realtime(¤t_time);
/*
* The calls to WRITE_STATUS_ITEM() below never fail because
* b->max_size is zero (unlimited), see para_printf(). However, clang
AC_MSG_ERROR([fatal: buggy snprintf() detected])
fi])
AX_FUNC_SNPRINTF()
+################################################################## clock_gettime
+clock_gettime_lib=
+AC_CHECK_LIB([c], [clock_gettime], [clock_gettime_lib=c], [
+ AC_CHECK_LIB([rt], [clock_gettime], [clock_gettime_lib=rt], [], [])
+])
+if test -n "$clock_gettime_lib"; then
+ AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [
+ define to 1 if clock_gettime() is supported])
+fi
+if test "$clock_gettime_lib" = "rt"; then
+ AC_SUBST(clock_gettime_ldflags, -lrt)
+fi
########################################################################### osl
have_osl=yes
OLD_CPPFLAGS="$CPPFLAGS"
#include <pwd.h>
#include <sys/types.h> /* getgrnam() */
#include <grp.h>
-#include <sys/time.h>
#include <signal.h>
#include "para.h"
fprintf(fp, "%s", color);
if (log_time || log_timing) {
struct timeval tv;
- gettimeofday(&tv, NULL);
+ clock_get_realtime(&tv);
if (daemon_test_flag(DF_LOG_TIME)) { /* print date and time */
time_t t1 = tv.tv_sec;
char str[100];
#include <regex.h>
#include <sys/types.h>
-#include <sys/time.h>
#include "para.h"
#include "list.h"
__must_check __malloc static char *random_filename(void)
{
char *result, *home = para_homedir();
- struct timeval tv;
- gettimeofday(&tv, NULL);
- srandom(tv.tv_usec);
+ srandom(clock_get_realtime(NULL)->tv_usec);
result = make_message("%s/.paraslash/%08lu", home,
para_random(99999999));
free(home);
void compute_chunk_time(long unsigned chunk_num,
struct timeval *chunk_tv, struct timeval *stream_start,
struct timeval *result);
+struct timeval *clock_get_realtime(struct timeval *tv);
/** The enum of all status items. */
enum status_items {STATUS_ITEM_ENUM NUM_STAT_ITEMS};
/** \file play.c Paraslash's standalone player. */
#include <regex.h>
-#include <sys/time.h>
#include <fnmatch.h>
#include <signal.h>
filter_init();
writer_init();
- gettimeofday(now, NULL);
+ clock_get_realtime(now);
sched.default_timeout.tv_sec = 5;
parse_config_or_die(argc, argv);
#include <regex.h>
#include <assert.h>
-#include <sys/time.h>
#include "para.h"
#include "ipc.h"
struct timeval t1, t2, diff;
unsigned long pst;
- gettimeofday(&t1, NULL);
+ clock_get_realtime(&t1);
t->post_select(s, t);
- gettimeofday(&t2, NULL);
+ clock_get_realtime(&t2);
tv_diff(&t1, &t2, &diff);
pst = tv2ms(&diff);
if (pst > 50)
FD_ZERO(&s->wfds);
s->select_timeout = s->default_timeout;
s->max_fileno = -1;
- gettimeofday(now, NULL);
+ clock_get_realtime(now);
sched_preselect(s);
ret = s->select_function(s->max_fileno + 1, &s->rfds, &s->wfds,
&s->select_timeout);
FD_ZERO(&s->rfds);
FD_ZERO(&s->wfds);
}
- gettimeofday(now, NULL);
+ clock_get_realtime(now);
sched_post_select(s);
if (list_empty(&s->pre_select_list) && list_empty(&s->post_select_list))
return 0;
* This is set by the scheduler at the beginning of its main loop. It may be
* used (read-only) from everywhere. As none of the functions called by the
* scheduler are allowed to block, this value should be accurate enough so that
- * there is no need to call gettimeofday() directly.
+ * there is no need to call clock_gettime() directly.
*/
extern struct timeval *now;
*/
#include <signal.h>
-#include <sys/time.h>
#include <regex.h>
#include <osl.h>
log_welcome("para_server");
init_ipc_or_die(); /* init mmd struct and mmd->lock */
/* make sure, the global now pointer is uptodate */
- gettimeofday(now, NULL);
+ clock_get_realtime(now);
set_server_start_time(now);
init_user_list(user_list_file);
/* become daemon */
/** \file string.c Memory allocation and string handling functions. */
-#include <sys/time.h> /* gettimeofday */
#include <pwd.h>
#include <sys/utsname.h> /* uname() */
#include <string.h>
tv_scale(chunk_num, chunk_tv, &tmp);
tv_add(&tmp, stream_start, result);
}
+
+/**
+ * Retrieve the time of the realtime clock.
+ *
+ * \param tv Where to store the result.
+ *
+ * Gets the current value of the system-wide real-time clock (identified by id
+ * \p CLOCK_REALTIME). If \a tv is \p NULL, the value is stored in a static
+ * buffer, otherwise it is stored at the location given by \a tv.
+ *
+ * \return This function aborts on errors. On success it returns a pointer to
+ * memory containing the current time.
+ *
+ * \sa clock_gettime(2), gettimeofday(2).
+ */
+struct timeval *clock_get_realtime(struct timeval *tv)
+{
+ static struct timeval user_friendly;
+
+ if (!tv)
+ tv = &user_friendly;
+#ifdef HAVE_CLOCK_GETTIME
+ {
+ struct timespec t;
+ int ret;
+
+ ret = clock_gettime(CLOCK_REALTIME, &t);
+ assert(ret == 0);
+ tv->tv_sec = t.tv_sec;
+ tv->tv_usec = t.tv_nsec / 1000;
+ }
+#else
+ #include <sys/time.h>
+ gettimeofday(tv, NULL);
+#endif /* HAVE_CLOCK_GETTIME */
+ return tv;
+}
#include <regex.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/udp.h>
#include <net/if.h>
#define _XOPEN_SOURCE 600
-#include <sys/time.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>