You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `enable_events` is convenient for a process that enables the audit
daemon once. However, when there is a need to disable/enable at will,
it does not work well.
For example, take something like this:
```
let (connection, handle, receiver) = new_connection().unwrap();
tokio::task::spawn(connection);
// Works well
handle.enable_events().await.unwrap();
...
// Now disable audit:
drop((handle, receiver));
// Now we want to re-enable audit:
let (connection, handle, receiver) = new_connection().unwrap();
tokio::task::spawn(connection);
// This fails on errno: -17, ie EEXIST
handle.enable_events().await.unwrap();
```
The reason this fails is because, while the drop did disable audit,
the pid is still set. The second call to enable_events thus fails
because the "AUDIT_SET_PID" call returns EEXIST (pid is already set to
this exact pid).
Now, it could be possible to handle the EEXIST error on `enable_events`
and consider that this is OK. However, it's not necessarily clear on
which parameter this error is returned (the SET_PID or the SET_ENABLED).
In addition, there is still the issue that we disabled audit,
while letting the pid set, which is a bit ugly.
By adding the two lower levels helpers (set_enabled, set_pid), it is
possible to do things more cleanly:
```
let (connection, handle, receiver) = new_connection().unwrap();
tokio::task::spawn(connection);
// Works well
handle.set_pid(std::process::id()).await.unwrap();
handle.set_enabled(true).await.unwrap();
// Now disable audit:
handle.set_pid(0).await.unwrap();
handle.set_enabled(false).await.unwrap();
drop((handle, receiver));
// Now we want to re-enable audit:
let (connection, handle, receiver) = new_connection().unwrap();
tokio::task::spawn(connection);
// Works well
handle.set_pid(std::process::id()).await.unwrap();
handle.set_enabled(true).await.unwrap();
```
0 commit comments