aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c40
1 files changed, 27 insertions, 13 deletions
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 <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);