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