diff options
| author | spv <spv@spv.sh> | 2025-11-17 16:47:32 -0500 |
|---|---|---|
| committer | spv <spv@spv.sh> | 2025-11-17 16:47:32 -0500 |
| commit | 6f2cd6be1d44fb13d75f66418c9a27b01b77a53d (patch) | |
| tree | 7ba44fa400145e77ef487b9fd1de36d692e7cd9f /src/main.c | |
| parent | 6f010046f0f17a5684a0f30423e2b3c6a41099d1 (diff) | |
add WIP report gen, systemd user service, work time tracker, sig handling
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 40 |
1 files changed, 27 insertions, 13 deletions
@@ -1,13 +1,31 @@ #include <linux/input.h> #include <sys/time.h> +#include <signal.h> +#include <stdlib.h> #include <stdio.h> +#include <errno.h> +#include <string.h> -#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); |
