New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exception handling around fapd handle is_active() call #560
Changes from 8 commits
51b240c
a97e3a8
941215a
df8fc46
2a837e8
93f59b3
ff82265
b5bede9
167f9ff
9cdbbf3
167d0d9
2a10fe0
5eee4a2
8270b6b
6b01a66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
import logging | ||
import os | ||
import sys | ||
import subprocess | ||
|
||
|
||
|
@@ -209,15 +210,16 @@ def _status(self): | |
logging.debug("fapd is currently DISABLED") | ||
return ServiceStatus.UNKNOWN | ||
elif self.mode == FapdMode.ONLINE: | ||
try: | ||
if self._fapd_lock.acquire(blocking=False): | ||
if self._fapd_lock.acquire(blocking=False): | ||
try: | ||
bStatus = ServiceStatus(self._fapd_ref.is_active()) | ||
if bStatus != self._fapd_status: | ||
logging.debug(f"_status({bStatus} updated") | ||
self._fapd_status = bStatus | ||
self._fapd_lock.release() | ||
except Exception: | ||
logging.warning("Daemon monitor query/update dispatch failed.") | ||
except Exception: | ||
logging.warning("Daemon status query/update failed.") | ||
|
||
self._fapd_lock.release() | ||
return self._fapd_status | ||
else: | ||
logging.debug("fapd is in a PROFILING session") | ||
|
@@ -227,10 +229,15 @@ def _status(self): | |
return ServiceStatus.FALSE | ||
|
||
def capture_online_state(self): | ||
logging.debug("capture_online_state()") | ||
updated_online_state = ServiceStatus(self._fapd_ref.is_active()) | ||
self._fapd_prior_online_state = updated_online_state | ||
self._fapd_cur_online_state = updated_online_state | ||
logging.debug("capture_online_state(): Capturing current online status") | ||
if self._fapd_lock.acquire(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, |
||
try: | ||
updated_online_state = ServiceStatus(self._fapd_ref.is_active()) | ||
self._fapd_prior_online_state = updated_online_state | ||
self._fapd_cur_online_state = updated_online_state | ||
except Exception: | ||
logging.warning("Daemon online status query/update failed.") | ||
self._fapd_lock.release() | ||
logging.debug(f"prior_online_state = {self._fapd_prior_online_state}") | ||
|
||
def revert_online_state(self): | ||
|
@@ -241,9 +248,14 @@ def revert_online_state(self): | |
|
||
def initial_daemon_status(self): | ||
if self._fapd_lock.acquire(): | ||
self._fapd_ref = Handle("fapolicyd") | ||
if self._fapd_ref.is_valid(): | ||
self._fapd_status = ServiceStatus(self._fapd_ref.is_active()) | ||
else: | ||
self._fapd_status = ServiceStatus.UNKNOWN | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and again. |
||
self._fapd_ref = Handle("fapolicyd") | ||
if self._fapd_ref.is_valid(): | ||
self._fapd_status = ServiceStatus(self._fapd_ref.is_active()) | ||
else: | ||
self._fapd_status = ServiceStatus.UNKNOWN | ||
except Exception as e: | ||
print(f"Fapd Handle is_valid() or is_active() exception: {e}", | ||
file=sys.stderr) | ||
raise | ||
self._fapd_lock.release() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use a
with
block here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into that approach originally. The fly/ointment thing is the blocking=False argument, i.e. if the lock is not available then don't wait and return False. Fapd control operations (start/stop) are given priority over the never-ending periodic status requests.
Still digging around. I would still prefer to have locking somewhere given the status requests and stop/start requests originate on differing threads. I don't care if it's under the hood in rust-land or not.