Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- (breaking) the `unset_env` parameters were split off into separate unsafe functions
- (breaking) `watchdog_enabled` now returns `Option<Duration>`
- the MSRV is now defined as 1.82

### Fixed
- fixed `watchdog_enabled` to handle missing `WATCHDOG_PID`

## [0.4.5] - 2025-01-18

Expand Down Expand Up @@ -35,42 +39,42 @@

### Changed

- added `watchdog_enabled` (similar to [`sd_watchdog_enabled`](https://www.freedesktop.org/software/systemd/man/sd_watchdog_enabled.html))
- added `watchdog_enabled` (similar to [`sd_watchdog_enabled`](https://www.freedesktop.org/software/systemd/man/sd_watchdog_enabled.html))

## [0.4.0] - 2022-01-12

### Changed

- (breaking) `NotifyState::Status`, `NotifyState::BusError` and `NotifyState::Custom` now contain a `&str` instead of a `String`
- the crate is now using the 2021 edition
- (breaking) `NotifyState::Status`, `NotifyState::BusError` and `NotifyState::Custom` now contain a `&str` instead of a `String`
- the crate is now using the 2021 edition

## [0.3.0] - 2021-02-25

### Changed

- (breaking) `listen_fds` now returns an iterator over `RawFd` values
- (breaking) `SD_LISTEN_FDS_START` is gone
- (breaking) `listen_fds` now returns an iterator over `RawFd` values
- (breaking) `SD_LISTEN_FDS_START` is gone

## [0.2.0] - 2021-02-18

### Changed

- (breaking) changed the `NotifyState::MainPid` and `NotifyState::Error` data from `i32` to `u32`
- (breaking) changed `listen_fds` to return `Result<u32>` instead of `Result<i32>`
- (breaking) changed the `NotifyState::MainPid` and `NotifyState::Error` data from `i32` to `u32`
- (breaking) changed `listen_fds` to return `Result<u32>` instead of `Result<i32>`

### Fixed

- fixed `Display` implementation for `NotifyState::WatchdogUsec` and `NotifyState::ExtendTimeoutUsec`
- removed a stray debug print
- fixed `Display` implementation for `NotifyState::WatchdogUsec` and `NotifyState::ExtendTimeoutUsec`
- removed a stray debug print

## [0.1.1] - 2019-10-20

### Added

- `listen_fds` function for file descriptor retrieval when using socket activation
- `listen_fds` function for file descriptor retrieval when using socket activation

## [0.1.0] - 2019-09-22

### Added

- initial release
- initial release
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "sd-notify"
version = "0.5.0"
edition = "2021"
rust-version = "1.82"
description = "Lightweight crate for systemd service state notifications"
readme = "README.md"
keywords = ["systemd", "sd_notify"]
Expand Down
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,8 @@ pub fn watchdog_enabled() -> Option<Duration> {
let p = env::var(WATCHDOG_PID)
.ok()
.and_then(|s| u32::from_str(&s).ok());

match (s, p) {
(Some(usec_val), Some(pid)) if pid == process::id() => {
Some(Duration::from_micros(usec_val))
}
_ => None,
}
s.filter(|_| p.is_none_or(|pid| pid == process::id()))
.map(Duration::from_micros)
}

/// Asks the service manager for enabled watchdog.
Expand Down
19 changes: 17 additions & 2 deletions tests/watchdog_enabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,28 @@ fn watchdog_enabled() {
assert!(env::var_os("WATCHDOG_USEC").is_none());
assert!(env::var_os("WATCHDOG_PID").is_none());

// no usec, no pip no unset env
// valid usec, no pid
unsafe {
env::set_var("WATCHDOG_USEC", "10");
}

unsafe {
assert_eq!(
sd_notify::watchdog_enabled_and_unset_env(),
Some(Duration::from_micros(10))
);
}

assert!(env::var_os("WATCHDOG_USEC").is_none());
assert!(env::var_os("WATCHDOG_PID").is_none());

// no usec, no pid, no unset env
assert_eq!(sd_notify::watchdog_enabled(), None);

assert!(env::var_os("WATCHDOG_USEC").is_none());
assert!(env::var_os("WATCHDOG_PID").is_none());

// valid pip
// valid pid
unsafe {
env::set_var("WATCHDOG_USEC", "5");
env::set_var("WATCHDOG_PID", process::id().to_string());
Expand Down
Loading