From 5f73d2bfb9b28254b2fa415929bcc23420979ffd Mon Sep 17 00:00:00 2001 From: Babis Chalios Date: Wed, 23 Oct 2024 12:01:14 +0200 Subject: [PATCH] fix(ci): condition for a non-existent process `pidfd_open` will fail if there is not a process with the requested PID. According to `man pidfd_open(2)`, it will return EINVAL when `PID` is not valid and `ESRCH` when the `PID` does not exist. Right now, we were checking only for the latter condition. Change the logic to also care for the former, which materializes as an OSError exception with errno == EINVAL. Signed-off-by: Babis Chalios --- tests/framework/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/framework/utils.py b/tests/framework/utils.py index 88e520fa5f3..dbae40016ea 100644 --- a/tests/framework/utils.py +++ b/tests/framework/utils.py @@ -1,6 +1,7 @@ # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """Generic utility functions that are used in the framework.""" +import errno import functools import json import logging @@ -453,7 +454,9 @@ def get_process_pidfd(pid): """Get a pidfd file descriptor for the process with PID `pid` Will return a pid file descriptor for the process with PID `pid` if it is - still alive. If the process has already exited it will return `None`. + still alive. If the process has already exited we will receive either a + `ProcessLookupError` exception or and an `OSError` exception with errno `EINVAL`. + In these cases, we will return `None`. Any other error while calling the system call, will raise an OSError exception. @@ -462,6 +465,11 @@ def get_process_pidfd(pid): pidfd = os.pidfd_open(pid) except ProcessLookupError: return None + except OSError as err: + if err.errno == errno.EINVAL: + return None + + raise return pidfd