Skip to content

Commit 093d9d2

Browse files
committed
mknod: add selinux/smack cfg alias
1 parent 11ffe4b commit 093d9d2

4 files changed

Lines changed: 25 additions & 26 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/uu/mknod/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ path = "src/mknod.rs"
2020
test = false
2121
doctest = false
2222

23+
[build-dependencies]
24+
cfg_aliases.workspace = true
25+
2326
[dependencies]
2427
clap = { workspace = true }
2528
uucore = { workspace = true, features = ["mode", "fs"] }

src/uu/mknod/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use cfg_aliases::cfg_aliases;
7+
8+
pub fn main() {
9+
cfg_aliases! {
10+
selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) },
11+
smack: { all(feature = "smack", target_os = "linux") },
12+
}
13+
}

src/uu/mknod/src/mknod.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,11 @@ struct Config {
5757
dev: u64,
5858

5959
/// Set security context (SELinux/SMACK).
60-
#[cfg(any(
61-
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
62-
all(feature = "smack", target_os = "linux"),
63-
))]
60+
#[cfg(any(selinux, smack))]
6461
set_security_context: bool,
6562

6663
/// Specific security context (SELinux/SMACK).
67-
#[cfg(any(
68-
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
69-
all(feature = "smack", target_os = "linux"),
70-
))]
64+
#[cfg(any(selinux, smack))]
7165
context: Option<String>,
7266
}
7367

@@ -102,7 +96,7 @@ fn mknod(file_name: &str, config: Config) -> i32 {
10296
}
10397

10498
// Apply SELinux context if requested
105-
#[cfg(all(feature = "selinux", any(target_os = "android", target_os = "linux")))]
99+
#[cfg(selinux)]
106100
if config.set_security_context {
107101
use std::io::Write as _;
108102

@@ -118,7 +112,7 @@ fn mknod(file_name: &str, config: Config) -> i32 {
118112
}
119113

120114
// Apply SMACK context if requested
121-
#[cfg(all(feature = "smack", target_os = "linux"))]
115+
#[cfg(smack)]
122116
if config.set_security_context {
123117
use std::io::Write as _;
124118

@@ -156,15 +150,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
156150
.expect("Missing argument 'NAME'");
157151

158152
// Extract the security context related flags and options
159-
#[cfg(any(
160-
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
161-
all(feature = "smack", target_os = "linux"),
162-
))]
153+
#[cfg(any(selinux, smack))]
163154
let set_security_context = matches.get_flag(options::SECURITY_CONTEXT);
164-
#[cfg(any(
165-
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
166-
all(feature = "smack", target_os = "linux"),
167-
))]
155+
#[cfg(any(selinux, smack))]
168156
let context = matches.get_one::<String>(options::CONTEXT).cloned();
169157

170158
let dev = match (
@@ -193,15 +181,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
193181
file_type: file_type.clone(),
194182
use_umask,
195183
dev,
196-
#[cfg(any(
197-
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
198-
all(feature = "smack", target_os = "linux"),
199-
))]
184+
#[cfg(any(selinux, smack))]
200185
set_security_context: set_security_context || context.is_some(),
201-
#[cfg(any(
202-
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
203-
all(feature = "smack", target_os = "linux"),
204-
))]
186+
#[cfg(any(selinux, smack))]
205187
context,
206188
};
207189

0 commit comments

Comments
 (0)