Index: libbb/vfork_daemon_rexec.c
===================================================================
--- libbb/vfork_daemon_rexec.c	(revision 22578)
+++ libbb/vfork_daemon_rexec.c	(working copy)
@@ -267,12 +267,15 @@
 		dup2(fd, 1);
 		dup2(fd, 2);
 	}
-	while (fd > 2) {
-		close(fd--);
-		if (!(flags & DAEMON_CLOSE_EXTRA_FDS))
-			return;
-		/* else close everything after fd#2 */
+	if (flags & DAEMON_CLOSE_EXTRA_FDS) {
+		/* close everything after fd#2 */
+		for (fd = getdtablesize()-1; fd > 2; fd--) {
+			close(fd);
+		}
 	}
+	else if (fd > 2) {
+		close(fd);
+	}
 }
 
 void bb_sanitize_stdio(void)
