svn commit: r189426 - in stable/7: usr.bin/bluetooth/rfcomm_sppd usr.sbin/bluetooth/hcsecd usr.sbin/bluetooth/hcseriald usr.sbin/bluetooth/rfcomm_pppd

Maksim Yevmenkin emax at FreeBSD.org
Thu Mar 5 17:34:31 PST 2009


Author: emax
Date: Fri Mar  6 01:34:30 2009
New Revision: 189426
URL: http://svn.freebsd.org/changeset/base/189426

Log:
  MFC r188130
  
  Clenup code a bit and do not call fork(2) before dameon(3) where not needed.

Modified:
  stable/7/usr.bin/bluetooth/rfcomm_sppd/   (props changed)
  stable/7/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
  stable/7/usr.sbin/bluetooth/hcsecd/   (props changed)
  stable/7/usr.sbin/bluetooth/hcsecd/hcsecd.c
  stable/7/usr.sbin/bluetooth/hcseriald/   (props changed)
  stable/7/usr.sbin/bluetooth/hcseriald/hcseriald.c
  stable/7/usr.sbin/bluetooth/rfcomm_pppd/   (props changed)
  stable/7/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c

Modified: stable/7/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c
==============================================================================
--- stable/7/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c	Fri Mar  6 01:27:51 2009	(r189425)
+++ stable/7/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c	Fri Mar  6 01:34:30 2009	(r189426)
@@ -281,22 +281,8 @@ main(int argc, char *argv[]) 
 	}
 
 	/* Became daemon if required */
-	if (background) {
-		switch (fork()) {
-		case -1:
-			err(1, "Could not fork()");
-			/* NOT REACHED */
-
-		case 0:
-			exit(0);
-			/* NOT REACHED */
-
-		default:
-			if (daemon(0, 0) < 0)
-				err(1, "Could not daemon()");
-			break;
-		}
-	}
+	if (background && daemon(0, 0) < 0)
+		err(1, "Could not daemon()");
 
 	openlog(SPPD_IDENT, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_DAEMON);
 	syslog(LOG_INFO, "Starting on %s...", (tty != NULL)? tty : "stdin/stdout");

Modified: stable/7/usr.sbin/bluetooth/hcsecd/hcsecd.c
==============================================================================
--- stable/7/usr.sbin/bluetooth/hcsecd/hcsecd.c	Fri Mar  6 01:27:51 2009	(r189425)
+++ stable/7/usr.sbin/bluetooth/hcsecd/hcsecd.c	Fri Mar  6 01:34:30 2009	(r189426)
@@ -128,9 +128,8 @@ main(int argc, char *argv[])
 			(void * const) &filter, sizeof(filter)) < 0)
 		err(1, "Could not set HCI socket filter");
 
-	if (detach)
-		if (daemon(0, 0) < 0)
-			err(1, "Could not daemon()ize");
+	if (detach && daemon(0, 0) < 0)
+		err(1, "Could not daemon()ize");
 
 	openlog(HCSECD_IDENT, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_DAEMON);
 

Modified: stable/7/usr.sbin/bluetooth/hcseriald/hcseriald.c
==============================================================================
--- stable/7/usr.sbin/bluetooth/hcseriald/hcseriald.c	Fri Mar  6 01:27:51 2009	(r189425)
+++ stable/7/usr.sbin/bluetooth/hcseriald/hcseriald.c	Fri Mar  6 01:34:30 2009	(r189426)
@@ -101,23 +101,10 @@ main(int argc, char *argv[])
 	/* Open device */
 	n = open_device(device, speed, name);
 
-	if (detach) {
-		pid_t	pid = fork();
-
-		if (pid == (pid_t) -1) {
-			syslog(LOG_ERR, "Could not fork(). %s (%d)",
-				strerror(errno), errno);
-			exit(1);
-		}
-
-		if (pid != 0)
-			exit(0);
-
-		if (daemon(0, 0) < 0) {
-			syslog(LOG_ERR, "Could not daemon(0, 0). %s (%d)",
-				strerror(errno), errno);
-			exit(1);
-		}
+	if (detach && daemon(0, 0) < 0) {
+		syslog(LOG_ERR, "Could not daemon(0, 0). %s (%d)",
+			strerror(errno), errno);
+		exit(1);
 	}
 
 	/* Write PID file */

Modified: stable/7/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c
==============================================================================
--- stable/7/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c	Fri Mar  6 01:27:51 2009	(r189425)
+++ stable/7/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c	Fri Mar  6 01:34:30 2009	(r189426)
@@ -166,22 +166,10 @@ main(int argc, char *argv[])
 
 	openlog(RFCOMM_PPPD, LOG_PID | LOG_PERROR | LOG_NDELAY, LOG_USER);
 
-	if (detach) {
-		pid = fork();
-		if (pid == (pid_t) -1) {
-			syslog(LOG_ERR, "Could not fork(). %s (%d)",
-				strerror(errno), errno);
-			exit(1);
-		}
-
-		if (pid != 0)
-			exit(0);
-
-		if (daemon(0, 0) < 0) {
-			syslog(LOG_ERR, "Could not daemon(0, 0). %s (%d)",
-				strerror(errno), errno);
-			exit(1);
-		}
+	if (detach && daemon(0, 0) < 0) {
+		syslog(LOG_ERR, "Could not daemon(0, 0). %s (%d)",
+			strerror(errno), errno);
+		exit(1);
 	}
 
 	s = socket(PF_BLUETOOTH, SOCK_STREAM, BLUETOOTH_PROTO_RFCOMM);


More information about the svn-src-all mailing list