From 6f2cd6be1d44fb13d75f66418c9a27b01b77a53d Mon Sep 17 00:00:00 2001 From: spv Date: Mon, 17 Nov 2025 16:47:32 -0500 Subject: add WIP report gen, systemd user service, work time tracker, sig handling --- src/main.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 3542f36..a9f14f5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,13 +1,31 @@ #include #include +#include +#include #include +#include +#include -#include "logger.h" -#include "config.h" +#include "common.h" + +#include "key_tracker.h" +#include "report.h" + +FILE* report_fp; +FILE* evdev_fp; + +void handler(int _) { + gen_report(report_fp); + + fclose(report_fp); + fclose(evdev_fp); + + exit(0); +} int main(int argc, char* argv[]) { - FILE* evdev_fp = fopen(KEYBOARD_EVDEV, "r"); - FILE* report_fp = NULL; + evdev_fp = fopen(KEYBOARD_EVDEV, "r"); + report_fp = NULL; char* report_path = NULL; @@ -25,19 +43,15 @@ int main(int argc, char* argv[]) { report_fp = fopen(report_path, "w"); + signal(SIGHUP, handler); + signal(SIGQUIT, handler); + signal(SIGTERM, handler); + do { fread(&pressed_key, sizeof(pressed_key), 1, evdev_fp); - gettimeofday(&press_time, NULL); - if (pressed_key.value == 1) { - perkey_pressed[pressed_key.code < PERKEY_LEN ? pressed_key.code : PERKEY_LEN]; - keys_pressed++; - - LOG(LOG_DEBUG, "%d:", keys_pressed, pressed_key.type, pressed_key.code, pressed_key.value); - rewind(report_fp); - fprintf(report_fp, "%d\n", keys_pressed); - fflush(report_fp); + log_key(pressed_key.code); } } while (1); -- cgit v1.2.3