Storage cleaner daemon

This commit is contained in:
kamkow1
2025-06-21 17:50:59 +02:00
parent 8d470cbe68
commit 099f4777cd
4 changed files with 81 additions and 1 deletions

1
.gitignore vendored
View File

@ -35,3 +35,4 @@ watcher
lts
store
ALLOWED_USERS.txt
ltscleanerd

View File

@ -1 +1,2 @@
./lts
./ltscleanerd

View File

@ -10,9 +10,12 @@ endif
all: lts watcher
lts: lts.go uuid.go
lts: ltscleanerd lts.go uuid.go
go build -ldflags="-X main.LISTEN_ADDR=$(LISTEN_ADDR)"
ltscleanerd: ltscleanerd.c
cc -o ltscleanerd ltscleanerd.c
watcher: watcher.c
cc -o $@ $<

75
ltscleanerd.c Normal file
View File

@ -0,0 +1,75 @@
//go:build exclude
#include <time.h>
#include <signal.h>
#define GEBS_NO_PREFIX
#define GEBS_IMPLEMENTATION
#include "gebs/gebs.h"
char *prog = nil;
char *file_path = nil;
void timer_handler(int sig, siginfo_t *si, void *uc)
{
if (file_path != nil) {
remove1(file_path);
exit(0);
}
}
void make_timer(char *name, long seconds)
{
struct sigevent timer_event;
struct itimerspec timer_spec;
struct sigaction action;
int sig_no = SIGRTMIN;
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = &timer_handler;
sigemptyset(&action.sa_mask);
if (sigaction(sig_no, &action, nil) == -1) {
LOGE("Could not create timer signal handler\n");
exit(1);
}
timer_event.sigev_notify = SIGEV_SIGNAL;
timer_event.sigev_signo = sig_no;
timer_event.sigev_value.sival_ptr = name;
timer_t timer_id;
if (timer_create(CLOCK_REALTIME, &timer_event, &timer_id) == -1) {
LOGE("Could not create timer\n");
exit(1);
}
memset(&timer_spec, 0, sizeof(timer_spec));
timer_spec.it_value.tv_sec = seconds;
if (timer_settime(timer_id, 0, &timer_spec, nil) == -1) {
LOGE("Could not set the timeout\n");
exit(1);
}
}
int main(int argc, char ** argv)
{
prog = SHIFT(&argc, &argv);
file_path = SHIFT(&argc, &argv);
char *timeout_string = SHIFT(&argc, &argv);
if (!exists1(file_path)) {
LOGI("Path %s does not exist\n", file_path);
return 1;
}
char *endp;
long timeout = strtol(timeout_string, &endp, 10);
make_timer("cleaner", timeout);
pause();
return 0;
}