Commit 2f5c4915 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Provide replacement for daemon()

Based on patch by Saso Kiselkov.
parent 58cc5454
...@@ -33,6 +33,7 @@ dnl On the fly charset transcoding ...@@ -33,6 +33,7 @@ dnl On the fly charset transcoding
AM_ICONV AM_ICONV
RDC_STRUCT_SOCKADDR_LEN RDC_STRUCT_SOCKADDR_LEN
AC_CHECK_FUNCS([daemon])
dnl Enable/Disable slp dnl Enable/Disable slp
AS_IF([test "x${enable_slp}" == "x"], AS_IF([test "x${enable_slp}" == "x"],
......
...@@ -56,6 +56,43 @@ using namespace std; ...@@ -56,6 +56,43 @@ using namespace std;
#include "lslp.h" #include "lslp.h"
#endif #endif
#ifndef HAVE_DAEMON
# include <fcntl.h>
/* daemon() is a BSD-specific function which SYSV doesn't have */
static int
daemon (int nochdir, int noclose)
{
switch (fork ())
{
case -1:
return -1;
case 0:
break;
default:
_exit (0);
}
if (setsid () == -1)
return -1;
if (!nochdir)
{
chdir ("/");
}
if (!noclose)
{
int nullfile = open ("/dev/null", O_RDWR);
dup2 (nullfile, 0);
dup2 (nullfile, 1);
dup2 (nullfile, 2);
close (nullfile);
}
}
#endif
/************************************************* /*************************************************
* Signal handler * Signal handler
*************************************************/ *************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment