Skip to content

Commit 5f73d2b

Browse files
committed
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 <[email protected]>
1 parent 8528813 commit 5f73d2b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tests/framework/utils.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""Generic utility functions that are used in the framework."""
4+
import errno
45
import functools
56
import json
67
import logging
@@ -453,7 +454,9 @@ def get_process_pidfd(pid):
453454
"""Get a pidfd file descriptor for the process with PID `pid`
454455
455456
Will return a pid file descriptor for the process with PID `pid` if it is
456-
still alive. If the process has already exited it will return `None`.
457+
still alive. If the process has already exited we will receive either a
458+
`ProcessLookupError` exception or and an `OSError` exception with errno `EINVAL`.
459+
In these cases, we will return `None`.
457460
458461
Any other error while calling the system call, will raise an OSError
459462
exception.
@@ -462,6 +465,11 @@ def get_process_pidfd(pid):
462465
pidfd = os.pidfd_open(pid)
463466
except ProcessLookupError:
464467
return None
468+
except OSError as err:
469+
if err.errno == errno.EINVAL:
470+
return None
471+
472+
raise
465473

466474
return pidfd
467475

0 commit comments

Comments
 (0)