qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: linux-user: keep the name-ending parenthesis in /proc/self/stat


From: Alex Bennée
Subject: Re: linux-user: keep the name-ending parenthesis in /proc/self/stat
Date: Thu, 09 Apr 2020 20:59:00 +0100
User-agent: mu4e 1.3.10; emacs 28.0.50

Brice Goglin <address@hidden> writes:

> Le 09/04/2020 à 17:27, Alex Bennée a écrit :
>> Brice Goglin <address@hidden> writes:
>>
>>> 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.

Huh testing on my box here it seems to truncate a lot earlier than that:

20:54:41 [alex@zen:~/l/q/b/all] sanitiser/fixes-for-5.1|●1✚1…(+1/-1) +
./cat_with9_12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890___4567890
 /proc/self/stat
23132 (cat_with9_12345) R 15690 23132 15676 34827 23132 4194304 87 0 0 0 0 0 0 
0 20 0 1 0 133272440 6172672 188 18446744073709551615 94698916007936 
94698916032905 140729243846896 0 0 0 0 0 0 0 0 0 17 2 0 0 0 0 0 94698916052048 
94698916053600 94698933542912 140729243849857 140729243850006 140729243850006 
140729243852659 0

20:55:21 [alex@zen:~/l/q/b/all] sanitiser/fixes-for-5.1|●1✚1…(+1/-1) 126 +
./x86_64-linux-user/qemu-x86_64  
./cat_with9_12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890___4567890
 /proc/s
elf/stat
23519 
(./cat_with9_12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890___40
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 274903122400 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

>>>
>>> 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: Philippe_Mathieu-Daudé <address@hidden>
>>> Signed-off-by: Brice Goglin <address@hidden>
>>>
>>> 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, ") ");
>> why not just use a format string:
>>
>>   snprintf(buf, sizeof(buf), "(%.125s) ", ts->bprm->argv[0]);
>>
>
> Go ahead and apply what you want (maybe 124 instead of 125 because of
> the ending \0).
>
> My commit message above explains how to test things very quickly.
>
> I don't use qemu-user or Guix myself, and I can't spend time
> debugging/testing this further.
>
> Thank you
>
> Brice


-- 
Alex Bennée



reply via email to

[Prev in Thread] Current Thread [Next in Thread]