[CRIU] [PATCH] posix-timer: take into account that sival_ptr can be NULL (v2)

Andrey Wagin avagin at gmail.com
Tue Feb 18 04:58:49 PST 2014


2014-02-18 15:39 GMT+04:00 Pavel Emelyanov <xemul at parallels.com>:
> On 02/18/2014 03:36 PM, Andrew Vagin wrote:
>> On Tue, Feb 18, 2014 at 03:23:02PM +0400, Pavel Emelyanov wrote:
>>> On 02/18/2014 02:07 PM, Andrey Vagin wrote:
>>>> ID: 0
>>>> signal: 26/          (null)
>>>> notify: signal/pid.5954
>>>> ClockID: 1
>>>>
>>>> fscanf "%p" doesn't handle "(null)".
>>>>
>>>> https://bugzilla.openvz.org/show_bug.cgi?id=2894
>>>>
>>>> v2: make the original scanf be %d/%s and then additionally
>>>>     parse the obtained string
>>>>
>>>> Signed-off-by: Andrey Vagin <avagin at openvz.org>
>>>> ---
>>>>  proc_parse.c | 12 ++++++++++--
>>>>  1 file changed, 10 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/proc_parse.c b/proc_parse.c
>>>> index 26dd9c4..5ecdc22 100644
>>>> --- a/proc_parse.c
>>>> +++ b/proc_parse.c
>>>> @@ -1277,16 +1277,17 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
>>>>     }
>>>>
>>>>     while (1) {
>>>> +           char pbuf[17]; /* 16 + eol */
>>>>             timer = xzalloc(sizeof(struct proc_posix_timer));
>>>>             if (timer == NULL)
>>>>                     goto err;
>>>>
>>>>             ret = fscanf(file, "ID: %ld\n"
>>>> -                              "signal: %d/%p\n"
>>>> +                              "signal: %d/%16s\n"
>>>>                                "notify: %6[a-z]/%3[a-z].%d\n"
>>>>                                "ClockID: %d\n",
>>>>                             &timer->spt.it_id,
>>>> -                           &timer->spt.si_signo, &timer->spt.sival_ptr,
>>>> +                           &timer->spt.si_signo, pbuf,
>>>>                             sigpid, tidpid, &pid_t,
>>>>                             &timer->spt.clock_id);
>>>>             if (ret != 7) {
>>>> @@ -1297,6 +1298,13 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
>>>>                     goto err;
>>>>             }
>>>>
>>>> +           timer->spt.sival_ptr = NULL;
>>>> +           if (sscanf(pbuf, "%p", &timer->spt.sival_ptr) != 1 &&
>>>> +               strstr(pbuf, "(null)") == NULL) {
>>>
>>> The strstr is overkill, better use strncmp for that case.
>>
>> It will look like this
>>
>> strncmp(pbuf, "          (null)", 16)
>
> This one is sucks the least :)

Actually scanf strips spaces, so it will look nice

>
>> or
>> strlen(pbuf) == 16 && strncmp(pbuf + 10, "(null)", 6)
>>
>>>
>>>> +                   xfree(timer);
>>>> +                   goto err;
>>>> +           }
>>>> +
>>>>             if ( tidpid[0] == 't') {
>>>>                     timer->spt.it_sigev_notify = SIGEV_THREAD_ID;
>>>>             } else {
>>>>
>>>
>>>
>> .
>>
>
>


More information about the CRIU mailing list