Skip to content

Commit e23f45f

Browse files
committed
set_selinux_security_context: match GNU's error
1 parent f21f7f0 commit e23f45f

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/uucore/src/lib/features/selinux.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub enum SeLinuxError {
1919
#[error("Failed to retrieve the security context")]
2020
ContextRetrievalFailure,
2121

22-
#[error("Failed to set the security context")]
23-
ContextSetFailure,
22+
#[error("failed to set default file creation context to {0}")]
23+
ContextSetFailure(String),
2424

2525
#[error("Invalid context string or conversion failure")]
2626
ContextConversionFailure,
@@ -32,7 +32,7 @@ impl From<SeLinuxError> for i32 {
3232
SeLinuxError::SELinuxNotEnabled => 1,
3333
SeLinuxError::FileOpenFailure => 2,
3434
SeLinuxError::ContextRetrievalFailure => 3,
35-
SeLinuxError::ContextSetFailure => 4,
35+
SeLinuxError::ContextSetFailure(_) => 4,
3636
SeLinuxError::ContextConversionFailure => 5,
3737
}
3838
}
@@ -113,10 +113,11 @@ pub fn set_selinux_security_context(
113113
false,
114114
)
115115
.set_for_path(path, false, false)
116-
.map_err(|_| SeLinuxError::ContextSetFailure)
116+
.map_err(|_| SeLinuxError::ContextSetFailure(ctx_str.to_string()))
117117
} else {
118118
// If no context provided, set the default SELinux context for the path
119-
SecurityContext::set_default_for_path(path).map_err(|_| SeLinuxError::ContextSetFailure)
119+
SecurityContext::set_default_for_path(path)
120+
.map_err(|_| SeLinuxError::ContextSetFailure("".to_string()))
120121
}
121122
}
122123

tests/by-util/test_mkfifo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn test_mkfifo_selinux_invalid() {
160160
.arg(arg)
161161
.arg(dest)
162162
.fails()
163-
.stderr_contains("Failed to");
163+
.stderr_contains("failed to");
164164
if at.file_exists(dest) {
165165
at.remove(dest);
166166
}

tests/by-util/test_mknod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn test_mknod_selinux_invalid() {
187187
.arg(dest)
188188
.arg("p")
189189
.fails()
190-
.stderr_contains("Failed to");
190+
.stderr_contains("failed to");
191191
if at.file_exists(dest) {
192192
at.remove(dest);
193193
}

0 commit comments

Comments
 (0)