Optimize inotify watches and add error handling#6
Closed
assisted-by-ai wants to merge 0 commit intoKicksecure:masterfrom
Closed
Optimize inotify watches and add error handling#6assisted-by-ai wants to merge 0 commit intoKicksecure:masterfrom
assisted-by-ai wants to merge 0 commit intoKicksecure:masterfrom
Conversation
ArrayBolt3
reviewed
Apr 10, 2026
Contributor
ArrayBolt3
left a comment
There was a problem hiding this comment.
Accepted with tweaks in ArrayBolt3@32edffb.
Comment on lines
+519
to
+531
| ## Only watch for events that are actually handled by INotifyEventHandler. | ||
| ## Using ALL_EVENTS would waste inotify resources on events like IN_ACCESS, | ||
| ## IN_OPEN, IN_CLOSE_NOWRITE, etc. that are never processed. | ||
| watch_mask: int = ( | ||
| pyinotify.IN_MODIFY | ||
| | pyinotify.IN_CREATE | ||
| | pyinotify.IN_DELETE | ||
| | pyinotify.IN_MOVED_FROM | ||
| | pyinotify.IN_MOVED_TO | ||
| | pyinotify.IN_DELETE_SELF | ||
| | pyinotify.IN_MOVE_SELF | ||
| ) | ||
|
|
Contributor
There was a problem hiding this comment.
Accepted, but the comment isn't necessary.
Comment on lines
+525
to
+565
| GlobalData.watch_manager.add_watch( | ||
| ret: dict[str, int] = GlobalData.watch_manager.add_watch( | ||
| GlobalData.tor_path, | ||
| pyinotify.ALL_EVENTS, | ||
| rec=True, | ||
| watch_mask, | ||
| ) | ||
| GlobalData.watch_manager.add_watch( | ||
| for path, wd in ret.items(): | ||
| if wd < 0: | ||
| logging.error( | ||
| "Failed to add inotify watch for '%s'!", path, | ||
| ) | ||
| ret = GlobalData.watch_manager.add_watch( | ||
| GlobalData.torrc_path, | ||
| pyinotify.ALL_EVENTS, | ||
| rec=True, | ||
| watch_mask, | ||
| ) | ||
| for path, wd in ret.items(): | ||
| if wd < 0: | ||
| logging.error( | ||
| "Failed to add inotify watch for '%s'!", path, | ||
| ) | ||
| if found_sdwdate_path: | ||
| GlobalData.watch_manager.add_watch( | ||
| ret = GlobalData.watch_manager.add_watch( | ||
| GlobalData.sdwdate_status_path, | ||
| pyinotify.ALL_EVENTS, | ||
| watch_mask, | ||
| ) | ||
| for path, wd in ret.items(): | ||
| if wd < 0: | ||
| logging.error( | ||
| "Failed to add inotify watch for '%s'!", path, | ||
| ) |
Contributor
There was a problem hiding this comment.
Accepted, but refactored to be less repetitive.
| @@ -0,0 +1 @@ | |||
| __pycache__/ | |||
b4cc199 to
e0deac3
Compare
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.
Summary
Improved inotify watch setup by replacing broad event monitoring with a targeted mask and added error handling for watch creation failures.
Key Changes
Optimized inotify event mask: Replaced
pyinotify.ALL_EVENTSwith a specificwatch_maskcontaining only the events actually handled byINotifyEventHandler(IN_MODIFY, IN_CREATE, IN_DELETE, IN_MOVED_FROM, IN_MOVED_TO, IN_DELETE_SELF, IN_MOVE_SELF). This reduces unnecessary inotify resource consumption from unprocessed events like IN_ACCESS, IN_OPEN, and IN_CLOSE_NOWRITE.Added error handling: Implemented validation of
add_watch()return values for all three watch paths (tor_path, torrc_path, sdwdate_status_path). Failed watches (indicated by negative watch descriptors) are now logged as errors.Removed recursive watching: Removed the
rec=Trueparameter fromadd_watch()calls, simplifying the watch configuration.Added .gitignore: Added
__pycache__/to .gitignore to exclude Python cache directories from version control.Implementation Details
The
add_watch()method returns a dictionary mapping paths to watch descriptors. Watch descriptors less than 0 indicate failures, which are now properly detected and logged for debugging purposes.https://claude.ai/code/session_019HiJXyxtYfp1BQDgAPjEqd