[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAG48ez0MyiTKO2MpNVQqavoTKo7FZXYAyohx1JTR=M9Uw=QJWQ@mail.gmail.com>
Date: Fri, 11 Oct 2019 17:09:29 +0200
From: Jann Horn <jannh@...gle.com>
To: Christian Kellner <ckellner@...hat.com>
Cc: kernel list <linux-kernel@...r.kernel.org>,
Linux API <linux-api@...r.kernel.org>,
Christian Kellner <christian@...lner.me>,
Christian Brauner <christian@...uner.io>,
Shuah Khan <shuah@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
"Peter Zijlstra (Intel)" <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>, Michal Hocko <mhocko@...e.com>,
Thomas Gleixner <tglx@...utronix.de>,
Elena Reshetova <elena.reshetova@...el.com>,
Roman Gushchin <guro@...com>,
Andrea Arcangeli <aarcange@...hat.com>,
"Joel Fernandes (Google)" <joel@...lfernandes.org>,
Al Viro <viro@...iv.linux.org.uk>,
"Dmitry V. Levin" <ldv@...linux.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@...r.kernel.org>
Subject: Re: [PATCH v2 2/2] pidfd: add tests for NSpid info in fdinfo
On Wed, Oct 9, 2019 at 6:10 PM Christian Kellner <ckellner@...hat.com> wrote:
> Add tests that check that if pid namespaces are configured the fdinfo
> file of a pidfd contains an NSpid: entry containing the process id
> in the current and additionally all nested namespaces.
[...]
> +static int compare_fdinfo_nspid(int pidfd, char *expect, size_t len)
> +{
> + char path[512];
> + FILE *f;
> + size_t n = 0;
> + ssize_t k;
> + char *line = NULL;
> + int r = -1;
> +
> + snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", pidfd);
(Maybe at some point the selftests code should add some more concise
alternative to snprintf() calls on separate lines. A macro or
something like that so that you can write stuff like `f =
fopen(tprintf("/proc/self/fdinfo/%d", pidfd), "re")`.)
> + f = fopen(path, "re");
> + if (!f)
> + return -1;
> +
> + while ((k = getline(&line, &n, f)) != -1) {
> + if (strncmp(line, "NSpid:", 6))
> + continue;
> +
> + line[k - 1] = '\0';
> + ksft_print_msg("Child: fdinfo NSpid line: '%s'.\n", line);
> + r = strncmp(line + 6, expect, len);
Wouldn't it be better to get rid of the nullbyte assignment and change
the strncmp() into a strcmp() here...
[...]
> + /* The child will have pid 1 in the new pid namespace,
> + * so the line must be 'NSPid:\t<pid>\t1'
> + */
> + n = snprintf(expect, sizeof(expect), "\t%d\t%d", pid, 1);
... and add a "\n" to the format string? It's shorter and doesn't
silently ignore it if the line doesn't end at that point.
Powered by blists - more mailing lists