summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2014-01-02 14:30:23 +0100
committerArthur de Jong <arthur@arthurdejong.org>2014-01-02 22:52:28 +0100
commit3afedc4a3c9c90d9bdb2bc72f6aca7e5cc9380e9 (patch)
tree648612c4b5969837bfa0c3f54c40b3ad5a64c0fc /compat
parent907d49d643aaed11f3f765f903f71ba9d1a6a119 (diff)
Remove daemon() replacement function
Diffstat (limited to 'compat')
-rw-r--r--compat/Makefile.am3
-rw-r--r--compat/daemon.c71
-rw-r--r--compat/daemon.h34
3 files changed, 1 insertions, 107 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 */