Occasionally iscisd will send a SIGTERM to pid 0, causing
all sorts of weird things. Problem is that pid == 0 is
a valid return value for log_init(), so that all routines
only check for pid < 0. However, as the signal handler
is inherited from the parent, even the logging thread
has a signal handler installed, for which the internal
pid is always '0'. So when a SIGTERM is send to the
logging thread, it'll forward the signal to PID 0.

References: bnc#589064

Signed-off-by: Hannes Reinecke <h...@suse.de>

diff --git a/usr/iscsid.c b/usr/iscsid.c
index 50c9b58..2e234fc 100644
--- a/usr/iscsid.c
+++ b/usr/iscsid.c
@@ -345,14 +345,6 @@ int main(int argc, char *argv[])
        struct sigaction sa_new;
        pid_t pid;
 
-       /* do not allow ctrl-c for now... */
-       sa_new.sa_handler = catch_signal;
-       sigemptyset(&sa_new.sa_mask);
-       sa_new.sa_flags = 0;
-       sigaction(SIGINT, &sa_new, &sa_old );
-       sigaction(SIGPIPE, &sa_new, &sa_old );
-       sigaction(SIGTERM, &sa_new, &sa_old );
-
        while ((ch = getopt_long(argc, argv, "c:i:fd:nu:g:p:vh", long_options,
                                 &longindex)) >= 0) {
                switch (ch) {
@@ -398,6 +390,14 @@ int main(int argc, char *argv[])
        if (log_pid < 0)
                exit(1);
 
+       /* do not allow ctrl-c for now... */
+       sa_new.sa_handler = catch_signal;
+       sigemptyset(&sa_new.sa_mask);
+       sa_new.sa_flags = 0;
+       sigaction(SIGINT, &sa_new, &sa_old );
+       sigaction(SIGPIPE, &sa_new, &sa_old );
+       sigaction(SIGTERM, &sa_new, &sa_old );
+
        sysfs_init();
        if (idbm_init(iscsid_get_config_file)) {
                log_close(log_pid);
diff --git a/usr/log.c b/usr/log.c
index 62500cb..2eeee8e 100644
--- a/usr/log.c
+++ b/usr/log.c
@@ -458,6 +458,8 @@ void log_close(pid_t pid)
                return;
        }
 
-       kill(pid, SIGTERM);
-       waitpid(pid, &status, 0);
+       if (pid > 0) {
+               kill(pid, SIGTERM);
+               waitpid(pid, &status, 0);
+       }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.

Reply via email to