From 855a1377e6792b4bb5435fd1f91f4d46a84ec0b0 Mon Sep 17 00:00:00 2001 From: yellowhatter Date: Tue, 17 Sep 2024 11:44:03 +0300 Subject: [PATCH] Review fixes --- commons/zenoh-shm/src/api/cleanup.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/commons/zenoh-shm/src/api/cleanup.rs b/commons/zenoh-shm/src/api/cleanup.rs index 9b2fa2c50f..dda3637a07 100644 --- a/commons/zenoh-shm/src/api/cleanup.rs +++ b/commons/zenoh-shm/src/api/cleanup.rs @@ -16,14 +16,20 @@ use crate::cleanup::CLEANUP; /// Make forced cleanup /// NOTE: this is a part of a temporary on-exit-cleanup workaround and it will be very likely removed in the future. +/// WARN: The improper usage can break the application logic, impacting SHM-utilizing Sessions in other processes. +/// Cleanup unlinks SHM segments _created_ by current process from filesystem with the following consequences: +/// - Sessions that are not linked to this segment will fail to link it if they try. Such kind of errors are properly handled. +/// - Already linked processes will still have this shared memory mapped and safely accessible +/// - The actual memory will be reclaimed by the OS only after last process using it will close it or exit +/// /// In order to properly cleanup some SHM internals upon process exit, Zenoh installs exit handlers (see atexit() API). -/// The atexit handler is executed only on process exit(), the inconvenience is that terminating signal handlers (like SIGINT) -/// bypass it and terminate the process without cleanup. To eliminate this effect, Zenoh overrides SIGHUP, SIGTERM, SIGINT -/// and SIGQUIT handlers and calls exit() inside to make graceful shutdown. If user is going to override these Zenoh's handlers, -/// the workaround will break, and there are two ways to keep this workaround working: +/// The atexit handler is executed only on process exit(), the inconvenience is that terminating signal handlers +/// (like SIGINT) bypass it and terminate the process without cleanup. To eliminate this effect, Zenoh overrides +/// SIGHUP, SIGTERM, SIGINT and SIGQUIT handlers and calls exit() inside to make graceful shutdown. If user is going to +/// override these Zenoh's handlers, the workaround will break, and there are two ways to keep this workaround working: /// - execute overridden Zenoh handlers in overriding handler code -/// - call forced_cleanup() anywhere at any time before terminating the process +/// - call force_cleanup_before_exit() anywhere at any time before terminating the process #[zenoh_macros::unstable_doc] -pub fn forced_cleanup() { +pub fn force_cleanup_before_exit() { CLEANUP.read().cleanup(); }