diff options
author | Britney Fransen <brfransen@gmail.com> | 2017-01-20 16:53:38 (GMT) |
---|---|---|
committer | Britney Fransen <brfransen@gmail.com> | 2017-01-20 16:53:38 (GMT) |
commit | 6d8692bba331b7a24205e4f9bb1b91dfa6d4d6d4 (patch) | |
tree | 443e6b7f12822b8a0a3fdb5a290757a817e7eb5b /abs/core/util-linux/0001-lsns-Fix-parser-for-proc-pid-stat-which-is-including.patch | |
parent | 95d651edb72e7b278c9ba02e9afa64eb6a0d911e (diff) | |
parent | d0b37ccccc013118824437c8afdf3c48dd4d6530 (diff) | |
download | linhes_pkgbuild-6d8692bba331b7a24205e4f9bb1b91dfa6d4d6d4.zip linhes_pkgbuild-6d8692bba331b7a24205e4f9bb1b91dfa6d4d6d4.tar.gz linhes_pkgbuild-6d8692bba331b7a24205e4f9bb1b91dfa6d4d6d4.tar.bz2 |
Merge branch 'testing'
Diffstat (limited to 'abs/core/util-linux/0001-lsns-Fix-parser-for-proc-pid-stat-which-is-including.patch')
-rw-r--r-- | abs/core/util-linux/0001-lsns-Fix-parser-for-proc-pid-stat-which-is-including.patch | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/abs/core/util-linux/0001-lsns-Fix-parser-for-proc-pid-stat-which-is-including.patch b/abs/core/util-linux/0001-lsns-Fix-parser-for-proc-pid-stat-which-is-including.patch new file mode 100644 index 0000000..b13f189 --- /dev/null +++ b/abs/core/util-linux/0001-lsns-Fix-parser-for-proc-pid-stat-which-is-including.patch @@ -0,0 +1,79 @@ +From 3fcbd7978980dc1a29c626b701333e27599e506d Mon Sep 17 00:00:00 2001 +From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> +Date: Wed, 23 Nov 2016 14:13:34 +0900 +Subject: [PATCH] lsns: Fix parser for /proc/<pid>/stat which is including + space in comm + +For example, child process of spamd has + + 32031 (spamd child) S 32026 32026 32026 0 -1 4210752 338 0 0 0 ... + +fscanf("%d %*s %c %d*[^\n]") in read_process() can't parse above as we +expected, because %s only skips non-whitespace. I.e. it parses like +following, + + 32031 (spamd child) S 32026 32026 32026 0 -1 4210752 338 0 0 0 ... + +---+ +----+ + + %d %*s %c + +and returns 2 (pid=32031, state=c). + +This fixes it by skipping task->comm part manually. + +Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> +--- + sys-utils/lsns.c | 30 ++++++++++++++++++++++++++---- + 1 file changed, 26 insertions(+), 4 deletions(-) + +diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c +index e4fd208..809737c 100644 +--- a/sys-utils/lsns.c ++++ b/sys-utils/lsns.c +@@ -217,6 +217,30 @@ static int get_ns_ino(int dir, const char *nsname, ino_t *ino) + return 0; + } + ++static int parse_proc_stat(FILE *fp, pid_t *pid, char *state, pid_t *ppid) ++{ ++ char *line = NULL, *p; ++ size_t len = 0; ++ int rc; ++ ++ if (getline(&line, &len, fp) < 0) { ++ rc = -errno; ++ goto error; ++ } ++ ++ p = strrchr(line, ')'); ++ if (p == NULL || ++ sscanf(line, "%d (", pid) != 1 || ++ sscanf(p, ") %c %d*[^\n]", state, ppid) != 2) { ++ rc = -EINVAL; ++ goto error; ++ } ++ rc = 0; ++ ++error: ++ free(line); ++ return rc; ++} + + static int read_process(struct lsns *ls, pid_t pid) + { +@@ -255,11 +279,9 @@ static int read_process(struct lsns *ls, pid_t pid) + rc = -errno; + goto done; + } +- rc = fscanf(f, "%d %*s %c %d*[^\n]", &p->pid, &p->state, &p->ppid); +- if (rc != 3) { +- rc = rc < 0 ? -errno : -EINVAL; ++ rc = parse_proc_stat(f, &p->pid, &p->state, &p->ppid); ++ if (rc < 0) + goto done; +- } + rc = 0; + + for (i = 0; i < ARRAY_SIZE(p->ns_ids); i++) { +-- +2.10.2 + |