[PATCH v2 1/3] support: Add support_process_state_wait

Adhemerval Zanella adhemerval.zanella@linaro.org
Tue Feb 18 17:52:00 GMT 2020



On 18/02/2020 12:17, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> +/* Wait for process PID to reach state STATE.  It can be a combination of
>> +   multiple possible states ('process_state_running | process_state_sleeping')
>> +   where the function return when any of these state are observed.
>> +   The timeout POLL_TS might be used to wait before polling the PID status
>> +   information from the kernel.  A NULL value will set to use a default
>> +   value (10000000 ns).
>> +   For an invalid state not represented by SUPPORT_PROCESS_STATE, it fallbacks
>> +   to a 2 second sleep.  */
>> +void support_process_state_wait (pid_t pid, enum support_process_state state,
>> +				 struct timespec *poll_ts);
> 
> The comment should say what happens if the timeout expires.  And I
> believe the argument should be a const struct timespec *.  But I don't
> see how controlling the poll interval is useful.

Thinking twice the poll interval really does not add much here,
I have removed it.

> 
>> diff --git a/support/xgetline.c b/support/xgetline.c
>> new file mode 100644
>> index 0000000000..5b010bcf56
>> --- /dev/null
>> +++ b/support/xgetline.c
>> @@ -0,0 +1,34 @@
>> +/* fopen with error checking.
>> +   Copyright (C) 2016-2019 Free Software Foundation, Inc.
>> +   This file is part of the GNU C Library.
>> +
>> +   The GNU C Library is free software; you can redistribute it and/or
>> +   modify it under the terms of the GNU Lesser General Public
>> +   License as published by the Free Software Foundation; either
>> +   version 2.1 of the License, or (at your option) any later version.
>> +
>> +   The GNU C Library is distributed in the hope that it will be useful,
>> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> +   Lesser General Public License for more details.
>> +
>> +   You should have received a copy of the GNU Lesser General Public
>> +   License along with the GNU C Library; if not, see
>> +   <https://www.gnu.org/licenses/>.  */
>> +
>> +#include <support/xstdio.h>
>> +
>> +#include <support/check.h>
>> +#include <errno.h>
>> +
>> +ssize_t
>> +xgetline (char **lineptr, size_t *n, FILE *stream)
>> +{
>> +  int old_errno = errno;
>> +  errno = 0;
>> +  ssize_t ret = getline (lineptr, n, stream);
>> +  if (ret == -1 && errno != 0)
>> +    FAIL_EXIT1 ("getline failed: %m");
>> +  errno = old_errno;
>> +  return ret;
>> +}
> 
> I think it would be clearer to use ferror to check for errors.

Maybe: 

   if (ret == -1 || ferror (stream))
     ...

?

> 
> Rest of the patch looks okay.
> 
> Thanks,
> Florian
> 



More information about the Libc-alpha mailing list