From: Christian Brauner Date: Thu, 24 May 2018 18:45:29 +0000 (+0200) Subject: utils: fix task_blocking_signal() X-Git-Tag: lxc-2.0.10~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbf93af1859be3c142fad54315ef5acd34096ce0;p=thirdparty%2Flxc.git utils: fix task_blocking_signal() sscanf() skips whitespace anyway so don't account for tabs in case the file layout changes. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 0056a4287..b76766a64 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -1829,11 +1829,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. diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 665012e93..56d64b4ae 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -1769,17 +1769,16 @@ int lxc_strmunmap(void *addr, size_t length) /* 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) @@ -1790,10 +1789,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; }