Blame SOURCES/at-3.1.13-usePOSIXtimers.patch

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