Storage cleaner daemon
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,3 +35,4 @@ watcher
|
|||||||
lts
|
lts
|
||||||
store
|
store
|
||||||
ALLOWED_USERS.txt
|
ALLOWED_USERS.txt
|
||||||
|
ltscleanerd
|
||||||
|
@ -1 +1,2 @@
|
|||||||
./lts
|
./lts
|
||||||
|
./ltscleanerd
|
||||||
|
5
Makefile
5
Makefile
@ -10,9 +10,12 @@ endif
|
|||||||
|
|
||||||
all: lts watcher
|
all: lts watcher
|
||||||
|
|
||||||
lts: lts.go uuid.go
|
lts: ltscleanerd lts.go uuid.go
|
||||||
go build -ldflags="-X main.LISTEN_ADDR=$(LISTEN_ADDR)"
|
go build -ldflags="-X main.LISTEN_ADDR=$(LISTEN_ADDR)"
|
||||||
|
|
||||||
|
ltscleanerd: ltscleanerd.c
|
||||||
|
cc -o ltscleanerd ltscleanerd.c
|
||||||
|
|
||||||
watcher: watcher.c
|
watcher: watcher.c
|
||||||
cc -o $@ $<
|
cc -o $@ $<
|
||||||
|
|
||||||
|
75
ltscleanerd.c
Normal file
75
ltscleanerd.c
Normal 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;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user