|
From: <mla...@us...> - 2008-01-01 14:34:05
|
Revision: 382
http://g15daemon.svn.sourceforge.net/g15daemon/?rev=382&view=rev
Author: mlampard
Date: 2008-01-01 06:34:02 -0800 (Tue, 01 Jan 2008)
Log Message:
-----------
add our own version of daemon() for those platforms that don't have native support.
Modified Paths:
--------------
trunk/g15daemon-wip/ChangeLog
trunk/g15daemon-wip/configure.in
trunk/g15daemon-wip/g15daemon/main.c
Modified: trunk/g15daemon-wip/ChangeLog
===================================================================
--- trunk/g15daemon-wip/ChangeLog 2008-01-01 13:11:08 UTC (rev 381)
+++ trunk/g15daemon-wip/ChangeLog 2008-01-01 14:34:02 UTC (rev 382)
@@ -141,3 +141,5 @@
- Feature: Debug verbosity of g15daemon_log is now variable.
- Feature: Plugin filenames are now cached in g15daemon.conf to allow
(manual, at this stage) changing of load-order.
+- Portability: Add our own daemon() function if platform doesn't have native
+ support.
Modified: trunk/g15daemon-wip/configure.in
===================================================================
--- trunk/g15daemon-wip/configure.in 2008-01-01 13:11:08 UTC (rev 381)
+++ trunk/g15daemon-wip/configure.in 2008-01-01 14:34:02 UTC (rev 382)
@@ -25,6 +25,8 @@
AC_CHECK_LIB([m], [sin])
AC_CHECK_LIB([pthread], [pthread_mutex_init])
+AC_CHECK_FUNC(daemon,AC_DEFINE(HAVE_DAEMON,1,[Define if daemon() is available]),[])
+
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_PID_T
Modified: trunk/g15daemon-wip/g15daemon/main.c
===================================================================
--- trunk/g15daemon-wip/g15daemon/main.c 2008-01-01 13:11:08 UTC (rev 381)
+++ trunk/g15daemon-wip/g15daemon/main.c 2008-01-01 14:34:02 UTC (rev 382)
@@ -275,7 +275,40 @@
}
}
+#ifndef HAVE_DAEMON
+/* daemon() is not posix compliant, so we roll our own if needed.*/
+int daemon(int nochdir, int noclose) {
+ pid_t pid;
+
+ if(nochdir<1)
+ chdir("/");
+ pid = fork();
+ switch(pid){
+ case -1:
+ printf("Unable to daemonise!\n");
+ return -1;
+ break;
+ case 0: {
+ umask(0);
+ if(setsid()==-1) {
+ perror("setsid");
+ return -1;
+ }
+ if(noclose<1) {
+ freopen( "/dev/null", "r", stdin);
+ freopen( "/dev/null", "w", stdout);
+ freopen( "/dev/null", "w", stderr);
+ }
+ break;
+ }
+ default:
+ _exit(0);
+ }
+ return 0;
+}
+#endif
+
int main (int argc, char *argv[])
{
pid_t daemonpid;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|