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