switch to syslog

This commit is contained in:
2025-09-16 23:42:41 +02:00
parent 4d8fd7b98e
commit 356d2fdaa3

View File

@@ -5,6 +5,7 @@
#include <string.h> #include <string.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <syslog.h>
pid_t pid, sid; pid_t pid, sid;
int server_sock; int server_sock;
@@ -38,16 +39,8 @@ int main() {
close(STDOUT_FILENO); close(STDOUT_FILENO);
close(STDERR_FILENO); close(STDERR_FILENO);
FILE *out_log; openlog("hdbd", LOG_CONS|LOG_PID, LOG_USER);
FILE *err_log; syslog(LOG_INFO, "Hello from hdbd");
/* TODO: switch to mode 'a' later */
out_log = fopen("/tmp/out_log.txt", "w");
err_log = fopen("/tmp/err_log.txt", "w");
if (out_log == NULL || err_log == NULL) {
return 1;
}
fprintf(err_log, "Hello, World!\n");
/* Setup Unix Socket */ /* Setup Unix Socket */
server_sock = socket(AF_UNIX, SOCK_STREAM, 0); server_sock = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -68,8 +61,7 @@ int main() {
return 1; return 1;
} }
fprintf(out_log, "Listening on %s\n", server.sun_path); syslog(LOG_INFO, "Listening for connections...");
/* Actual program */ /* Actual program */
int client_sock; int client_sock;
@@ -102,8 +94,6 @@ int main() {
close(client_sock); close(client_sock);
} }
fclose(out_log);
fclose(err_log);
close(server_sock); close(server_sock);
return 0; return 0;
} }