Blame SOURCES/at-3.1.14-usePOSIXtimers.patch

d3b522
diff -up at-3.1.14/atd.c.timers at-3.1.14/atd.c
d3b522
--- at-3.1.14/atd.c.timers	2013-12-02 11:03:01.250080057 +0100
d3b522
+++ at-3.1.14/atd.c	2013-12-02 11:06:15.560243498 +0100
d3b522
@@ -831,6 +831,54 @@ run_loop()
d3b522
     return next_job;
d3b522
 }
d3b522
 
d3b522
+#ifdef HAVE_TIMER_CREATE
d3b522
+timer_t timer;
d3b522
+struct itimerspec timeout;
d3b522
+
d3b522
+void timer_setup()
d3b522
+{
d3b522
+    struct sigevent sev;
d3b522
+
d3b522
+    sev.sigev_notify = SIGEV_SIGNAL;
d3b522
+    sev.sigev_signo = SIGHUP;
d3b522
+    sev.sigev_value.sival_ptr = &timer;
d3b522
+
d3b522
+    memset(&timeout, 0, sizeof(timeout));
d3b522
+
d3b522
+    if (timer_create(CLOCK_REALTIME, &sev, &timer) < 0)
d3b522
+           pabort("unable to create timer");
d3b522
+}
d3b522
+
d3b522
+time_t atd_gettime()
d3b522
+{
d3b522
+    struct timespec curtime;
d3b522
+
d3b522
+    clock_gettime(CLOCK_REALTIME, &curtime);
d3b522
+
d3b522
+    return curtime.tv_sec;
d3b522
+}
d3b522
+
d3b522
+void atd_setalarm(time_t next)
d3b522
+{
d3b522
+    timeout.it_value.tv_sec = next;
d3b522
+    timer_settime(timer, TIMER_ABSTIME, &timeout, NULL);
d3b522
+    pause();
d3b522
+}
d3b522
+#else
d3b522
+void timer_setup()
d3b522
+{
d3b522
+}
d3b522
+
d3b522
+time_t atd_gettime()
d3b522
+{
d3b522
+    return time(NULL);
d3b522
+}
d3b522
+
d3b522
+void atd_setalarm(time_t next)
d3b522
+{
d3b522
+    sleep(next - atd_gettime());
d3b522
+}
d3b522
+#endif
d3b522
 /* Global functions */
d3b522
 
d3b522
 int
d3b522
@@ -936,7 +984,7 @@ main(int argc, char *argv[])
d3b522
     sigaction(SIGCHLD, &act, NULL);
d3b522
 
d3b522
     if (!run_as_daemon) {
d3b522
-	now = time(NULL);
d3b522
+	now = atd_gettime();
d3b522
 	run_loop();
d3b522
 	exit(EXIT_SUCCESS);
d3b522
     }
d3b522
@@ -959,13 +1007,14 @@ main(int argc, char *argv[])
d3b522
     act.sa_handler = set_term;
d3b522
     sigaction(SIGINT, &act, NULL);
d3b522
 
d3b522
+    timer_setup();
d3b522
     daemon_setup();
d3b522
 
d3b522
     do {
d3b522
-	now = time(NULL);
d3b522
+	now = atd_gettime();
d3b522
 	next_invocation = run_loop();
d3b522
 	if (next_invocation > now) {
d3b522
-	    sleep(next_invocation - now);
d3b522
+	    atd_setalarm(next_invocation);
d3b522
 	}
d3b522
     } while (!term_signal);
d3b522
     daemon_cleanup();
d3b522
diff -up at-3.1.14/config.h.in.timers at-3.1.14/config.h.in
d3b522
--- at-3.1.14/config.h.in.timers	2013-12-02 11:00:27.000000000 +0100
d3b522
+++ at-3.1.14/config.h.in	2013-12-02 11:02:06.521033976 +0100
d3b522
@@ -38,6 +38,9 @@
d3b522
 /* Define to 1 if you have the `getloadavg' function. */
d3b522
 #undef HAVE_GETLOADAVG
d3b522
 
d3b522
+/* Define to 1 if you have the `timer_create' function. */
d3b522
+#undef HAVE_TIMER_CREATE
d3b522
+
d3b522
 /* Define to 1 if you have the <getopt.h> header file. */
d3b522
 #undef HAVE_GETOPT_H
d3b522
 
d3b522
diff -up at-3.1.14/configure.ac.timers at-3.1.14/configure.ac
d3b522
--- at-3.1.14/configure.ac.timers	2013-12-02 11:00:27.000000000 +0100
d3b522
+++ at-3.1.14/configure.ac	2013-12-02 11:02:45.217066560 +0100
d3b522
@@ -254,6 +254,10 @@ AC_CHECK_LIB(selinux, is_selinux_enabled
d3b522
 AC_SUBST(SELINUXLIB)
d3b522
 AC_SUBST(WITH_SELINUX)
d3b522
 
d3b522
+dnl check for POSIX timer functions
d3b522
+AC_SEARCH_LIBS([timer_create],[rt])
d3b522
+AC_CHECK_FUNCS([timer_create])
d3b522
+
d3b522
 AC_MSG_CHECKING(groupname to run under)
d3b522
 AC_ARG_WITH(daemon_groupname,
d3b522
 [ --with-daemon_groupname=DAEMON_GROUPNAME	Groupname to run under (default daemon) ],