|
|
@ -21,9 +21,9 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#define __USE_GNU
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/types.h>
|
|
|
@ -38,6 +38,7 @@
|
|
|
|
#include <errno.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
|
|
|
|
int openlistener_socket(int port)
|
|
|
|
int openlistener_socket(int port)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -117,6 +118,27 @@ int normalize_path(char *path)
|
|
|
|
return 0;
|
|
|
|
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
|
|
|
|
#define DM_MAX_CLOSE 8192
|
|
|
|
|
|
|
|
|
|
|
|
int daemonize(void)
|
|
|
|
int daemonize(void)
|
|
|
@ -166,5 +188,9 @@ int daemonize(void)
|
|
|
|
return EBADFD;
|
|
|
|
return EBADFD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* redirect output to syslog as well */
|
|
|
|
|
|
|
|
tosyslog(&stdout);
|
|
|
|
|
|
|
|
tosyslog(&stderr);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|