From 3afedc4a3c9c90d9bdb2bc72f6aca7e5cc9380e9 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Thu, 2 Jan 2014 14:30:23 +0100 Subject: Remove daemon() replacement function --- compat/Makefile.am | 3 +-- compat/daemon.c | 71 ------------------------------------------------------ compat/daemon.h | 34 -------------------------- 3 files changed, 1 insertion(+), 107 deletions(-) delete mode 100644 compat/daemon.c delete mode 100644 compat/daemon.h (limited to 'compat') 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 -#include -#include -#include - -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 - -#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 */ -- cgit v1.2.2