From c0ea9b36185e3942139e40fbd9122e3cfc75100d Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Wed, 21 Jun 2023 11:06:46 +0200 Subject: [PATCH] fix(userspace): switch to `timer_settime` API in stats writer. It seems like `setitimer` is not correctly working when built from CI; perhaps a gcc/glibc bug? Signed-off-by: Federico Di Pierro --- submodules/falcosecurity-rules | 2 +- userspace/falco/stats_writer.cpp | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/submodules/falcosecurity-rules b/submodules/falcosecurity-rules index f5ef8d98..3f524806 160000 --- a/submodules/falcosecurity-rules +++ b/submodules/falcosecurity-rules @@ -1 +1 @@ -Subproject commit f5ef8d98d5ac8642f48dd6a478d5501ef0d903dd +Subproject commit 3f52480618491a9232a1ec6a1f692fc04899c989 diff --git a/userspace/falco/stats_writer.cpp b/userspace/falco/stats_writer.cpp index 00a64c43..0e7aa111 100644 --- a/userspace/falco/stats_writer.cpp +++ b/userspace/falco/stats_writer.cpp @@ -15,7 +15,8 @@ limitations under the License. */ #include -#include +#include +#include #include #include @@ -39,10 +40,10 @@ static void timer_handler(int signum) bool stats_writer::init_ticker(uint32_t interval_msec, std::string &err) { - struct itimerval timer; - struct sigaction handler; + struct itimerspec timer = {}; + struct sigaction handler = {}; - memset (&handler, 0, sizeof (handler)); + memset (&handler, 0, sizeof(handler)); handler.sa_handler = &timer_handler; if (sigaction(SIGALRM, &handler, NULL) == -1) { @@ -50,14 +51,29 @@ bool stats_writer::init_ticker(uint32_t interval_msec, std::string &err) return false; } + timer_t timerid; + struct sigevent sev = {}; + /* Create the timer */ + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGALRM; + sev.sigev_value.sival_ptr = &timerid; + if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) == -1) { + err = std::string("Could not create periodic timer: ") + strerror(errno); + return false; + } timer.it_value.tv_sec = interval_msec / 1000; - timer.it_value.tv_usec = (interval_msec % 1000) * 1000; + timer.it_value.tv_nsec = (interval_msec % 1000) * 1000 * 1000; timer.it_interval = timer.it_value; - if (setitimer(ITIMER_REAL, &timer, NULL) == -1) - { + + if (timer_settime(timerid, 0, &timer, NULL) == -1) { err = std::string("Could not set up periodic timer: ") + strerror(errno); return false; } + //if (setitimer(ITIMER_REAL, &timer, NULL) == -1) + //{ + // err = std::string("Could not set up periodic timer: ") + strerror(errno); + // return false; + //} return true; }