qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Brice Goglin <Brice.Goglin@inria.fr>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	qemu-devel@nongnu.org, "Laurent Vivier" <laurent@vivier.eu>
Subject: Re: linux-user: keep the name-ending parenthesis in /proc/self/stat
Date: Wed, 8 Apr 2020 08:40:06 +0200	[thread overview]
Message-ID: <197d29e7-c26d-9c55-6278-f37da0dd760e@inria.fr> (raw)
In-Reply-To: <4ac78bc6-35d6-5705-9e75-4e48436d8589@inria.fr>

Le 31/03/2020 à 00:29, Brice Goglin a écrit :
> Le 31/03/2020 à 00:05, Philippe Mathieu-Daudé a écrit :
>> On 3/30/20 9:07 PM, Brice Goglin wrote:
>>> When the program name is very long, qemu-user may truncate it in
>>> /proc/self/stat. However the truncation must keep the ending ") "
>>> to conform to the 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.
>>>
>>> To reproduce:
>>> $ ln -s /bin/cat <filenamewithmorethan128chars>
>>> $ qemu-x86_64 ./<filenamewithmorethan128chars> /proc/self/stat
>>>
>>> Before the patch, you get:
>>> 1134631 (<filenametruncated>0 0 0 0 0 0 0 0 ...
>>> After the patch:
>>> 1134631 (<filenametruncat>) 0 0 0 0 0 0 0 0 ...
>>>
>>> This fixes an issue with hwloc failing to parse /proc/self/stat
>>> when Ludovic Courtes was testing it in guix over qemu-aarch64.
>>>
>>> Signed-off-by: Brice Goglin<Brice.Goglin@inria.fr>
>>>
>>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>>> index 5af55fca78..a1126dcf5b 100644
>>> --- a/linux-user/syscall.c
>>> +++ b/linux-user/syscall.c
>>> @@ -7305,7 +7305,10 @@ static int open_self_stat(void *cpu_env, int fd)
>>>           snprintf(buf, sizeof(buf), "%"PRId64 " ", val);
>>>         } else if (i == 1) {
>>>           /* app name */
>>> -        snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]);
>>> +        len = snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]);
>>> +        if (len >= sizeof(buf))
>>> +          /* bring back the ending ") " that was truncated */
>>> +          strcpy(buf+sizeof(buf)-3, ") ");
>> Maybe we can avoid the sprintf() call:
>>
>> -- >8 --
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -7305,7 +7305,11 @@ static int open_self_stat(void *cpu_env, int fd)
>>          snprintf(buf, sizeof(buf), "%"PRId64 " ", val);
>>        } else if (i == 1) {
>>          /* app name */
>> -        snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]);
>> +        char *ptr = buf;
>> +
>> +        *ptr++ = '(';
>> +        ptr = stpncpy(ptr, ts->bprm->argv[0], sizeof(buf) - 3);
>> +        strcpy(ptr, ") ");
>>        } else if (i == 27) {
>>          /* stack bottom */
>>          val = start_stack;
>>
> This works too.


Hello

Is anybody going to fix this anyhow for the next release?

Thank you

Brice




  reply	other threads:[~2020-04-08  6:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 19:07 linux-user: keep the name-ending parenthesis in /proc/self/stat Brice Goglin
2020-03-30 22:05 ` Philippe Mathieu-Daudé
2020-03-30 22:29   ` Brice Goglin
2020-04-08  6:40     ` Brice Goglin [this message]
2020-04-08  8:09       ` Laurent Vivier
  -- strict thread matches above, loose matches on Subject: below --
2020-04-08  8:24 Brice Goglin
2020-04-08 15:48 ` Laurent Vivier
2020-04-08 15:56   ` Brice Goglin
2020-04-09 15:27 ` Alex Bennée
2020-04-09 15:34   ` Brice Goglin
2020-04-09 19:59     ` Alex Bennée

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=197d29e7-c26d-9c55-6278-f37da0dd760e@inria.fr \
    --to=brice.goglin@inria.fr \
    --cc=laurent@vivier.eu \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).