mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-29 08:07:24 +00:00
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 <nierro92@gmail.com>
This commit is contained in:
parent
5b0ed1eb56
commit
c0ea9b3618
@ -1 +1 @@
|
||||
Subproject commit f5ef8d98d5ac8642f48dd6a478d5501ef0d903dd
|
||||
Subproject commit 3f52480618491a9232a1ec6a1f692fc04899c989
|
@ -15,7 +15,8 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
#include <ctime>
|
||||
#include <csignal>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <atomic>
|
||||
|
||||
@ -39,8 +40,8 @@ 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));
|
||||
handler.sa_handler = &timer_handler;
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user