From 319f3137ecfce438ec2596165ae2dddebc393a9e Mon Sep 17 00:00:00 2001
From: Ryan Zezeski <ryan@zinascii.com>
Date: Sat, 31 Jan 2015 18:54:49 -0500
Subject: [PATCH] 872 remove duplicate daemon() definitions
 Reviewed by: Garrett D'Amore <garrett@damore.org>
 Reviewed by: Marcel Telka <marcel@telka.sk>

---
 usr/src/lib/gss_mechs/mech_krb5/Makefile.com       |    2 +-
 .../lib/gss_mechs/mech_krb5/krb5/posix/daemon.c    |   95 --------------------
 usr/src/lib/gss_mechs/mech_krb5/mapfile-vers       |    1 -
 usr/src/lib/libresolv2/Makefile.com                |    2 +-
 usr/src/lib/libresolv2/common/bsd/daemon.c         |   81 -----------------
 usr/src/lib/libresolv2/common/mapfile-vers         |    1 -
 usr/src/lib/libresolv2/include/port_after.h        |    5 -
 7 files changed, 2 insertions(+), 185 deletions(-)
 delete mode 100644 usr/src/lib/gss_mechs/mech_krb5/krb5/posix/daemon.c
 delete mode 100644 usr/src/lib/libresolv2/common/bsd/daemon.c

diff --git a/usr/src/lib/gss_mechs/mech_krb5/Makefile.com b/usr/src/lib/gss_mechs/mech_krb5/Makefile.com
index 3d41bd6..0d43786 100644
--- a/usr/src/lib/gss_mechs/mech_krb5/Makefile.com
+++ b/usr/src/lib/gss_mechs/mech_krb5/Makefile.com
@@ -152,7 +152,7 @@ K5_OS=	an_to_ln.o def_realm.o ccdefname.o free_krbhs.o free_hstrl.o \
 
 K5_OS_UTS=init_os_ctx.o timeofday.o toffset.o c_ustime.o
 
-K5_POSIX= setenv.o daemon.o
+K5_POSIX= setenv.o
 
 K5_RCACHE=rc_base.o rc_file.o rc_mem.o rc_common.o rc_io.o rcdef.o rc_conv.o \
 	ser_rc.o rcfns.o rc_none.o
