Skip to content

Commit

Permalink
wip3: try to switch to timer_settime API.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP committed Jun 21, 2023
1 parent 3ee7756 commit e173d58
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions userspace/falco/stats_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -40,8 +41,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;
Expand All @@ -51,14 +52,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;
}
Expand Down

0 comments on commit e173d58

Please sign in to comment.