Jelle de Jong <jelledej...@powercraft.nl> wrote:

Hi,

> Thanks for you quick, and useful information, this is really
> appreciated! Keep me in the loop of any progress.

The attached patch should fix your saned issue; add it to the package
as the last dpatch and you should be done.

Tell me how it goes.

Thanks,

JB.

-- 
 Julien BLACHE <jbla...@debian.org>  |  Debian, because code matters more 
 Debian & GNU/Linux Developer        |       <http://www.debian.org>
 Public key available on <http://www.jblache.org> - KeyID: F5D6 5169 
 GPG Fingerprint : 935A 79F1 C8B3 3521 FD62 7CC7 CD61 4FD7 F5D6 5169 

Index: saned.c
===================================================================
RCS file: /cvsroot/sane/sane-backends/frontend/saned.c,v
retrieving revision 1.66
diff -u -r1.66 saned.c
--- saned.c	26 Feb 2009 03:15:43 -0000	1.66
+++ saned.c	28 Feb 2009 20:37:01 -0000
@@ -3112,6 +3112,41 @@
 run_inetd (int argc, char **argv)
 {
   int fd = 1;
+  int dave_null;
+
+  /* Some backends really can't keep their dirty fingers off
+   * stdin/stdout/stderr; we work around them here so they don't
+   * mess up the network dialog and crash the remote net backend.
+   */
+  do
+    {
+      fd = dup (fd);
+
+      if (fd == -1)
+	{
+	  DBG (DBG_ERR, "run_inetd: duplicating fd failed: %s", strerror (errno));
+	  return;
+	}
+    }
+  while (fd < 3);
+
+  /* Our good'ole friend Dave Null to the rescue */
+  dave_null = open ("/dev/null", O_RDWR);
+  if (dave_null < 0)
+    {
+      DBG (DBG_ERR, "run_inetd: could not open /dev/null: %s", strerror (errno));
+      return;
+    }
+
+  close (STDIN_FILENO);
+  close (STDOUT_FILENO);
+  close (STDERR_FILENO);
+
+  dup2 (dave_null, STDIN_FILENO);
+  dup2 (dave_null, STDOUT_FILENO);
+  dup2 (dave_null, STDERR_FILENO);
+
+  close (dave_null);
 
 #ifndef HAVE_OS2_H
   /* Unused in this function */

Reply via email to