Skip to content

Commit 1116ad2

Browse files
committed
uucore: add systemd_logind cfg alias
1 parent c2d65cc commit 1116ad2

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
@@ -21,6 +21,9 @@ workspace = true
2121
[lib]
2222
path = "src/lib/lib.rs"
2323

24+
[build-dependencies]
25+
cfg_aliases.workspace = true
26+
2427
[dependencies]
2528
bstr = { workspace = true, optional = true }
2629
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;
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

@@ -400,12 +400,12 @@ impl UtmpxIter {
400400
Self {
401401
guard,
402402
phantom: PhantomData,
403-
#[cfg(feature = "feat_systemd_logind")]
403+
#[cfg(systemd_logind)]
404404
systemd_iter: None,
405405
}
406406
}
407407

408-
#[cfg(feature = "feat_systemd_logind")]
408+
#[cfg(systemd_logind)]
409409
fn new_systemd() -> Self {
410410
// PoisonErrors can safely be ignored
411411
let guard = LOCK.lock().unwrap_or_else(|err| err.into_inner());
@@ -428,7 +428,7 @@ impl UtmpxIter {
428428
/// Wrapper type that can hold either traditional utmpx records or systemd records
429429
pub enum UtmpxRecord {
430430
Traditional(Box<Utmpx>),
431-
#[cfg(feature = "feat_systemd_logind")]
431+
#[cfg(systemd_logind)]
432432
Systemd(systemd_logind::SystemdUtmpxCompat),
433433
}
434434

@@ -437,7 +437,7 @@ impl UtmpxRecord {
437437
pub fn record_type(&self) -> i16 {
438438
match self {
439439
Self::Traditional(utmpx) => utmpx.record_type(),
440-
#[cfg(feature = "feat_systemd_logind")]
440+
#[cfg(systemd_logind)]
441441
Self::Systemd(systemd) => systemd.record_type(),
442442
}
443443
}
@@ -446,7 +446,7 @@ impl UtmpxRecord {
446446
pub fn pid(&self) -> i32 {
447447
match self {
448448
Self::Traditional(utmpx) => utmpx.pid(),
449-
#[cfg(feature = "feat_systemd_logind")]
449+
#[cfg(systemd_logind)]
450450
Self::Systemd(systemd) => systemd.pid(),
451451
}
452452
}
@@ -455,7 +455,7 @@ impl UtmpxRecord {
455455
pub fn terminal_suffix(&self) -> String {
456456
match self {
457457
Self::Traditional(utmpx) => utmpx.terminal_suffix(),
458-
#[cfg(feature = "feat_systemd_logind")]
458+
#[cfg(systemd_logind)]
459459
Self::Systemd(systemd) => systemd.terminal_suffix(),
460460
}
461461
}
@@ -464,7 +464,7 @@ impl UtmpxRecord {
464464
pub fn user(&self) -> String {
465465
match self {
466466
Self::Traditional(utmpx) => utmpx.user(),
467-
#[cfg(feature = "feat_systemd_logind")]
467+
#[cfg(systemd_logind)]
468468
Self::Systemd(systemd) => systemd.user(),
469469
}
470470
}
@@ -473,7 +473,7 @@ impl UtmpxRecord {
473473
pub fn host(&self) -> String {
474474
match self {
475475
Self::Traditional(utmpx) => utmpx.host(),
476-
#[cfg(feature = "feat_systemd_logind")]
476+
#[cfg(systemd_logind)]
477477
Self::Systemd(systemd) => systemd.host(),
478478
}
479479
}
@@ -482,7 +482,7 @@ impl UtmpxRecord {
482482
pub fn tty_device(&self) -> String {
483483
match self {
484484
Self::Traditional(utmpx) => utmpx.tty_device(),
485-
#[cfg(feature = "feat_systemd_logind")]
485+
#[cfg(systemd_logind)]
486486
Self::Systemd(systemd) => systemd.tty_device(),
487487
}
488488
}
@@ -491,7 +491,7 @@ impl UtmpxRecord {
491491
pub fn login_time(&self) -> time::OffsetDateTime {
492492
match self {
493493
Self::Traditional(utmpx) => utmpx.login_time(),
494-
#[cfg(feature = "feat_systemd_logind")]
494+
#[cfg(systemd_logind)]
495495
Self::Systemd(systemd) => systemd.login_time(),
496496
}
497497
}
@@ -502,7 +502,7 @@ impl UtmpxRecord {
502502
pub fn exit_status(&self) -> (i16, i16) {
503503
match self {
504504
Self::Traditional(utmpx) => utmpx.exit_status(),
505-
#[cfg(feature = "feat_systemd_logind")]
505+
#[cfg(systemd_logind)]
506506
Self::Systemd(systemd) => systemd.exit_status(),
507507
}
508508
}
@@ -511,7 +511,7 @@ impl UtmpxRecord {
511511
pub fn is_user_process(&self) -> bool {
512512
match self {
513513
Self::Traditional(utmpx) => utmpx.is_user_process(),
514-
#[cfg(feature = "feat_systemd_logind")]
514+
#[cfg(systemd_logind)]
515515
Self::Systemd(systemd) => systemd.is_user_process(),
516516
}
517517
}
@@ -520,7 +520,7 @@ impl UtmpxRecord {
520520
pub fn canon_host(&self) -> IOResult<String> {
521521
match self {
522522
Self::Traditional(utmpx) => utmpx.canon_host(),
523-
#[cfg(feature = "feat_systemd_logind")]
523+
#[cfg(systemd_logind)]
524524
Self::Systemd(systemd) => systemd.canon_host(),
525525
}
526526
}
@@ -529,7 +529,7 @@ impl UtmpxRecord {
529529
impl Iterator for UtmpxIter {
530530
type Item = UtmpxRecord;
531531
fn next(&mut self) -> Option<Self::Item> {
532-
#[cfg(feature = "feat_systemd_logind")]
532+
#[cfg(systemd_logind)]
533533
{
534534
if let Some(ref mut systemd_iter) = self.systemd_iter {
535535
// 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)