Skip to content

Commit 949de82

Browse files
committed
uucore: add systemd_logind cfg alias
1 parent 44ca3b2 commit 949de82

6 files changed

Lines changed: 33 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uucore/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ workspace = true
2222
[lib]
2323
path = "src/lib/lib.rs"
2424

25+
[build-dependencies]
26+
cfg_aliases.workspace = true
27+
2528
[dependencies]
2629
bstr = { workspace = true, optional = true }
2730
clap = { workspace = true }

src/uucore/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6+
// spell-checker:ignore logind
7+
68
use std::env;
79
use std::fs::File;
810
use std::io::Write;
911
use std::path::{Path, PathBuf};
1012

13+
use cfg_aliases::cfg_aliases;
14+
1115
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
16+
cfg_aliases! {
17+
systemd_logind: { all(feature = "feat_systemd_logind", target_os = "linux") },
18+
}
19+
1220
let out_dir = env::var("OUT_DIR")?;
1321

1422
let mut embedded_file = File::create(Path::new(&out_dir).join("embedded_locales.rs"))?;

src/uucore/src/lib/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub mod selinux;
8787
pub mod signals;
8888
#[cfg(all(target_os = "linux", feature = "smack"))]
8989
pub mod smack;
90-
#[cfg(feature = "feat_systemd_logind")]
90+
#[cfg(systemd_logind)]
9191
pub mod systemd_logind;
9292
#[cfg(all(
9393
unix,

src/uucore/src/lib/features/utmpx.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::path::Path;
4141
use std::ptr;
4242
use std::sync::{Mutex, MutexGuard};
4343

44-
#[cfg(feature = "feat_systemd_logind")]
44+
#[cfg(systemd_logind)]
4545
use crate::features::systemd_logind;
4646

