diff --git a/ChangeLog b/ChangeLog
index ec17797..31d1ebb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-02-14  Stef Walter  <stef@memberwebs.com>
 
+	* daemon/gkr-daemon.c: Close stdin/stdout when not running
+	in foreground. Fixes bug #571781
+	
+2009-02-14  Stef Walter  <stef@memberwebs.com>
+
 	* configure.in: Bump version number.
 
 === gnome-keyring 2.25.91 ===
diff --git a/daemon/gkr-daemon.c b/daemon/gkr-daemon.c
index 25c3770..b7b3119 100644
--- a/daemon/gkr-daemon.c
+++ b/daemon/gkr-daemon.c
@@ -579,31 +579,32 @@ fork_and_print_environment (void)
 		exit (0);
 	}
 	
-	if (!run_daemonized) 
-		return;
-	
-	/* Double fork if need to daemonize properly */
-	pid = fork ();
+	if (run_daemonized) { 
+		
+		/* Double fork if need to daemonize properly */
+		pid = fork ();
 	
-	if (pid != 0) {
+		if (pid != 0) {
 
-		/* Here we are in the intermediate child process */
-			
-		/* 
-		 * This process exits, so that the final child will inherit 
-		 * init as parent to avoid zombies
-		 */
-		if (pid == -1)
-			exit (1);
-
-		/* We've done two forks. Now we know the PID */
-		print_environment (pid);
-			
-		/* The intermediate child exits */
-		exit (0);
+			/* Here we are in the intermediate child process */
+				
+			/* 
+			 * This process exits, so that the final child will inherit 
+			 * init as parent to avoid zombies
+			 */
+			if (pid == -1)
+				exit (1);
+	
+			/* We've done two forks. Now we know the PID */
+			print_environment (pid);
+				
+			/* The intermediate child exits */
+			exit (0);
+		}
+		
 	}
 
-	/* Here we are in the resulting daemon process. */
+	/* Here we are in the resulting daemon or background process. */
 
 	for (i = 0; i < 3; ++i) {
 		fd = open ("/dev/null", O_RDONLY);
