Blame SOURCES/at-3.1.13-usePOSIXtimers.patch

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