@@ -34,6 +34,7 @@ use std::os::unix::io::RawFd;
3434use std:: os:: unix:: net:: UnixDatagram ;
3535use std:: process;
3636use std:: str:: FromStr ;
37+ use std:: time:: Duration ;
3738
3839use libc:: CLOCK_MONOTONIC ;
3940
@@ -472,10 +473,13 @@ fn fd_cloexec(fd: u32) -> io::Result<()> {
472473/// ```no_run
473474/// # use sd_notify;
474475/// #
475- /// let mut usec = 0;
476- /// let enabled = sd_notify::watchdog_enabled(&mut usec);
476+ /// if let Some(duration) = sd_notify::watchdog_enabled() {
477+ /// // watchdog enabled with `duration`
478+ /// } else {
479+ /// // watchdog disabled
480+ /// }
477481/// ```
478- pub fn watchdog_enabled ( usec : & mut u64 ) -> bool {
482+ pub fn watchdog_enabled ( ) -> Option < Duration > {
479483 let s = env:: var ( WATCHDOG_USEC )
480484 . ok ( )
481485 . and_then ( |s| u64:: from_str ( & s) . ok ( ) ) ;
@@ -485,10 +489,9 @@ pub fn watchdog_enabled(usec: &mut u64) -> bool {
485489
486490 match ( s, p) {
487491 ( Some ( usec_val) , Some ( pid) ) if pid == process:: id ( ) => {
488- * usec = usec_val;
489- true
492+ Some ( Duration :: from_micros ( usec_val) )
490493 }
491- _ => false ,
494+ _ => None ,
492495 }
493496}
494497
@@ -504,8 +507,8 @@ pub fn watchdog_enabled(usec: &mut u64) -> bool {
504507/// preconditions. See its safety documentation for more details. It can only
505508/// be safely called before threads are spawned, in particular before any
506509/// `tokio` runtime initialization or `#[tokio::main]`.
507- pub unsafe fn watchdog_enabled_and_unset_env ( usec : & mut u64 ) -> bool {
508- let result = watchdog_enabled ( usec ) ;
510+ pub unsafe fn watchdog_enabled_and_unset_env ( ) -> Option < Duration > {
511+ let result = watchdog_enabled ( ) ;
509512 unsafe {
510513 env:: remove_var ( WATCHDOG_USEC ) ;
511514 env:: remove_var ( WATCHDOG_PID ) ;
0 commit comments