aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorspv <spv@spv.sh>2025-11-18 10:29:15 -0500
committerspv <spv@spv.sh>2025-11-18 10:29:15 -0500
commitdf46e8485d65cc9dae9b959e828eec1eed36838e (patch)
treeb2a1816784a55dc46b6133af544b0c0bd357e534 /src/main.c
parent89928b63f48116604bddf10763123ee979f038cc (diff)
change reporting logic, 1 per hour. add skeleton of report processing code.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index a9f14f5..dab70af 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,6 +5,9 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
+
+#include <time.h>
#include "common.h"
@@ -23,7 +26,31 @@ void handler(int _) {
exit(0);
}
+void wait_thread(pid_t keypress_pid) {
+ time_t start_time = time(NULL);
+ struct tm* start_tm = localtime(&start_time);
+ int start_hour = start_tm->tm_hour;
+
+ while (1) {
+ time_t now = time(NULL);
+ struct tm* now_tm = localtime(&now);
+
+ if (now_tm->tm_hour != start_hour) {
+ kill(keypress_pid, SIGQUIT);
+
+ exit(0);
+ }
+
+ sleep(1);
+ }
+}
+
int main(int argc, char* argv[]) {
+ pid_t keypress_pid = getpid();
+ pid_t wait_pid = fork();
+
+ if (wait_pid == 0) wait_thread(keypress_pid);
+
evdev_fp = fopen(KEYBOARD_EVDEV, "r");
report_fp = NULL;
@@ -39,7 +66,9 @@ int main(int argc, char* argv[]) {
gettimeofday(&start_time, NULL);
- asprintf(&report_path, REPORT_PATH, start_time.tv_sec);
+ struct tm* start_tm = localtime(&start_time.tv_sec);
+
+ asprintf(&report_path, REPORT_PATH, start_tm->tm_year + 1900, start_tm->tm_mon + 1, start_tm->tm_mday, start_tm->tm_hour);
report_fp = fopen(report_path, "w");