setup daemon

This commit is contained in:
2025-06-01 22:40:56 +02:00
parent b96397646a
commit 31dc467165
2 changed files with 41 additions and 0 deletions

View File

@ -6,6 +6,9 @@ hdb:
gcc -ansi -O2 -pipe -o build/hdb src/main.c src/db.c -lsqlite3 gcc -ansi -O2 -pipe -o build/hdb src/main.c src/db.c -lsqlite3
strip build/hdb strip build/hdb
hdbd: src/db.c src/hdbd.c
gcc -ansi -o build/hdbd src/hdbd.c src/db.c -lsqlite3 -lstrops
.PHONY: install uninstall .PHONY: install uninstall
install: hdb install: hdb

38
src/hdbd.c Normal file
View File

@ -0,0 +1,38 @@
#include <strops.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
/* Setup daemon */
pid_t pid;
pid_t sid;
pid = fork();
if (pid == -1) {
fprintf(stderr, "Couldn't fork\n");
return 1;
} else if (pid > 0) {
printf("Pid of child is %d\n", pid);
return 0;
}
sid = setsid();
if (sid == -1) {
return 1;
}
if (chdir("/") == -1) {
return 1;
}
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
/* Actual program */
char should_close = 0;
while(!should_close) {
sleep(1);
}
}