Package: log2mail
Version: 0.3.0
Severity: normal
Tags: patch

[EMAIL PROTECTED] discovered a bug in log2mail which does not
detach from the terminal it was started in.  Attached is a fix to solve
that problem.

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.17-1-k7
Locale: [EMAIL PROTECTED], [EMAIL PROTECTED] (charmap=ISO-8859-15)
Gemeinsame Unterverzeichnisse: log2mail-0.3.0-vanilla/debian und log2mail-0.3.0/debian.
diff -u log2mail-0.3.0-vanilla/main.cc log2mail-0.3.0/main.cc
--- log2mail-0.3.0-vanilla/main.cc	2004-10-04 22:44:48.000000000 +0200
+++ log2mail-0.3.0/main.cc	2006-09-17 12:08:15.067656500 +0200
@@ -20,6 +20,8 @@
 #include <stdarg.h>
 #include <syslog.h>
 #include <signal.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
 
 void usage (char *name) {
   printf("usage: %s [-f config file] [-l] [-N] [-V] [-v] [-h|?]\n", name);
@@ -167,6 +169,17 @@
     openlog("log2mail", LOG_PID, LOG_DAEMON);
   }
 
+
+  /* detach from terminal */
+  int fdtty = open("/dev/tty", O_RDWR, 0);
+  if (fdtty != -1) {
+    ioctl(fdtty, (int) TIOCNOTTY, (char *)0);
+    close(fdtty);
+  }
+
+  /* close fds */
+  for (int i=0;i<3;i++) close(i);
+
   /* install signal handler */
   if (SIG_ERR == signal(SIGTERM, sigHandler)) {
     printlog(LOG_ERR, "signal handler for SIGTERM not installed: %m");

Reply via email to