diff --git a/usr/src/lib/gss_mechs/mech_krb5/krb5/posix/daemon.c b/usr/src/lib/gss_mechs/mech_krb5/krb5/posix/daemon.c
deleted file mode 100644
index 00dde48..0000000
--- a/usr/src/lib/gss_mechs/mech_krb5/krb5/posix/daemon.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*-
- * Copyright (c) 1990 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.
- */
-
-#include "k5-int.h"
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <unistd.h>
-#ifdef HAVE_PATHS_H
-#include <paths.h>
-#endif
-
-#ifndef _PATH_DEVNULL
-#define _PATH_DEVNULL "/dev/null"
-#endif
-
-int
-daemon(nochdir, noclose)
-	int nochdir, noclose;
-{
-	int cpid;
-
-	if ((cpid = fork()) == -1)
-		return (-1);
-	if (cpid)
-		exit(0);
-#ifdef HAVE_SETSID
-	(void) setsid();
-#else
-#ifndef TIOCNOTTY
-	setpgrp();
-#else
-	{
-		int n;
-	    
-		/*
-		 * The open below may hang on pseudo ttys if the person
-		 * who starts named logs out before this point.  Thus,
-		 * the need for the timer.
-		 */
-		alarm(120);
-		n = open("/dev/tty", O_RDWR);
-		alarm(0);
-		if (n > 0) {
-			(void) ioctl(n, TIOCNOTTY, (char *)NULL);
-			(void) close(n);
-		}
-	}
-#endif
-#endif
-	if (!nochdir)
-		(void) chdir("/");
-	if (!noclose) {
-		int devnull = open(_PATH_DEVNULL, O_RDWR, 0);
-
-		if (devnull != -1) {
-			(void) dup2(devnull, 0);
-			(void) dup2(devnull, 1);
-			(void) dup2(devnull, 2);
-			if (devnull > 2)
-				(void) close(devnull);
-		}
-	}
-	return (0);
-}
diff --git a/usr/src/lib/gss_mechs/mech_krb5/mapfile-vers b/usr/src/lib/gss_mechs/mech_krb5/mapfile-vers
index 50b3e46..bbe2bf4 100644
--- a/usr/src/lib/gss_mechs/mech_krb5/mapfile-vers
+++ b/usr/src/lib/gss_mechs/mech_krb5/mapfile-vers
@@ -144,7 +144,6 @@ SYMBOL_VERSION SUNWprivate_1.1 {
 	asn1buf_wrap_data;
 	com_err;
 	com_err_va;
-	daemon;
 	decode_krb5_alt_method;
 	decode_krb5_ap_rep;
 	decode_krb5_ap_rep_enc_part;
diff --git a/usr/src/lib/libresolv2/Makefile.com b/usr/src/lib/libresolv2/Makefile.com
index c02ae22..942d2a6 100644
--- a/usr/src/lib/libresolv2/Makefile.com
+++ b/usr/src/lib/libresolv2/Makefile.com
@@ -27,7 +27,7 @@
 LIBRARY= libresolv.a
 VERS= .2
 
-BSDOBJS=   	daemon.o	putenv.o	strcasecmp.o	strsep.o \
+BSDOBJS=   	putenv.o	strcasecmp.o	strsep.o \
 		ftruncate.o	readv.o		strdup.o	strtoul.o \
 		gettimeofday.o	setenv.o	strerror.o	utimes.o \
 		mktemp.o	setitimer.o	strpbrk.o	writev.o
diff --git a/usr/src/lib/libresolv2/common/bsd/daemon.c b/usr/src/lib/libresolv2/common/bsd/daemon.c
deleted file mode 100644
index 54ff83b..0000000
--- a/usr/src/lib/libresolv2/common/bsd/daemon.c
+++ /dev/null
@@ -1,81 +0,0 @@
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)daemon.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: daemon.c,v 1.2 2005/04/27 04:56:10 sra Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * 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.
- */
-
-#include "port_before.h"
-
-#include <fcntl.h>
-#include <paths.h>
-#include <unistd.h>
-
-#include "port_after.h"
-
-#ifndef NEED_DAEMON
-int __bind_daemon__;
-#else
-
-int
-daemon(int nochdir, int 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
-
-/*! \file */
diff --git a/usr/src/lib/libresolv2/common/mapfile-vers b/usr/src/lib/libresolv2/common/mapfile-vers
index a70aac2..cd2b90a 100644
--- a/usr/src/lib/libresolv2/common/mapfile-vers
+++ b/usr/src/lib/libresolv2/common/mapfile-vers
@@ -130,7 +130,6 @@ SYMBOL_VERSION SUNWprivate_2.1 {
 	__ctl_sendhelp;
 	__ctl_server;
 	__ctl_setcsctx;
-	daemon;
 	dn_count_labels;
 	__dn_count_labels;
 	dn_skipname;
diff --git a/usr/src/lib/libresolv2/include/port_after.h b/usr/src/lib/libresolv2/include/port_after.h
index c3abf4b..a88b8a5 100644
--- a/usr/src/lib/libresolv2/include/port_after.h
+++ b/usr/src/lib/libresolv2/include/port_after.h
@@ -46,7 +46,6 @@
 #undef NEED_PSELECT
 #undef HAVE_SA_LEN
 #undef HAVE_MINIMUM_IFREQ
-#define NEED_DAEMON 1
 #undef NEED_STRSEP
 #undef NEED_STRERROR
 #ifdef NEED_STRERROR
@@ -292,10 +291,6 @@ extern const struct in6_addr isc_in6addr_loopback;
 #define MAX(x,y) (((x) >= (y)) ? (x) : (y))
 #endif
 
-#ifdef NEED_DAEMON
-int daemon(int nochdir, int noclose);
-#endif
-
 #ifdef NEED_STRSEP
 char * strsep(char **stringp, const char *delim);
 #endif
-- 
1.7.3.2

