Function byztime::install_sigbus_handler[][src]

pub fn install_sigbus_handler() -> Result<()>

Install a signal handler for graceful recovery from page faults in the timedata file.

If the timedata file gets truncated after it has been opened, future accesses to it will raise SIGBUS. This function installs a signal handler that will allow whatever function was trying to access the truncated file to gracefully error out with EPROTO rather than crashing the program. If the SIGBUS was caused for some reason unrelated to a timedata access, this handler will reraise SIGBUS with the kernel default signal handler, which will cause the program to crash and dump core just as it normally would.

A timedata file getting truncated while open is not something that should ever ordinarily happen; it would indicate that the byztime daemon or some or other process that has write permissions to the file is buggy or malicious. Benign mistakes such as the user specifying a path that does not point to a valid timedata file are detected and handled without relying on SIGBUS. Nonetheless, this crate is designed such that even a malicious byztime server should not ever be able to cause a client to crash or hang, and it is necessary to be able to trap and recover from SIGBUS in order to uphold that guarantee.

Calling this function will replace whatever SIGBUS handler was previously installed, so use it only if nothing else in your program needs to handle SIGBUS. Otherwise, call byztime_sys::byztime_handle_sigbus (no safe wrapper provided) from within your custom signal handler.