Your message dated Sat, 18 Jul 2009 11:59:05 +0200
with message-id <[email protected]>
and subject line Fixed
has caused the Debian Bug report #452728,
regarding nbd-client doesn't detach from terminal properly
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
452728: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=452728
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: nbd-client
Version: 1:2.9.9-1
Severity: minor
Tags: patch

Hi,

nbd-client doesn't detach itself fully from the terminal when it forks:

# lsof -p 3610
[...]
nbd-clien 3610 root    0u   CHR  136,0              2 /dev/pts/0
nbd-clien 3610 root    1u   CHR  136,0              2 /dev/pts/0
nbd-clien 3610 root    2u   CHR  136,0              2 /dev/pts/0
[...]

The attached patch fixes that.

Cheers, Til
=== nbd-client.c
==================================================================
--- nbd-client.c	(revision 5)
+++ nbd-client.c	(local)
@@ -183,6 +183,8 @@
 	int sdp=0;
 	u64 size64;
 	u32 flags;
+	pid_t pid;
+	int  i;
 
 	logging();
 
@@ -275,12 +277,30 @@
 	set_timeout(nbd, timeout);
 	finish_sock(sock, nbd, swap);
 
+#ifndef NOFORK
 	/* Go daemon */
-	
-	chdir("/");
-#ifndef NOFORK
-	if (fork())
-		exit(0);
+	umask(0);
+	if (chdir("/") < 0)
+		perror("Cannot change directory to /");
+	/* lose controlling terminal */
+	pid = fork();
+	if (pid < 0)
+		perror("Cannot fork");
+	else if (pid != 0)
+		exit(0);	/* parent */
+	setsid();
+	/* make sure we never gain it again */
+	pid = fork();
+	if (pid < 0)
+		perror("Cannot fork");
+	else if (pid != 0)
+		exit(0);	/* parent */
+	/* detach file descriptors */
+	for (i = 0; i < 3; i++)
+		close(i);
+	(void)open("/dev/null", O_RDWR);
+	(void)dup(0);
+	(void)dup(0);
 #endif
 
 	do {

--- End Message ---
--- Begin Message ---
Version: 1:2.9.13-1

I apparently forgot to note this in the changelog, but this bug was
fixed with the upload of the 2.9.13 upstream release.

Regards,

-- 
The biometric identification system at the gates of the CIA headquarters
works because there's a guard with a large gun making sure no one is
trying to fool the system.
  http://www.schneier.com/blog/archives/2009/01/biometrics.html


--- End Message ---

Reply via email to