@@ -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
@@ -474,10 +475,13 @@ fn fd_cloexec(fd: u32) -> io::Result<()> {
474475/// ```no_run
475476/// # use sd_notify;
476477/// #
477- /// let mut usec = 0;
478- /// let enabled = sd_notify::watchdog_enabled(&mut usec);
478+ /// if let Some(duration) = sd_notify::watchdog_enabled() {
479+ /// // watchdog enabled with `duration`
480+ /// } else {
481+ /// // watchdog disabled
482+ /// }
479483/// ```
480- pub fn watchdog_enabled ( usec : & mut u64 ) -> bool {
484+ pub fn watchdog_enabled ( ) -> Option < Duration > {
481485 let s = env:: var ( WATCHDOG_USEC )
482486 . ok ( )
483487 . and_then ( |s| u64:: from_str ( & s) . ok ( ) ) ;
@@ -487,10 +491,9 @@ pub fn watchdog_enabled(usec: &mut u64) -> bool {
487491
488492 match ( s, p) {
489493 ( Some ( usec_val) , Some ( pid) ) if pid == process:: id ( ) => {
490- * usec = usec_val;
491- true
494+ Some ( Duration :: from_micros ( usec_val) )
492495 }
493- _ => false ,
496+ _ => None ,
494497 }
495498}
496499
@@ -506,8 +509,8 @@ pub fn watchdog_enabled(usec: &mut u64) -> bool {
506509/// preconditions. See its safety documentation for more details. It can only
507510/// be safely called before threads are spawned, in particular before any
508511/// `tokio` runtime initialization or `#[tokio::main]`.
509- pub unsafe fn watchdog_enabled_and_unset_env ( usec : & mut u64 ) -> bool {
510- let result = watchdog_enabled ( usec ) ;
512+ pub unsafe fn watchdog_enabled_and_unset_env ( ) -> Option < Duration > {
513+ let result = watchdog_enabled ( ) ;
511514 unsafe {
512515 env:: remove_var ( WATCHDOG_USEC ) ;
513516 env:: remove_var ( WATCHDOG_PID ) ;
0 commit comments