Blame SOURCES/at-3.1.14-usePOSIXtimers.patch

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