diff options
-rw-r--r-- | compat/Makefile.am | 3 | ||||
-rw-r--r-- | compat/daemon.c | 71 | ||||
-rw-r--r-- | compat/daemon.h | 34 | ||||
-rw-r--r-- | configure.ac | 7 |
4 files changed, 1 insertions, 114 deletions
diff --git a/compat/Makefile.am b/compat/Makefile.am index 66703c5..361c9be 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -1,6 +1,6 @@ # Makefile.am - use automake to generate Makefile.in # -# Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Arthur de Jong +# Copyright (C) 2008-2014 Arthur de Jong # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -23,7 +23,6 @@ AM_CPPFLAGS=-I$(top_srcdir) AM_CFLAGS = -fPIC EXTRA_DIST = getopt_long.c getopt_long.h \ - daemon.c daemon.h \ ether.c ether.h \ shell.h \ strndup.c strndup.h \ diff --git a/compat/daemon.c b/compat/daemon.c deleted file mode 100644 index e3d5aea..0000000 --- a/compat/daemon.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - daemon.c - implementation of daemon() for systems that lack it - - Copyright (C) 2002, 2003, 2008, 2012 Arthur de Jong - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#include "daemon.h" - -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -int daemon(int nochdir, int noclose) -{ - /* change directory */ - if (!nochdir) - if (chdir("/") != 0) - return -1; - /* fork() and exit() to detach from the parent process */ - switch (fork()) - { - case 0: /* we are the child */ - break; - case -1: /* we are the parent, but have an error */ - return -1; - default: /* we are the parent and we're done */ - _exit(0); - } - /* become process leader */ - if (setsid() < 0) - { - return -1; - } - /* fork again so we cannot allocate a pty */ - switch (fork()) - { - case 0: /* we are the child */ - break; - case -1: /* we are the parent, but have an error */ - return -1; - default: /* we are the parent and we're done */ - _exit(0); - } - /* close stdin, stdout and stderr and reconnect to /dev/null */ - if (!noclose) - { - close(0); /* stdin */ - close(1); /* stdout */ - close(2); /* stderr */ - open("/dev/null", O_RDWR); /* stdin, fd=0 */ - dup(0); /* stdout, fd=1 */ - dup(0); /* stderr, fd=2 */ - } - return 0; -} diff --git a/compat/daemon.h b/compat/daemon.h deleted file mode 100644 index 0de27cc..0000000 --- a/compat/daemon.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - daemon.h - definition of daemon() for systems that lack it - - Copyright (C) 2002, 2003, 2008, 2011, 2012 Arthur de Jong - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA -*/ - -#ifndef COMPAT__DAEMON_H -#define COMPAT__DAEMON_H 1 - -#include <unistd.h> - -#if !HAVE_DECL_DAEMON -/* we define daemon() here because on some platforms the function is - undefined: deamonize process, optionally chdir to / and optionally - close stdin, strdout and stderr and redirect them to /dev/null */ -int daemon(int nochdir, int noclose); -#endif /* not HAVE_DECL_DAEMON */ - -#endif /* not COMPAT__DAEMON_H */ diff --git a/configure.ac b/configure.ac index a80dff6..411c9e5 100644 --- a/configure.ac +++ b/configure.ac @@ -697,13 +697,6 @@ then AC_REPLACE_FUNCS(getopt_long) AC_REPLACE_FUNCS(strndup) - # replace daemon() function if it is not on the system - AC_SEARCH_LIBS(daemon, bsd) - AC_REPLACE_FUNCS(daemon) - AC_CHECK_DECLS([daemon],,, [ - #include <unistd.h> - #include <stdlib.h>]) - # replace ether_aton_r() and ether_ntoa_r() if they are not found AC_CHECK_FUNCS(ether_aton_r ether_ntoa_r,, [AC_LIBOBJ(ether)]) |