Skip to content

Commit

Permalink
fix(ci): condition for a non-existent process
Browse files Browse the repository at this point in the history
`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]>
  • Loading branch information
bchalios committed Oct 24, 2024
1 parent 8528813 commit 5f73d2b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/framework/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit 5f73d2b

Please sign in to comment.