Skip to content

Commit

Permalink
Use rustix::fstat instead of std
Browse files Browse the repository at this point in the history
Avoids duplicating the FD to safely convert into file.  Instead we now
stat the FD directly.
  • Loading branch information
swsnr committed Oct 19, 2023
1 parent 085ad15 commit 35f2373
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@

use std::io::prelude::*;
use std::os::fd::AsFd;
use std::os::linux::fs::MetadataExt;

use client::JournalClient;
use log::kv::{Error, Key, Value, Visitor};
Expand All @@ -80,11 +79,8 @@ use fields::*;
/// file descriptor match the value of `$JOURNAL_STREAM` (see `systemd.exec(5)`).
/// Otherwise, return `false`.
pub fn connected_to_journal() -> bool {
std::io::stderr()
.as_fd()
.try_clone_to_owned()
.and_then(|fd| std::fs::File::from(fd).metadata())
.map(|metadata| format!("{}:{}", metadata.st_dev(), metadata.st_ino()))
rustix::fs::fstat(std::io::stderr().as_fd())
.map(|stat| format!("{}:{}", stat.st_dev, stat.st_ino))
.ok()
.and_then(|stderr| {
std::env::var_os("JOURNAL_STREAM").map(|s| s.to_string_lossy() == stderr.as_str())
Expand Down

0 comments on commit 35f2373

Please sign in to comment.