/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+#undef HAVE_LIBNSL
+
/* Define to 1 if you have the `socket' library (-lsocket). */
#undef HAVE_LIBSOCKET
# Checks for libraries.
AC_CHECK_LIB(socket,socket)
+AC_CHECK_LIB(nsl,gethostbyname)
# Checks for header files.
AC_HEADER_STDC
#include <time.h>
#include <fcntl.h>
#include <sys/wait.h>
+#include <signal.h>
#include "mlmmj-maintd.h"
#include "mlmmj.h"
exit(EXIT_SUCCESS);
}
+static int mydaemon(const char *rootdir)
+{
+ int i;
+ pid_t pid;
+
+ if((pid = fork()) < 0)
+ return -1;
+ else if (pid)
+ exit(EXIT_SUCCESS); /* parent says bye bye */
+
+ if(setsid() < 0) {
+ log_error(LOG_ARGS, "Could not setsid()");
+ return -1;
+ }
+
+ if(signal(SIGHUP, SIG_IGN) == SIG_IGN) {
+ log_error(LOG_ARGS, "Could not signal(SIGHUP, SIG_IGN)");
+ return -1;
+ }
+
+ if((pid = fork()) < 0)
+ return -1;
+ else if (pid)
+ exit(EXIT_SUCCESS); /* parent says bye bye */
+
+ chdir(rootdir);
+
+ i = sysconf(_SC_OPEN_MAX);
+ if(i < 0)
+ i = 256;
+ while(i >= 0)
+ close(i--);
+
+ open("/dev/null", O_RDONLY);
+ open("/dev/null", O_RDWR);
+ open("/dev/null", O_RDWR);
+
+ return 0;
+}
+
int delolder(const char *dirname, time_t than)
{
DIR *dir;
mlmmjunsub = concatstr(2, bindir, "/mlmmj-unsub");
myfree(bindir);
- if(daemonize && daemon(1,0) < 0) {
+ if(daemonize && (mydaemon(listdir) < 0)) {
log_error(LOG_ARGS, "Could not daemonize. Only one "
"maintenance run will be done.");
daemonize = 0;