4747
pub use self::ut::*;
@@ -313,13 +313,13 @@ impl Utmpx {
313313
/// Only one instance of [`UtmpxIter`] may be active at a time. This
314314
/// function will block as long as one is still active. Beware!
315315
pub fn iter_all_records() -> UtmpxIter {
316-
#[cfg(feature = "feat_systemd_logind")]
316+
#[cfg(systemd_logind)]
317317
{
318318
// Use systemd-logind instead of traditional utmp when feature is enabled
319319
UtmpxIter::new_systemd()
320320
}
321321

322-
#[cfg(not(feature = "feat_systemd_logind"))]
322+
#[cfg(not(systemd_logind))]
323323
{
324324
let iter = UtmpxIter::new();
325325
unsafe {
@@ -345,7 +345,7 @@ impl Utmpx {
345345
///
346346
/// The same caveats as for [`Utmpx::iter_all_records`] apply.
347347
pub fn iter_all_records_from<P: AsRef<Path>>(path: P) -> UtmpxIter {
348-
#[cfg(feature = "feat_systemd_logind")]
348+
#[cfg(systemd_logind)]
349349
{
350350
// Use systemd-logind for default utmp file when feature is enabled
351351
if path.as_ref() == Path::new(DEFAULT_FILE) {
@@ -389,7 +389,7 @@ pub struct UtmpxIter {
389389
/// Ensure UtmpxIter is !Send. Technically redundant because MutexGuard
390390
/// is also !Send.
391391
phantom: PhantomData<std::rc::Rc<()>>,
392-
#[cfg(feature = "feat_systemd_logind")]
392+
#[cfg(systemd_logind)]
393393
systemd_iter: Option<systemd_logind::SystemdUtmpxIter>,
394394
}
395395

@@ -402,12 +402,12 @@ impl UtmpxIter {
402402
Self {
403403
guard,
404404
phantom: PhantomData,
405-
#[cfg(feature = "feat_systemd_logind")]
405+
#[cfg(systemd_logind)]
406406
systemd_iter: None,
407407
}
408408
}
409409

410-
#[cfg(feature = "feat_systemd_logind")]
410+
#[cfg(systemd_logind)]
411411
fn new_systemd() -> Self {
412412
// PoisonErrors can safely be ignored
413413
let guard = LOCK
@@ -432,7 +432,7 @@ impl UtmpxIter {
432432
/// Wrapper type that can hold either traditional utmpx records or systemd records
433433
pub enum UtmpxRecord {
434434
Traditional(Box<Utmpx>),
435-
#[cfg(feature = "feat_systemd_logind")]
435+
#[cfg(systemd_logind)]
436436
Systemd(systemd_logind::SystemdUtmpxCompat),
437437
}
438438

@@ -441,7 +441,7 @@ impl UtmpxRecord {
441441
pub fn record_type(&self) -> i16 {
442442
match self {
443443
Self::Traditional(utmpx) => utmpx.record_type(),
444-
#[cfg(feature = "feat_systemd_logind")]
444+
#[cfg(systemd_logind)]
445445
Self::Systemd(systemd) => systemd.record_type(),
446446
}
447447
}
@@ -450,7 +450,7 @@ impl UtmpxRecord {
450450
pub fn pid(&self) -> i32 {
451451
match self {
452452
Self::Traditional(utmpx) => utmpx.pid(),
453-
#[cfg(feature = "feat_systemd_logind")]
453+
#[cfg(systemd_logind)]
454454
Self::Systemd(systemd) => systemd.pid(),
455455
}
456456
}
@@ -459,7 +459,7 @@ impl UtmpxRecord {
459459
pub fn terminal_suffix(&self) -> String {
460460
match self {
461461
Self::Traditional(utmpx) => utmpx.terminal_suffix(),
462-
#[cfg(feature = "feat_systemd_logind")]
462+
#[cfg(systemd_logind)]
463463
Self::Systemd(systemd) => systemd.terminal_suffix(),
464464
}
465465
}
@@ -468,7 +468,7 @@ impl UtmpxRecord {
468468
pub fn user(&self) -> String {
469469
match self {
470470
Self::Traditional(utmpx) => utmpx.user(),
471-
#[cfg(feature = "feat_systemd_logind")]
471+
#[cfg(systemd_logind)]
472472
Self::Systemd(systemd) => systemd.user(),
473473
}
474474
}
@@ -477,7 +477,7 @@ impl UtmpxRecord {
477477
pub fn host(&self) -> String {
478478
match self {
479479
Self::Traditional(utmpx) => utmpx.host(),
480-
#[cfg(feature = "feat_systemd_logind")]
480+
#[cfg(systemd_logind)]
481481
Self::Systemd(systemd) => systemd.host(),
482482
}
483483
}
@@ -486,7 +486,7 @@ impl UtmpxRecord {
486486
pub fn tty_device(&self) -> String {
487487
match self {
488488
Self::Traditional(utmpx) => utmpx.tty_device(),
489-
#[cfg(feature = "feat_systemd_logind")]
489+
#[cfg(systemd_logind)]
490490
Self::Systemd(systemd) => systemd.tty_device(),
491491
}
492492
}
@@ -495,7 +495,7 @@ impl UtmpxRecord {
495495
pub fn login_time(&self) -> time::OffsetDateTime {
496496
match self {
497497
Self::Traditional(utmpx) => utmpx.login_time(),
498-
#[cfg(feature = "feat_systemd_logind")]
498+
#[cfg(systemd_logind)]
499499
Self::Systemd(systemd) => systemd.login_time(),
500500
}
501501
}
@@ -506,7 +506,7 @@ impl UtmpxRecord {
506506
pub fn exit_status(&self) -> (i16, i16) {
507507
match self {
508508
Self::Traditional(utmpx) => utmpx.exit_status(),
509-
#[cfg(feature = "feat_systemd_logind")]
509+
#[cfg(systemd_logind)]
510510
Self::Systemd(systemd) => systemd.exit_status(),
511511
}
512512
}
@@ -515,7 +515,7 @@ impl UtmpxRecord {
515515
pub fn is_user_process(&self) -> bool {
516516
match self {
517517
Self::Traditional(utmpx) => utmpx.is_user_process(),
518-
#[cfg(feature = "feat_systemd_logind")]
518+
#[cfg(systemd_logind)]
519519
Self::Systemd(systemd) => systemd.is_user_process(),
520520
}
521521
}
@@ -524,7 +524,7 @@ impl UtmpxRecord {
524524
pub fn canon_host(&self) -> IOResult<String> {
525525
match self {
526526
Self::Traditional(utmpx) => utmpx.canon_host(),
527-
#[cfg(feature = "feat_systemd_logind")]
527+
#[cfg(systemd_logind)]
528528
Self::Systemd(systemd) => Ok(systemd.canon_host()),
529529
}
530530
}
@@ -533,7 +533,7 @@ impl UtmpxRecord {
533533
impl Iterator for UtmpxIter {
534534
type Item = UtmpxRecord;
535535
fn next(&mut self) -> Option<Self::Item> {
536-
#[cfg(feature = "feat_systemd_logind")]
536+
#[cfg(systemd_logind)]
537537
{
538538
if let Some(ref mut systemd_iter) = self.systemd_iter {
539539
// We have a systemd iterator - use it exclusively (never fall back to traditional utmp)

src/uucore/src/lib/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub use crate::features::ranges;
7575
pub use crate::features::ringbuffer;
7676
#[cfg(feature = "sum")]
7777
pub use crate::features::sum;
78-
#[cfg(feature = "feat_systemd_logind")]
78+
#[cfg(systemd_logind)]
7979
pub use crate::features::systemd_logind;
8080
#[cfg(feature = "time")]
8181
pub use crate::features::time;

0 commit comments

Comments
 (0)