From 5b86b9d85e5dc0c1bb9533b4fb15f9e29e210fa4 Mon Sep 17 00:00:00 2001 From: Marcela Mašláňová Date: Dec 02 2013 11:33:07 +0000 Subject: Backport POSIX timers. --- diff --git a/at-3.1.14-usePOSIXtimers.patch b/at-3.1.14-usePOSIXtimers.patch new file mode 100644 index 0000000..ebf7d8d --- /dev/null +++ b/at-3.1.14-usePOSIXtimers.patch @@ -0,0 +1,111 @@ +diff -up at-3.1.14/atd.c.timers at-3.1.14/atd.c +--- at-3.1.14/atd.c.timers 2013-12-02 11:03:01.250080057 +0100 ++++ at-3.1.14/atd.c 2013-12-02 11:06:15.560243498 +0100 +@@ -831,6 +831,54 @@ run_loop() + 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 +@@ -936,7 +984,7 @@ main(int argc, char *argv[]) + sigaction(SIGCHLD, &act, NULL); + + if (!run_as_daemon) { +- now = time(NULL); ++ now = atd_gettime(); + run_loop(); + exit(EXIT_SUCCESS); + } +@@ -959,13 +1007,14 @@ main(int argc, char *argv[]) + 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 -up at-3.1.14/config.h.in.timers at-3.1.14/config.h.in +--- at-3.1.14/config.h.in.timers 2013-12-02 11:00:27.000000000 +0100 ++++ at-3.1.14/config.h.in 2013-12-02 11:02:06.521033976 +0100 +@@ -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 header file. */ + #undef HAVE_GETOPT_H + +diff -up at-3.1.14/configure.ac.timers at-3.1.14/configure.ac +--- at-3.1.14/configure.ac.timers 2013-12-02 11:00:27.000000000 +0100 ++++ at-3.1.14/configure.ac 2013-12-02 11:02:45.217066560 +0100 +@@ -254,6 +254,10 @@ AC_CHECK_LIB(selinux, is_selinux_enabled + 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_MSG_CHECKING(groupname to run under) + AC_ARG_WITH(daemon_groupname, + [ --with-daemon_groupname=DAEMON_GROUPNAME Groupname to run under (default daemon) ], diff --git a/at.spec b/at.spec index 8cd356a..e1ed70d 100644 --- a/at.spec +++ b/at.spec @@ -26,7 +26,7 @@ Patch6: at-3.1.14-nitpicks.patch Patch7: at-3.1.14-nowrap.patch Patch8: at-3.1.14-fix_no_export.patch Patch9: at-3.1.14-mailwithhostname.patch -#Patch10: at-3.1.13-usePOSIXtimers.patch +Patch10: at-3.1.14-usePOSIXtimers.patch #Patch11: at-3.1.13-help.patch BuildRequires: fileutils /etc/init.d @@ -80,7 +80,7 @@ cp %{SOURCE1} . %patch8 -p1 -b .export %patch9 -p1 -b .mail -#%%patch10 -p1 -b .posix +%patch10 -p1 -b .posix #%%patch11 -p1 -b .help %build