|
|
6927e7 |
diff -up at-3.1.14/atd.c.timers at-3.1.14/atd.c
|
|
|
6927e7 |
--- at-3.1.14/atd.c.timers 2013-12-02 11:03:01.250080057 +0100
|
|
|
6927e7 |
+++ at-3.1.14/atd.c 2013-12-02 11:06:15.560243498 +0100
|
|
|
6927e7 |
@@ -831,6 +831,54 @@ run_loop()
|
|
|
6927e7 |
return next_job;
|
|
|
6927e7 |
}
|
|
|
6927e7 |
|
|
|
6927e7 |
+#ifdef HAVE_TIMER_CREATE
|
|
|
6927e7 |
+timer_t timer;
|
|
|
6927e7 |
+struct itimerspec timeout;
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+void timer_setup()
|
|
|
6927e7 |
+{
|
|
|
6927e7 |
+ struct sigevent sev;
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+ sev.sigev_notify = SIGEV_SIGNAL;
|
|
|
6927e7 |
+ sev.sigev_signo = SIGHUP;
|
|
|
6927e7 |
+ sev.sigev_value.sival_ptr = &timer;
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+ memset(&timeout, 0, sizeof(timeout));
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+ if (timer_create(CLOCK_REALTIME, &sev, &timer) < 0)
|
|
|
6927e7 |
+ pabort("unable to create timer");
|
|
|
6927e7 |
+}
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+time_t atd_gettime()
|
|
|
6927e7 |
+{
|
|
|
6927e7 |
+ struct timespec curtime;
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+ clock_gettime(CLOCK_REALTIME, &curtime);
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+ return curtime.tv_sec;
|
|
|
6927e7 |
+}
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+void atd_setalarm(time_t next)
|
|
|
6927e7 |
+{
|
|
|
6927e7 |
+ timeout.it_value.tv_sec = next;
|
|
|
6927e7 |
+ timer_settime(timer, TIMER_ABSTIME, &timeout, NULL);
|
|
|
6927e7 |
+ pause();
|
|
|
6927e7 |
+}
|
|
|
6927e7 |
+#else
|
|
|
6927e7 |
+void timer_setup()
|
|
|
6927e7 |
+{
|
|
|
6927e7 |
+}
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+time_t atd_gettime()
|
|
|
6927e7 |
+{
|
|
|
6927e7 |
+ return time(NULL);
|
|
|
6927e7 |
+}
|
|
|
6927e7 |
+
|
|
|
6927e7 |
+void atd_setalarm(time_t next)
|
|
|
6927e7 |
+{
|
|
|
6927e7 |
+ sleep(next - atd_gettime());
|
|
|
6927e7 |
+}
|
|
|
6927e7 |
+#endif
|
|
|
6927e7 |
/* Global functions */
|
|
|
6927e7 |
|
|
|
6927e7 |
int
|
|
|
6927e7 |
@@ -936,7 +984,7 @@ main(int argc, char *argv[])
|
|
|
6927e7 |
sigaction(SIGCHLD, &act, NULL);
|
|
|
6927e7 |
|
|
|
6927e7 |
if (!run_as_daemon) {
|
|
|
6927e7 |
- now = time(NULL);
|
|
|
6927e7 |
+ now = atd_gettime();
|
|
|
6927e7 |
run_loop();
|
|
|
6927e7 |
exit(EXIT_SUCCESS);
|
|
|
6927e7 |
}
|
|
|
6927e7 |
@@ -959,13 +1007,14 @@ main(int argc, char *argv[])
|
|
|
6927e7 |
act.sa_handler = set_term;
|
|
|
6927e7 |
sigaction(SIGINT, &act, NULL);
|
|
|
6927e7 |
|
|
|
6927e7 |
+ timer_setup();
|
|
|
6927e7 |
daemon_setup();
|
|
|
6927e7 |
|
|
|
6927e7 |
do {
|
|
|
6927e7 |
- now = time(NULL);
|
|
|
6927e7 |
+ now = atd_gettime();
|
|
|
6927e7 |
next_invocation = run_loop();
|
|
|
6927e7 |
if (next_invocation > now) {
|
|
|
6927e7 |
- sleep(next_invocation - now);
|
|
|
6927e7 |
+ atd_setalarm(next_invocation);
|
|
|
6927e7 |
}
|
|
|
6927e7 |
} while (!term_signal);
|
|
|
6927e7 |
daemon_cleanup();
|
|
|
6927e7 |
diff -up at-3.1.14/config.h.in.timers at-3.1.14/config.h.in
|
|
|
6927e7 |
--- at-3.1.14/config.h.in.timers 2013-12-02 11:00:27.000000000 +0100
|
|
|
6927e7 |
+++ at-3.1.14/config.h.in 2013-12-02 11:02:06.521033976 +0100
|
|
|
6927e7 |
@@ -38,6 +38,9 @@
|
|
|
6927e7 |
/* Define to 1 if you have the `getloadavg' function. */
|
|
|
6927e7 |
#undef HAVE_GETLOADAVG
|
|
|
6927e7 |
|
|
|
6927e7 |
+/* Define to 1 if you have the `timer_create' function. */
|
|
|
6927e7 |
+#undef HAVE_TIMER_CREATE
|
|
|
6927e7 |
+
|
|
|
6927e7 |
/* Define to 1 if you have the <getopt.h> header file. */
|
|
|
6927e7 |
#undef HAVE_GETOPT_H
|
|
|
6927e7 |
|
|
|
6927e7 |
diff -up at-3.1.14/configure.ac.timers at-3.1.14/configure.ac
|
|
|
6927e7 |
--- at-3.1.14/configure.ac.timers 2013-12-02 11:00:27.000000000 +0100
|
|
|
6927e7 |
+++ at-3.1.14/configure.ac 2013-12-02 11:02:45.217066560 +0100
|
|
|
6927e7 |
@@ -254,6 +254,10 @@ AC_CHECK_LIB(selinux, is_selinux_enabled
|
|
|
6927e7 |
AC_SUBST(SELINUXLIB)
|
|
|
6927e7 |
AC_SUBST(WITH_SELINUX)
|
|
|
6927e7 |
|
|
|
6927e7 |
+dnl check for POSIX timer functions
|
|
|
6927e7 |
+AC_SEARCH_LIBS([timer_create],[rt])
|
|
|
6927e7 |
+AC_CHECK_FUNCS([timer_create])
|
|
|
6927e7 |
+
|
|
|
6927e7 |
AC_MSG_CHECKING(groupname to run under)
|
|
|
6927e7 |
AC_ARG_WITH(daemon_groupname,
|
|
|
6927e7 |
[ --with-daemon_groupname=DAEMON_GROUPNAME Groupname to run under (default daemon) ],
|