[helpers] Added an ability to redirect all output to syslog in case of daemon mode;

v0.4.xx
leonid-ed 9 years ago
parent 678afa32d7
commit c0736303e0

@ -21,9 +21,9 @@
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <dirent.h>
#define __USE_GNU
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
@ -38,6 +38,7 @@
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <syslog.h>
int openlistener_socket(int port)
{
@ -117,6 +118,27 @@ int normalize_path(char *path)
return 0;
}
/* syslog stuff */
static size_t writer(void *cookie, char const *data, size_t len)
{
(void)cookie;
syslog(LOG_DEBUG, "%.*s", (int)len, data);
return len;
}
static int noop(void) { return 0; }
static cookie_io_functions_t log_fns = {
(void*) noop, (void*) writer, (void*) noop, (void*) noop
};
void tosyslog(FILE **pfp)
{
setvbuf(*pfp = fopencookie(NULL, "w", log_fns), NULL, _IOLBF, 0);
}
/* daemonization stuff */
#define DM_MAX_CLOSE 8192
int daemonize(void)
@ -166,5 +188,9 @@ int daemonize(void)
return EBADFD;
}
/* redirect output to syslog as well */
tosyslog(&stdout);
tosyslog(&stderr);
return 0;
}

Loading…
Cancel
Save