Skip to content

Commit

Permalink
Add 'time' field in the JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae committed Feb 25, 2020
1 parent a55c05b commit d4af943
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* fsmon -- MIT - Copyright NowSecure 2015-2019 - [email protected] */
/* fsmon -- MIT - Copyright NowSecure 2015-2020 - [email protected] */

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -57,6 +57,17 @@ static bool setup_signals() {
return res;
}

static uint64_t __sys_now(void) {
uint64_t ret;
struct timeval now;
gettimeofday (&now, NULL);
ret = now.tv_sec;
ret <<= 20;
ret |= now.tv_usec;
//(sizeof (now.tv_sec) == 4
return ret;
}

static bool callback(FileMonitor *fm, FileMonitorEvent *ev) {
if (fm->child) {
if (fm->pid && ev->pid != fm->pid) {
Expand Down Expand Up @@ -97,6 +108,10 @@ static bool callback(FileMonitor *fm, FileMonitorEvent *ev) {
if (ev->inode) {
printf ("\"inode\":%d,", ev->inode);
}
if (ev->tstamp) {
uint64_t now = __sys_now();
printf ("\"time\":%" PRId64 ",", now);
}
if (ev->tstamp) {
printf ("\"timestamp\":%" PRId64 ",", ev->tstamp);
}
Expand Down

0 comments on commit d4af943

Please sign in to comment.