Skip to content

Commit

Permalink
Use libc instead of own definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Jan 15, 2025
1 parent 1c9943e commit 64ca63c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.4.4] - 2025-01-15

### Added

- added `NotifyState::MonotonicUsec`, for use with `Type=notify-reload`

## [0.4.3] - 2024-10-05

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[API docs]: https://docs.rs/sd-notify/badge.svg
[docs.rs]: https://docs.rs/sd-notify/

A lightweight (no dependencies) crate for sending `systemd` service state notifications.
A lightweight crate for sending `systemd` service state notifications.

## Quick start

Expand Down
10 changes: 0 additions & 10 deletions src/ffi.rs

This file was deleted.

18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ use std::str::FromStr;

use libc::CLOCK_MONOTONIC;

mod ffi;

/// Daemon notification for the service manager.
#[derive(Clone, Debug)]
pub enum NotifyState<'a> {
Expand Down Expand Up @@ -111,13 +109,15 @@ impl Display for NotifyState<'_> {
}

impl NotifyState<'_> {
/// Create a new NotifyState::MonotonicUsec using the current system monotonic time.
/// Create a new [`NotifyState::MonotonicUsec`] using the current system monotonic time.
///
/// # Example
///
/// ```no_run
/// ```
/// # use sd_notify::NotifyState;
/// #
/// let _ = NotifyState::monotonic_usec_now()
/// .expect("Failed to access monotonic time");
/// .expect("Failed to read monotonic time");
/// ```
pub fn monotonic_usec_now() -> io::Result<Self> {
monotonic_time_usec().map(NotifyState::MonotonicUsec)
Expand Down Expand Up @@ -404,14 +404,14 @@ impl Drop for UnsetEnvGuard {
}

fn fd_cloexec(fd: u32) -> io::Result<()> {
let fd = RawFd::try_from(fd).map_err(|_| io::Error::from_raw_os_error(ffi::EBADF))?;
let flags = unsafe { ffi::fcntl(fd, ffi::F_GETFD, 0) };
let fd = RawFd::try_from(fd).map_err(|_| io::Error::from_raw_os_error(libc::EBADF))?;
let flags = unsafe { libc::fcntl(fd, libc::F_GETFD, 0) };
if flags < 0 {
return Err(io::Error::last_os_error());
}
let new_flags = flags | ffi::FD_CLOEXEC;
let new_flags = flags | libc::FD_CLOEXEC;
if new_flags != flags {
let r = unsafe { ffi::fcntl(fd, ffi::F_SETFD, new_flags) };
let r = unsafe { libc::fcntl(fd, libc::F_SETFD, new_flags) };
if r < 0 {
return Err(io::Error::last_os_error());
}
Expand Down

0 comments on commit 64ca63c

Please sign in to comment.