aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-04-04 19:25:57 +0000
committerEric Andersen <andersen@codepoet.org>2001-04-04 19:25:57 +0000
commitb2e3e9b0c9149f0c7e1e6a8b46587d7cb53b68aa (patch)
treed420a30885568b703014b5808e9f174aa8aa808e
parent2129f97cd9502b731f6489e4c8be54fd44affc1d (diff)
downloadbusybox-w32-b2e3e9b0c9149f0c7e1e6a8b46587d7cb53b68aa.tar.gz
busybox-w32-b2e3e9b0c9149f0c7e1e6a8b46587d7cb53b68aa.tar.bz2
busybox-w32-b2e3e9b0c9149f0c7e1e6a8b46587d7cb53b68aa.zip
Seems that stupid libc5 doesn't implement daemon(), so conditionally
inclde that here. -Erik
-rw-r--r--Makefile2
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/daemon.c103
-rw-r--r--libbb/libbb.h2
4 files changed, 108 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index c8c9d4687..85ba823fb 100644
--- a/Makefile
+++ b/Makefile
@@ -236,7 +236,7 @@ endif
236LIBBB = libbb 236LIBBB = libbb
237LIBBB_LIB = libbb.a 237LIBBB_LIB = libbb.a
238LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c copy_file.c \ 238LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c copy_file.c \
239copy_file_chunk.c create_path.c device_open.c error_msg.c \ 239copy_file_chunk.c create_path.c daemon.c device_open.c error_msg.c \
240find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \ 240find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \
241full_write.c get_console.c get_last_path_component.c get_line_from_file.c \ 241full_write.c get_console.c get_last_path_component.c get_line_from_file.c \
242human_readable.c inode_hash.c isdirectory.c kernel_version.c loop.c \ 242human_readable.c inode_hash.c isdirectory.c kernel_version.c loop.c \
diff --git a/include/libbb.h b/include/libbb.h
index b5c845952..d850befea 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -39,6 +39,8 @@
39#if ! defined __GLIBC__ && ! defined __UCLIBC__ 39#if ! defined __GLIBC__ && ! defined __UCLIBC__
40/* libc5 doesn't define socklen_t */ 40/* libc5 doesn't define socklen_t */
41typedef unsigned int socklen_t; 41typedef unsigned int socklen_t;
42/* libc5 doesn't implement BSD 4.4 daemon() */
43extern int daemon (int nochdir, int noclose);
42#endif 44#endif
43 45
44/* Some useful definitions */ 46/* Some useful definitions */
diff --git a/libbb/daemon.c b/libbb/daemon.c
new file mode 100644
index 000000000..55a776ce0
--- /dev/null
+++ b/libbb/daemon.c
@@ -0,0 +1,103 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * daemon implementation for uClibc
4 *
5 * Copyright (c) 1991, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Modified for uClibc by Erik Andersen
9 * <andersee@debian.org>, <andersen@lineo.com>
10 *
11 * The uClibc Library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
15 *
16 * The GNU C Library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with the GNU C Library; see the file COPYING.LIB. If not,
23 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
25 *
26 * Original copyright notice is retained at the end of this file.
27 */
28
29#include <features.h>
30#include <fcntl.h>
31#include <paths.h>
32#include <unistd.h>
33
34
35/* Stupid libc doesn't have a reliable way for use to know
36 * that libc5 is being used. Assume this is good enough */
37#if ! defined __GLIBC__ && ! defined __UCLIBC__
38
39int daemon( int nochdir, int noclose )
40{
41 int fd;
42
43 switch (fork()) {
44 case -1:
45 return(-1);
46 case 0:
47 break;
48 default:
49 _exit(0);
50 }
51
52 if (setsid() == -1)
53 return(-1);
54
55 if (!nochdir)
56 chdir("/");
57
58 if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
59 dup2(fd, STDIN_FILENO);
60 dup2(fd, STDOUT_FILENO);
61 dup2(fd, STDERR_FILENO);
62 if (fd > 2)
63 close(fd);
64 }
65 return(0);
66}
67#endif
68
69
70/*-
71 * Copyright (c) 1990, 1993
72 * The Regents of the University of California. All rights reserved.
73 *
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
76 * are met:
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright
80 * notice, this list of conditions and the following disclaimer in the
81 * documentation and/or other materials provided with the distribution.
82 *
83 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
84 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
85 *
86 * 4. Neither the name of the University nor the names of its contributors
87 * may be used to endorse or promote products derived from this software
88 * without specific prior written permission.
89 *
90 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 */
102
103
diff --git a/libbb/libbb.h b/libbb/libbb.h
index b5c845952..d850befea 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -39,6 +39,8 @@
39#if ! defined __GLIBC__ && ! defined __UCLIBC__ 39#if ! defined __GLIBC__ && ! defined __UCLIBC__
40/* libc5 doesn't define socklen_t */ 40/* libc5 doesn't define socklen_t */
41typedef unsigned int socklen_t; 41typedef unsigned int socklen_t;
42/* libc5 doesn't implement BSD 4.4 daemon() */
43extern int daemon (int nochdir, int noclose);
42#endif 44#endif
43 45
44/* Some useful definitions */ 46/* Some useful definitions */