From: "Alex Bennée" <alex.bennee@linaro.org>
To: Brice Goglin <Brice.Goglin@inria.fr>
Cc: "Ludovic Courtes" <ludovic.courtes@inria.fr>,
"Riku Voipio" <riku.voipio@iki.fi>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Laurent Vivier" <laurent@vivier.eu>
Subject: Re: [PATCH v1 10/11] linux-user: fix /proc/self/stat handling
Date: Sat, 11 Apr 2020 14:00:55 +0100 [thread overview]
Message-ID: <87r1wu89dk.fsf@linaro.org> (raw)
In-Reply-To: <5ffb4cc2-f397-28b1-ec63-eb9d606439cf@inria.fr>
Brice Goglin <Brice.Goglin@inria.fr> writes:
> Le 10/04/2020 à 14:33, Alex Bennée a écrit :
>> That was by inspection on my system which seems to truncate a lot
>> earlier. It would be nice to find where in the Linux kernel it is
>> output but I failed to grep the relevant function last night.
>
>
> It's in proc/array.c, do_task_stat() calls proc_task_name(). In the end,
> it seems to use task->tcomm or task->comm which is limited by
>
> #define TASK_COMM_LEN 16
Thanks. I'll amend the commit message. Are you happy with the fix on
your end?
>
> Brice
>
>
>
>>
>> On Fri, 10 Apr 2020, 12:11 Philippe Mathieu-Daudé, <philmd@redhat.com
>> <mailto:philmd@redhat.com>> wrote:
>>
>> Cc'ing Ludovic in case he can test with Guix-HPC.
>>
>> On 4/9/20 11:15 PM, Alex Bennée wrote:
>> > In the original bug report long files names in Guix caused
>> > /proc/self/stat be truncated without the trailing ") " as
>> specified in
>> > proc manpage which says:
>> > (2) comm %s
>> > The filename of the executable, in parentheses. This
>> > is visible whether or not the executable is swapped
>> > out.
>> >
>> > Additionally it should only be reporting the executable name rather
>> > than the full path. Fix both these failings while cleaning up
>> the code
>> > to use GString to build up the reported values. As the whole
>> function
>> > is cleaned up also adjust the white space to the current coding
>> style.
>> >
>> > Message-ID: <fb4c55fa-d539-67ee-c6c9-de8fb63c8488@inria.fr
>> <mailto:fb4c55fa-d539-67ee-c6c9-de8fb63c8488@inria.fr>>
>> > Reported-by: Brice Goglin <Brice.Goglin@inria.fr
>> <mailto:Brice.Goglin@inria.fr>>
>> > Cc: Philippe_Mathieu-Daudé <philmd@redhat.com
>> <mailto:philmd@redhat.com>>
>> > Signed-off-by: Alex Bennée <alex.bennee@linaro.org
>> <mailto:alex.bennee@linaro.org>>
>> > ---
>> > linux-user/syscall.c | 43
>> +++++++++++++++++++------------------------
>> > 1 file changed, 19 insertions(+), 24 deletions(-)
>> >
>> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> > index 6495ddc4cda..674f70e70a5 100644
>> > --- a/linux-user/syscall.c
>> > +++ b/linux-user/syscall.c
>> > @@ -7295,34 +7295,29 @@ static int open_self_stat(void *cpu_env,
>> int fd)
>> > {
>> > CPUState *cpu = env_cpu((CPUArchState *)cpu_env);
>> > TaskState *ts = cpu->opaque;
>> > - abi_ulong start_stack = ts->info->start_stack;
>> > + g_autoptr(GString) buf = g_string_new(NULL);
>> > int i;
>> >
>> > for (i = 0; i < 44; i++) {
>> > - char buf[128];
>> > - int len;
>> > - uint64_t val = 0;
>> > -
>> > - if (i == 0) {
>> > - /* pid */
>> > - val = getpid();
>> > - snprintf(buf, sizeof(buf), "%"PRId64 " ", val);
>> > - } else if (i == 1) {
>> > - /* app name */
>> > - snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]);
>> > - } else if (i == 27) {
>> > - /* stack bottom */
>> > - val = start_stack;
>> > - snprintf(buf, sizeof(buf), "%"PRId64 " ", val);
>> > - } else {
>> > - /* for the rest, there is MasterCard */
>> > - snprintf(buf, sizeof(buf), "0%c", i == 43 ? '\n' : ' ');
>> > - }
>> > + if (i == 0) {
>> > + /* pid */
>> > + g_string_printf(buf, FMT_pid " ", getpid());
>> > + } else if (i == 1) {
>> > + /* app name */
>> > + gchar *bin = g_strrstr(ts->bprm->argv[0], "/");
>> > + bin = bin ? bin + 1 : ts->bprm->argv[0];
>> > + g_string_printf(buf, "(%.15s) ", bin);
>>
>> 15 or 125? 15 seems short. From your previous test I understood it
>> was
>> 124, for
>> sizeof("cat_with9_12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890___40").
>>
>> > + } else if (i == 27) {
>> > + /* stack bottom */
>> > + g_string_printf(buf, TARGET_ABI_FMT_ld " ",
>> ts->info->start_stack);
>> > + } else {
>> > + /* for the rest, there is MasterCard */
>> > + g_string_printf(buf, "0%c", i == 43 ? '\n' : ' ');
>> > + }
>> >
>> > - len = strlen(buf);
>> > - if (write(fd, buf, len) != len) {
>> > - return -1;
>> > - }
>> > + if (write(fd, buf->str, buf->len) != buf->len) {
>> > + return -1;
>> > + }
>> > }
>> >
>> > return 0;
>> >
>>
--
Alex Bennée
next prev parent reply other threads:[~2020-04-11 13:01 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-09 21:15 [PATCH for 5.0-rc3 v1 00/11] more random fixes Alex Bennée
2020-04-09 21:15 ` [PATCH v1 01/11] linux-user: completely re-write init_guest_space Alex Bennée
2020-04-09 21:15 ` [PATCH v1 02/11] exec/cpu-all: Use bool for have_guest_base Alex Bennée
2020-04-10 10:59 ` Philippe Mathieu-Daudé
2020-04-09 21:15 ` [PATCH v1 03/11] accel/tcg: Relax va restrictions on 64-bit guests Alex Bennée
2020-04-09 21:15 ` [PATCH v1 04/11] linux-user/ppc: Fix padding in mcontext_t for ppc64 Alex Bennée
2020-04-09 21:15 ` [PATCH v1 05/11] tests/docker: add docs FEATURE flag and use for test-misc Alex Bennée
2020-04-10 10:58 ` Philippe Mathieu-Daudé
2020-04-10 14:40 ` Richard Henderson
2020-04-09 21:15 ` [PATCH v1 06/11] configure: redirect sphinx-build check to config.log Alex Bennée
2020-04-10 10:56 ` Philippe Mathieu-Daudé
2020-04-10 14:37 ` Richard Henderson
2020-04-09 21:15 ` [PATCH v1 07/11] configure: disable PIE for Windows builds Alex Bennée
2020-04-09 21:15 ` [Bug 1871798] " Alex Bennée
2020-04-09 22:51 ` Howard Spoelstra
2020-04-09 22:51 ` [Bug 1871798] " Howard Spoelstra
2020-04-10 10:55 ` Philippe Mathieu-Daudé
2020-04-10 10:55 ` [Bug 1871798] " Philippe Mathieu-Daudé
2020-04-10 14:42 ` Richard Henderson
2020-04-09 21:15 ` [PATCH v1 08/11] target/m68k/helper: Fix m68k_fpu_gdb_get_reg() use of GByteArray Alex Bennée
2020-04-10 14:44 ` Richard Henderson
2020-04-09 21:15 ` [PATCH v1 09/11] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Alex Bennée
2020-04-10 13:08 ` Stefano Garzarella
2020-04-11 12:58 ` Alex Bennée
2020-04-14 7:48 ` Stefano Garzarella
2020-04-11 17:14 ` Philippe Mathieu-Daudé
2020-04-10 14:44 ` Richard Henderson
2020-04-09 21:15 ` [PATCH v1 10/11] linux-user: fix /proc/self/stat handling Alex Bennée
2020-04-10 11:11 ` Philippe Mathieu-Daudé
2020-04-10 12:33 ` Alex Bennée
2020-04-10 12:47 ` Philippe Mathieu-Daudé
2020-04-10 13:21 ` Brice Goglin
2020-04-11 13:00 ` Alex Bennée [this message]
2020-04-10 14:51 ` Richard Henderson
2020-04-09 21:15 ` [PATCH v1 11/11] .travis.yml: Build OSX 10.14 with Xcode 10.0 Alex Bennée
2020-04-14 10:17 ` Daniel P. Berrangé
2020-04-09 23:31 ` [PATCH for 5.0-rc3 v1 00/11] more random fixes no-reply
-- strict thread matches above, loose matches on Subject: below --
2020-04-15 10:42 [PULL for 5.0-rc3 0/8] a few small fixes (docker, user, pie and gdbstub) Alex Bennée
2020-04-15 10:42 ` [PULL 1/8] tests/docker: add docs FEATURE flag and use for test-misc Alex Bennée
2020-04-15 10:42 ` [PULL 2/8] configure: redirect sphinx-build check to config.log Alex Bennée
2020-04-15 10:42 ` [PULL 3/8] configure: disable PIE for Windows builds Alex Bennée
2020-04-15 10:42 ` [Bug 1871798] " Alex Bennée
2020-04-15 10:42 ` [PULL 4/8] linux-user: fix /proc/self/stat handling Alex Bennée
2020-04-15 10:42 ` [PULL 5/8] target/m68k/helper: Fix m68k_fpu_gdb_get_reg() use of GByteArray Alex Bennée
2020-04-15 10:42 ` [PULL 6/8] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Alex Bennée
2020-04-15 10:42 ` [PULL 7/8] gdbstub: Do not use memset() on GByteArray Alex Bennée
2020-04-15 10:42 ` [PULL 8/8] gdbstub: Introduce gdb_get_float32() to get 32-bit float registers Alex Bennée
2020-04-15 12:16 ` [PULL for 5.0-rc3 0/8] a few small fixes (docker, user, pie and gdbstub) Peter Maydell
2020-04-14 20:06 [PATCH v2 for 5.0-rc3 00/17] more randome fixes (user, pie, docker " Alex Bennée
2020-04-14 20:06 ` [PATCH v2 01/17] linux-user: completely re-write init_guest_space Alex Bennée
2020-04-14 20:06 ` [PATCH v2 02/17] exec/cpu-all: Use bool for have_guest_base Alex Bennée
2020-04-14 20:06 ` [PATCH v2 03/17] accel/tcg: Relax va restrictions on 64-bit guests Alex Bennée
2020-04-14 20:06 ` [PATCH v2 04/17] .gitignore: include common build sub-directories Alex Bennée
2020-04-14 20:06 ` [PATCH v2 05/17] linux-user/ppc: Fix padding in mcontext_t for ppc64 Alex Bennée
2020-04-14 20:06 ` [PATCH v2 06/17] tests/docker: add docs FEATURE flag and use for test-misc Alex Bennée
2020-04-14 20:06 ` [PATCH v2 07/17] configure: redirect sphinx-build check to config.log Alex Bennée
2020-04-14 20:06 ` [PATCH v2 08/17] configure: disable PIE for Windows builds Alex Bennée
2020-04-14 20:06 ` [Bug 1871798] " Alex Bennée
2020-04-14 20:06 ` [PATCH v2 09/17] linux-user: fix /proc/self/stat handling Alex Bennée
2020-04-14 20:06 ` [PATCH v2 10/17] target/m68k/helper: Fix m68k_fpu_gdb_get_reg() use of GByteArray Alex Bennée
2020-04-14 20:06 ` [PATCH v2 11/17] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Alex Bennée
2020-04-14 20:06 ` [PATCH v2 12/17] gdbstub: Do not use memset() on GByteArray Alex Bennée
2020-04-14 20:06 ` [PATCH v2 13/17] gdbstub: Introduce gdb_get_float32() to get 32-bit float registers Alex Bennée
2020-04-14 21:20 ` Richard Henderson
2020-04-14 20:06 ` [PATCH v2 14/17] gdbstub: Introduce gdb_get_float64() to get 64-bit " Alex Bennée
2020-04-14 21:22 ` Richard Henderson
2020-04-14 20:06 ` [PATCH v2 15/17] target/m68k: hack around the FPU register support (HACK!) Alex Bennée
2020-04-14 20:06 ` [PATCH v2 16/17] tests/tcg: drop inferior.was_attached() test Alex Bennée
2020-04-14 20:06 ` [PATCH v2 17/17] tests/tcg: add a multiarch linux-user gdb test Alex Bennée
2020-04-15 1:42 ` [PATCH v2 for 5.0-rc3 00/17] more randome fixes (user, pie, docker and gdbstub) no-reply
2020-04-09 8:43 [Bug 1871798] [NEW] Fails to start on Windows host without explicit --disable-pie James Le Cuirot
2020-04-09 8:51 ` [Bug 1871798] " Alex Bennée
2020-04-09 17:27 ` Alex Bennée
2020-04-09 18:39 ` James Le Cuirot
2020-04-09 19:31 ` James Le Cuirot
2020-04-09 23:04 ` James Le Cuirot
2020-04-18 13:41 ` Philippe Mathieu-Daudé
2020-04-30 13:45 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1wu89dk.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=Brice.Goglin@inria.fr \
--cc=laurent@vivier.eu \
--cc=ludovic.courtes@inria.fr \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).