fix error of not define HAVE_SETSID
authorPeng Haitao <penght@cn.fujitsu.com>
Fri, 6 Jan 2012 06:48:18 +0000 (14:48 +0800)
committerRainer Gerhards <rgerhards@adiscon.com>
Mon, 16 Jan 2012 16:12:57 +0000 (17:12 +0100)
[add list to the CC list]

When HAVE_SETSID is not defined, rsyslogd will use ioctl() make itself to daemon,
but this can not make rsyslogd process become the process group leader of a new
process group. In RHEL6.1, the status is as follows:
# uname -a
Linux RHEL6U1GA-Intel64-199 2.6.32-131.0.15.el6.x86_64 #1 SMP Tue May 10 15:42:40 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
# /etc/init.d/rsyslog restart
Shutting down system logger:                               [  OK  ]
Starting system logger:                                    [  OK  ]
# ps axo pgrp,ppid,pid,comm | grep rsyslog
 6290     1  6301 rsyslogd

When we send SIGTERM signal to 6290, rsyslogd will die:( So I think we should
call setpgid() before ioctl().

Signed-off-by: Peng Haitao <penght@cn.fujitsu.com>
tools/syslogd.c

index 6879baf..6577040 100644 (file)
@@ -460,8 +460,15 @@ void untty(void)
 #else
 {
        int i;
+       pid_t pid;
 
        if(!Debug) {
+               pid = getpid();
+               if (setpgid(pid, pid) < 0) {
+                       perror("setpgid");
+                       exit(1);
+               }
+
                i = open(_PATH_TTY, O_RDWR|O_CLOEXEC);
                if (i >= 0) {
 #                      if !defined(__hpux)