switch to syslog
This commit is contained in:
18
src/hdbd.c
18
src/hdbd.c
@@ -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,17 +39,9 @@ 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);
|
||||||
if (server_sock == -1) {
|
if (server_sock == -1) {
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user