]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Don't use daemon() since it's not present on Solaris. Use our own instead
authormmj <none@none>
Sat, 3 Jul 2004 21:03:08 +0000 (07:03 +1000)
committermmj <none@none>
Sat, 3 Jul 2004 21:03:08 +0000 (07:03 +1000)
config.h.in
configure.ac
src/mlmmj-maintd.c
src/mlmmj-make-ml.sh

index 951dac387984e47e0a05fc946c7af1d83bb61619..a1080f1f1f019d7b4b0deb3e0ee31aeaa099596e 100644 (file)
@@ -15,6 +15,9 @@
 /* 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
 
index 3611a5d8ef86b22193afb96c76911375754ca2a2..dd73d44792f8a61f50ea5f49530db85acd4154e8 100644 (file)
@@ -13,6 +13,7 @@ AC_PROG_CC
 
 # Checks for libraries.
 AC_CHECK_LIB(socket,socket)
+AC_CHECK_LIB(nsl,gethostbyname)
 
 # Checks for header files.
 AC_HEADER_STDC
index cdf4c93b95966c054e9f0866773a37cb40fd7049..e836d01365a27f275b287dc7c8034b263191ad06 100644 (file)
@@ -31,6 +31,7 @@
 #include <time.h>
 #include <fcntl.h>
 #include <sys/wait.h>
+#include <signal.h>
 
 #include "mlmmj-maintd.h"
 #include "mlmmj.h"
@@ -54,6 +55,46 @@ static void print_help(const char *prg)
        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;
@@ -746,7 +787,7 @@ int main(int argc, char **argv)
        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;
index b0c0c26443d25a2a6b56e8a03d6a6709ba5fcfad..0398ceaa4afe6b1770cd30459f2669c86d20f444 100755 (executable)
@@ -40,7 +40,8 @@ case "$Option" in
        exit 1
 esac
 done
-shift $(($OPTIND - 1))
+let SHIFTVAL=$OPTIND-1
+shift $SHIFTVAL
 
 if [ -z "$SPOOLDIR" ]; then
        SPOOLDIR="$DEFAULTDIR"