Blame SOURCES/at-3.1.13-usePOSIXtimers.patch

2eda5e
diff -up at-3.1.13/atd.c.posix at-3.1.13/atd.c
2eda5e
--- at-3.1.13/atd.c.posix	2022-02-15 15:41:22.766701662 +0100
2eda5e
+++ at-3.1.13/atd.c	2022-02-15 15:41:22.768701680 +0100
2eda5e
@@ -821,6 +821,54 @@ run_loop()
2eda5e
     return next_job;
2eda5e
 }
2eda5e
 
2eda5e
+#ifdef HAVE_CLOCK_GETTIME
2eda5e
+timer_t timer;
2eda5e
+struct itimerspec timeout;
2eda5e
+
2eda5e
+void timer_setup()
2eda5e
+{
2eda5e
+    struct sigevent sev;
2eda5e
+
2eda5e
+    sev.sigev_notify = SIGEV_SIGNAL;
2eda5e
+    sev.sigev_signo = SIGHUP;
2eda5e
+    sev.sigev_value.sival_ptr = &timer;
2eda5e
+
2eda5e
+    memset(&timeout, 0, sizeof(timeout));
2eda5e
+
2eda5e
+    if (timer_create(CLOCK_REALTIME, &sev, &timer) < 0)
2eda5e
+	    pabort("unable to create timer");
2eda5e
+}
2eda5e
+
2eda5e
+time_t atd_gettime()
2eda5e
+{
2eda5e
+    struct timespec curtime;
2eda5e
+
2eda5e
+    clock_gettime(CLOCK_REALTIME, &curtime);
2eda5e
+
2eda5e
+    return curtime.tv_sec;
2eda5e
+}
2eda5e
+
2eda5e
+void atd_setalarm(time_t next)
2eda5e
+{
2eda5e
+    timeout.it_value.tv_sec = next;
2eda5e
+    timer_settime(timer, TIMER_ABSTIME, &timeout, NULL);
2eda5e
+    pause();
2eda5e
+}
2eda5e
+#else
2eda5e
+void timer_setup()
2eda5e
+{
2eda5e
+}
2eda5e
+
2eda5e
+time_t atd_gettime()
2eda5e
+{
2eda5e
+    return time(NULL);
2eda5e
+}
2eda5e
+
2eda5e
+void atd_setalarm(time_t next)
2eda5e
+{
2eda5e
+    sleep(next - atd_gettime());
2eda5e
+}
2eda5e
+#endif
2eda5e
 /* Global functions */
2eda5e
 
2eda5e
 int
2eda5e
@@ -926,7 +974,7 @@ main(int argc, char *argv[])
2eda5e
     sigaction(SIGCHLD, &act, NULL);
2eda5e
 
2eda5e
     if (!run_as_daemon) {
2eda5e
-	now = time(NULL);
2eda5e
+	now = atd_gettime();
2eda5e
 	run_loop();
2eda5e
 	exit(EXIT_SUCCESS);
2eda5e
     }
2eda5e
@@ -949,13 +997,15 @@ main(int argc, char *argv[])
2eda5e
     act.sa_handler = set_term;
2eda5e
     sigaction(SIGINT, &act, NULL);
2eda5e
 
2eda5e
+    timer_setup();
2eda5e
+
2eda5e
     daemon_setup();
2eda5e
 
2eda5e
     do {
2eda5e
-	now = time(NULL);
2eda5e
+	now = atd_gettime();
2eda5e
 	next_invocation = run_loop();
2eda5e
 	if (next_invocation > now) {
2eda5e
-	    sleep(next_invocation - now);
2eda5e
+	    atd_setalarm(next_invocation);
2eda5e
 	}
2eda5e
     } while (!term_signal);
2eda5e
     daemon_cleanup();
2eda5e
diff -up at-3.1.13/config.h.in.posix at-3.1.13/config.h.in
2eda5e
--- at-3.1.13/config.h.in.posix	2022-02-15 15:41:22.758701591 +0100
2eda5e
+++ at-3.1.13/config.h.in	2022-02-15 15:41:22.769701689 +0100
2eda5e
@@ -38,6 +38,9 @@
2eda5e
 /* Define to 1 if you have the `getloadavg' function. */
2eda5e
 #undef HAVE_GETLOADAVG
2eda5e
 
2eda5e
+/* Define to 1 if you have the `clock_gettime' function. */
2eda5e
+#undef HAVE_TIMER_CREATE
2eda5e
+
2eda5e
 /* Define to 1 if you have the <getopt.h> header file. */
2eda5e
 #undef HAVE_GETOPT_H
2eda5e
 
2eda5e
diff -up at-3.1.13/configure.ac.posix at-3.1.13/configure.ac
2eda5e
--- at-3.1.13/configure.ac.posix	2022-02-15 15:41:22.770701698 +0100
2eda5e
+++ at-3.1.13/configure.ac	2022-02-15 15:43:29.945835498 +0100
2eda5e
@@ -253,6 +253,10 @@ AC_CHECK_LIB(selinux, is_selinux_enabled
2eda5e
 AC_SUBST(SELINUXLIB)
2eda5e
 AC_SUBST(WITH_SELINUX)
2eda5e
 
2eda5e
+dnl check for POSIX timer functions
2eda5e
+AC_SEARCH_LIBS([timer_create],[rt])
2eda5e
+AC_CHECK_FUNCS([timer_create])
2eda5e
+
2eda5e
 AC_MSG_CHECKING(groupname to run under)
2eda5e
 AC_ARG_WITH(daemon_groupname,
2eda5e
 [ --with-daemon_groupname=DAEMON_GROUPNAME	Groupname to run under (default daemon) ],