From: mmj Date: Sat, 3 Jul 2004 21:03:08 +0000 (+1000) Subject: Don't use daemon() since it's not present on Solaris. Use our own instead X-Git-Tag: RELEASE_1_0_0~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6aeb320dbcc722527a32a6cb3ddff68e663db610;p=thirdparty%2Fmlmmj.git Don't use daemon() since it's not present on Solaris. Use our own instead --- diff --git a/config.h.in b/config.h.in index 951dac38..a1080f1f 100644 --- a/config.h.in +++ b/config.h.in @@ -15,6 +15,9 @@ /* Define to 1 if you have the 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 diff --git a/configure.ac b/configure.ac index 3611a5d8..dd73d447 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index cdf4c93b..e836d013 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -31,6 +31,7 @@ #include #include #include +#include #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; diff --git a/src/mlmmj-make-ml.sh b/src/mlmmj-make-ml.sh index b0c0c264..0398ceaa 100755 --- a/src/mlmmj-make-ml.sh +++ b/src/mlmmj-make-ml.sh @@ -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"