changeset 288:1f741ed4b937

Don't use daemon() since it's not present on Solaris. Use our own instead
author mmj
date Sun, 04 Jul 2004 07:03:08 +1000
parents 62fbbf742b3c
children c0beaab3aa91
files config.h.in configure.ac src/mlmmj-maintd.c src/mlmmj-make-ml.sh
diffstat 4 files changed, 48 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/config.h.in	Sat Jul 03 23:32:25 2004 +1000
+++ b/config.h.in	Sun Jul 04 07:03:08 2004 +1000
@@ -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
 
--- a/configure.ac	Sat Jul 03 23:32:25 2004 +1000
+++ b/configure.ac	Sun Jul 04 07:03:08 2004 +1000
@@ -13,6 +13,7 @@
 
 # Checks for libraries.
 AC_CHECK_LIB(socket,socket)
+AC_CHECK_LIB(nsl,gethostbyname)
 
 # Checks for header files.
 AC_HEADER_STDC
--- a/src/mlmmj-maintd.c	Sat Jul 03 23:32:25 2004 +1000
+++ b/src/mlmmj-maintd.c	Sun Jul 04 07:03:08 2004 +1000
@@ -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 @@
 	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 @@
 	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;
--- a/src/mlmmj-make-ml.sh	Sat Jul 03 23:32:25 2004 +1000
+++ b/src/mlmmj-make-ml.sh	Sun Jul 04 07:03:08 2004 +1000
@@ -40,7 +40,8 @@
 	exit 1
 esac
 done
-shift $(($OPTIND - 1))
+let SHIFTVAL=$OPTIND-1
+shift $SHIFTVAL
 
 if [ -z "$SPOOLDIR" ]; then
 	SPOOLDIR="$DEFAULTDIR"