Blame SOURCES/at-3.1.13-usePOSIXtimers.patch

66f700
diff -ur -x configure at-3.1.13.orig/atd.c at-3.1.13/atd.c
66f700
--- at-3.1.13.orig/atd.c	2011-11-16 11:30:22.424764253 -0500
66f700
+++ at-3.1.13/atd.c	2011-11-16 16:41:12.102831656 -0500
66f700
@@ -815,6 +815,54 @@
66f700
     return next_job;
66f700
 }
66f700
 
66f700
+#ifdef HAVE_CLOCK_GETTIME
66f700
+timer_t timer;
66f700
+struct itimerspec timeout;
66f700
+
66f700
+void timer_setup()
66f700
+{
66f700
+    struct sigevent sev;
66f700
+
66f700
+    sev.sigev_notify = SIGEV_SIGNAL;
66f700
+    sev.sigev_signo = SIGHUP;
66f700
+    sev.sigev_value.sival_ptr = &timer;
66f700
+
66f700
+    memset(&timeout, 0, sizeof(timeout));
66f700
+
66f700
+    if (timer_create(CLOCK_REALTIME, &sev, &timer) < 0)
66f700
+	    pabort("unable to create timer");
66f700
+}
66f700
+
66f700
+time_t atd_gettime()
66f700
+{
66f700
+    struct timespec curtime;
66f700
+
66f700
+    clock_gettime(CLOCK_REALTIME, &curtime);
66f700
+
66f700
+    return curtime.tv_sec;
66f700
+}
66f700
+
66f700
+void atd_setalarm(time_t next)
66f700
+{
66f700
+    timeout.it_value.tv_sec = next;
66f700
+    timer_settime(timer, TIMER_ABSTIME, &timeout, NULL);
66f700
+    pause();
66f700
+}
66f700
+#else
66f700
+void timer_setup()
66f700
+{
66f700
+}
66f700
+
66f700
+time_t atd_gettime()
66f700
+{
66f700
+    return time(NULL);
66f700
+}
66f700
+
66f700
+void atd_setalarm(time_t next)
66f700
+{
66f700
+    sleep(next - atd_gettime());
66f700
+}
66f700
+#endif
66f700
 /* Global functions */
66f700
 
66f700
 int
66f700
@@ -835,7 +883,6 @@
66f700
     struct sigaction act;
66f700
     struct passwd *pwe;
66f700
     struct group *ge;
66f700
-
66f700
 #ifdef WITH_SELINUX
66f700
     selinux_enabled=is_selinux_enabled();
66f700
 #endif
66f700
@@ -912,7 +959,7 @@
66f700
     sigaction(SIGCHLD, &act, NULL);
66f700
 
66f700
     if (!run_as_daemon) {
66f700
-	now = time(NULL);
66f700
+	now = atd_gettime();
66f700
 	run_loop();
66f700
 	exit(EXIT_SUCCESS);
66f700
     }
66f700
@@ -935,13 +982,15 @@
66f700
     act.sa_handler = set_term;
66f700
     sigaction(SIGINT, &act, NULL);
66f700
 
66f700
+    timer_setup();
66f700
+
66f700
     daemon_setup();
66f700
 
66f700
     do {
66f700
-	now = time(NULL);
66f700
+	now = atd_gettime();
66f700
 	next_invocation = run_loop();
66f700
 	if (next_invocation > now) {
66f700
-	    sleep(next_invocation - now);
66f700
+	    atd_setalarm(next_invocation);
66f700
 	}
66f700
     } while (!term_signal);
66f700
     daemon_cleanup();
66f700
diff -ur -x configure at-3.1.13.orig/config.h.in at-3.1.13/config.h.in
66f700
--- at-3.1.13.orig/config.h.in	2011-11-16 11:30:22.424764253 -0500
66f700
+++ at-3.1.13/config.h.in	2011-11-16 16:32:44.485426754 -0500
66f700
@@ -38,6 +38,9 @@
66f700
 /* Define to 1 if you have the `getloadavg' function. */
66f700
 #undef HAVE_GETLOADAVG
66f700
 
66f700
+/* Define to 1 if you have the `clock_gettime' function. */
66f700
+#undef HAVE_TIMER_CREATE
66f700
+
66f700
 /* Define to 1 if you have the <getopt.h> header file. */
66f700
 #undef HAVE_GETOPT_H
66f700
 
66f700
diff -ur -x configure at-3.1.13.orig/configure.ac at-3.1.13/configure.ac
66f700
--- at-3.1.13.orig/configure.ac	2011-11-16 11:30:22.425764254 -0500
66f700
+++ at-3.1.13/configure.ac	2011-11-16 16:31:29.791561747 -0500
66f700
@@ -274,5 +274,9 @@
66f700
 AC_SUBST(SELINUXLIB)
66f700
 AC_SUBST(WITH_SELINUX)
66f700
 
66f700
+dnl check for POSIX timer functions
66f700
+AC_SEARCH_LIBS([timer_create],[rt])
66f700
+AC_CHECK_FUNCS([timer_create])
66f700
+
66f700
 AC_CONFIG_FILES(Makefile atrun atd.8 atrun.8 at.1 at.allow.5 batch)
66f700
 AC_OUTPUT