]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: fix task_blocking_signal() 2348/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 24 May 2018 18:45:29 +0000 (20:45 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 24 May 2018 20:34:20 +0000 (22:34 +0200)
sscanf() skips whitespace anyway so don't account for tabs in case the file
layout changes.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxccontainer.c
src/lxc/utils.c

index 16182332ce9d81ab9ae78d2dd38c39ae7c00d515..02c7e09a9265845dc23b1589379c1a4252796983 100644 (file)
@@ -2000,11 +2000,10 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout)
                return true;
 
        /* Detect whether we should send SIGRTMIN + 3 (e.g. systemd). */
-       if (task_blocking_signal(pid, (SIGRTMIN + 3)))
-               haltsignal = (SIGRTMIN + 3);
-
        if (c->lxc_conf && c->lxc_conf->haltsignal)
                haltsignal = c->lxc_conf->haltsignal;
+       else if (task_blocking_signal(pid, (SIGRTMIN + 3)))
+               haltsignal = (SIGRTMIN + 3);
 
        /* Add a new state client before sending the shutdown signal so that we
         * don't miss a state.
index 82403dfc69ea38dbf83fb0582c226cab4d26b9f0..4d9eea87e7d9d816ddb38edeb557668ea17998d2 100644 (file)
@@ -1814,17 +1814,16 @@ int lxc_count_file_lines(const char *fn)
 
 /* Check whether a signal is blocked by a process. */
 /* /proc/pid-to-str/status\0 = (5 + 21 + 7 + 1) */
-#define __PROC_STATUS_LEN (5 + (LXC_NUMSTRLEN64) + 7 + 1)
+#define __PROC_STATUS_LEN (6 + (LXC_NUMSTRLEN64) + 7 + 1)
 bool task_blocking_signal(pid_t pid, int signal)
 {
-       bool bret = false;
-       char *line = NULL;
-       long unsigned int sigblk = 0;
-       size_t n = 0;
        int ret;
-       FILE *f;
-
        char status[__PROC_STATUS_LEN];
+       FILE *f;
+       long unsigned int sigblk = 0;
+       size_t n = 0;
+       bool bret = false;
+       char *line = NULL;
 
        ret = snprintf(status, __PROC_STATUS_LEN, "/proc/%d/status", pid);
        if (ret < 0 || ret >= __PROC_STATUS_LEN)
@@ -1835,10 +1834,10 @@ bool task_blocking_signal(pid_t pid, int signal)
                return bret;
 
        while (getline(&line, &n, f) != -1) {
-               if (strncmp(line, "SigBlk:\t", 8))
+               if (strncmp(line, "SigBlk:", 7))
                        continue;
 
-               if (sscanf(line + 8, "%lx", &sigblk) != 1)
+               if (sscanf(line + 7, "%lx", &sigblk) != 1)
                        goto out;
        }