Fix handle FileNotFoundError from os.getcwd()#828
Open
nathan9513-aps wants to merge 1 commit into
Open
Conversation
When the process is started from a directory that has been deleted (e.g. a temporary ABRT spool directory removed before the reporter is invoked), os.getcwd() raises FileNotFoundError (ENOENT). Wrap the call in a try/except and fall back to '/' as a safe placeholder. The real dump directory is always supplied via the -d option and will override this default during argument parsing.
Author
|
@msrb Could you take a look at this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Related Bugzilla issue: https://bugzilla.redhat.com/show_bug.cgi?id=2477455
What this PR does: This PR fixes a crash occurring at startup in reporter-bugzilla when the process is invoked from a directory that no longer exists.
Root Cause: When reporter-bugzilla is started, it attempts to fetch the current working directory using os.getcwd() (line 379). However, if the reporter is spawned from a temporary directory (e.g. an ABRT spool directory) that gets deleted before the Python process is fully initialized, the underlying getcwd(2) syscall fails with ENOENT, which in Python raises a FileNotFoundError. This causes the script to crash immediately.
python
Traceback (most recent call last):
File "/usr/bin/reporter-bugzilla", line 379, in
dump_dir_name = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory
Fix: Wrapped the os.getcwd() call in a try/except block to catch the FileNotFoundError. If the error occurs, it falls back to / as a safe placeholder directory.
This is perfectly safe because dump_dir_name will be properly overridden shortly after by the required -d DIR option during argument parsing (or it will fail gracefully downstream with a proper libreport error if no dump directory is provided).
Testing done:
Verified that reporter-bugzilla no longer crashes with a traceback when run from a deleted directory.
Checked that normal execution via the -d parameter continues to work flawlessly.