You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
2.8 KiB

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