[libcamera-devel,1/3] libcamera: process: fix killing innocent processes unexpectedly

Message ID 20200725122442.1679820-2-vicamo.yang@canonical.com
State Accepted
Headers show
Series
  • fix test failures in package build systems
Related show

Commit Message

You-Sheng Yang July 25, 2020, 12:24 p.m. UTC
When a libcamera::process is being destructed or called kill() without a
previous successful call to start(), it's pid_ may remains -1, which
causes all the killable processes being killed when passed to
`kill(pid_, SIG_KILL)`.

Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
---
 src/libcamera/process.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart July 26, 2020, 10:42 p.m. UTC | #1
Hi You-Shang,

Thank you for the patch.

On Sat, Jul 25, 2020 at 08:24:40PM +0800, You-Sheng Yang wrote:
> When a libcamera::process is being destructed or called kill() without a
> previous successful call to start(), it's pid_ may remains -1, which
> causes all the killable processes being killed when passed to
> `kill(pid_, SIG_KILL)`.

Oops. This is embarassing :-)

> Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/libcamera/process.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
> index e816ee8..8311d27 100644
> --- a/src/libcamera/process.cpp
> +++ b/src/libcamera/process.cpp
> @@ -373,7 +373,8 @@ void Process::died(int wstatus)
>   */
>  void Process::kill()
>  {
> -	::kill(pid_, SIGKILL);
> +	if (pid_ > 0)
> +		::kill(pid_, SIGKILL);
>  }
>  
>  } /* namespace libcamera */
Kieran Bingham July 27, 2020, 9:30 a.m. UTC | #2
Hi You-Sheng,

On 26/07/2020 23:42, Laurent Pinchart wrote:
> Hi You-Shang,
> 
> Thank you for the patch.
> 
> On Sat, Jul 25, 2020 at 08:24:40PM +0800, You-Sheng Yang wrote:
>> When a libcamera::process is being destructed or called kill() without a
>> previous successful call to start(), it's pid_ may remains -1, which
>> causes all the killable processes being killed when passed to
>> `kill(pid_, SIG_KILL)`.
> 
> Oops. This is embarassing :-)

Ouch ouch ouch!


>> Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>



> 
>> ---
>>  src/libcamera/process.cpp | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
>> index e816ee8..8311d27 100644
>> --- a/src/libcamera/process.cpp
>> +++ b/src/libcamera/process.cpp
>> @@ -373,7 +373,8 @@ void Process::died(int wstatus)
>>   */
>>  void Process::kill()
>>  {
>> -	::kill(pid_, SIGKILL);
>> +	if (pid_ > 0)
>> +		::kill(pid_, SIGKILL);
>>  }
>>  
>>  } /* namespace libcamera */
>

Patch

diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp
index e816ee8..8311d27 100644
--- a/src/libcamera/process.cpp
+++ b/src/libcamera/process.cpp
@@ -373,7 +373,8 @@  void Process::died(int wstatus)
  */
 void Process::kill()
 {
-	::kill(pid_, SIGKILL);
+	if (pid_ > 0)
+		::kill(pid_, SIGKILL);
 }
 
 } /* namespace libcamera */