[BusyBox] klogd.c: no daemon() call in libc5

Marius Groeger mag at sysgo.de
Fri Mar 30 10:08:10 UTC 2001


Hi,

The file klogd.c in current CVS snapshot makes a call to the daemon()
library function, which is not present in libc5 (how about uclibc?!).
Attached is a patch for this. I took the daemon() source from glibc
2.1.3.

Regards,

Marius Groeger

-----------------------------------------------------------------------------
Marius Groeger           SYSGO Real-Time Solutions GmbH     mgroeger at sysgo.de
Software Engineering     Embedded and Real-Time Software    www.sysgo.de
Voice: +49-6136-9948-0   Am Pfaffenstein 14                 www.osek.de
FAX:   +49-6136-9948-10  55270 Klein-Winternheim, Germany   www.elinos.com


Index: sysgo/elinos/busybox/Makefile
diff -u sysgo/elinos/busybox/Makefile:1.1.1.2 sysgo/elinos/busybox/Makefile:1.4
--- busybox/Makefile:1.1.1.2	Fri Mar 30 11:07:44 2001
+++ busybox/Makefile	Fri Mar 30 11:53:45 2001
@@ -227,7 +227,7 @@
 LIBBB_DIR = $(BB_SRC_DIR:=/)$(LIBBB)
 LIBBB_LIB = libbb.a
 LIBBB_CSRC= ask_confirmation.c check_wildcard_match.c chomp.c copy_file.c \
-copy_file_chunk.c create_path.c device_open.c error_msg.c \
+copy_file_chunk.c create_path.c daemon.c device_open.c error_msg.c \
 find_mount_point.c find_pid_by_name.c find_root_device.c full_read.c \
 full_write.c get_console.c get_last_path_component.c get_line_from_file.c \
 human_readable.c inode_hash.c isdirectory.c kernel_version.c loop.c \
--- /dev/null	Fri Mar 30 11:59:00 2001
+++ busybox/libbb/daemon.c	Fri Mar 30 11:53:45 2001
@@ -0,0 +1,71 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __GLIBC__
+
+#include <fcntl.h>
+#include <paths.h>
+#include <unistd.h>
+
+int
+daemon(nochdir, noclose)
+	int nochdir, noclose;
+{
+	int fd;
+
+	switch (fork()) {
+	case -1:
+		return (-1);
+	case 0:
+		break;
+	default:
+		_exit(0);
+	}
+
+	if (__setsid() == -1)
+		return (-1);
+
+	if (!nochdir)
+		(void)__chdir("/");
+
+	if (!noclose && (fd = __open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+		(void)__dup2(fd, STDIN_FILENO);
+		(void)__dup2(fd, STDOUT_FILENO);
+		(void)__dup2(fd, STDERR_FILENO);
+		if (fd > 2)
+			(void)__close (fd);
+	}
+	return (0);
+}
+
+#endif






More information about the busybox mailing list