Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ feat_common_core = [
"lsipc",
"lslocks",
"lsmem",
"lsns",
"mcookie",
"mesg",
"mountpoint",
Expand Down Expand Up @@ -106,6 +107,7 @@ lscpu = { optional = true, version = "0.0.1", package = "uu_lscpu", path = "src/
lsipc = { optional = true, version = "0.0.1", package = "uu_lsipc", path = "src/uu/lsipc" }
lslocks = { optional = true, version = "0.0.1", package = "uu_lslocks", path = "src/uu/lslocks" }
lsmem = { optional = true, version = "0.0.1", package = "uu_lsmem", path = "src/uu/lsmem" }
lsns = { optional = true, version = "0.0.1", package = "uu_lsns", path = "src/uu/lsns" }
mcookie = { optional = true, version = "0.0.1", package = "uu_mcookie", path = "src/uu/mcookie" }
mesg = { optional = true, version = "0.0.1", package = "uu_mesg", path = "src/uu/mesg" }
mountpoint = { optional = true, version = "0.0.1", package = "uu_mountpoint", path = "src/uu/mountpoint" }
Expand Down
16 changes: 16 additions & 0 deletions src/uu/lsns/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "uu_lsns"
version = "0.0.1"
edition = "2024"

[lib]
path = "src/lsns.rs"

[[bin]]
name = "lsns"
path = "src/main.rs"

[dependencies]
uucore = { workspace = true, features = ["entries"] }
clap = { workspace = true }
smartcols-sys = { workspace = true }
7 changes: 7 additions & 0 deletions src/uu/lsns/lsns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# lsns

```
lsns [OPTION]...
```

List the namespaces in the system.
62 changes: 62 additions & 0 deletions src/uu/lsns/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This file is part of the uutils util-linux package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use std::ffi::c_int;
use std::fmt;

use uucore::error::UError;

#[derive(Debug)]
pub enum LsnsError {
/// Generic I/O error with context message
IOError(String, std::io::Error),
}

impl LsnsError {
/// Create an I/O error with a context message
pub(crate) fn io0(message: impl Into<String>, error: impl Into<std::io::Error>) -> Self {
Self::IOError(message.into(), error.into())
}

/// Helper to convert negative errno to Result
pub(crate) fn io_from_neg_errno(
message: impl Into<String>,
result: c_int,
) -> Result<usize, LsnsError> {
if let Ok(result) = usize::try_from(result) {
Ok(result)
} else {
let err = std::io::Error::from_raw_os_error(-result);
Err(Self::IOError(message.into(), err))
}
}
}

impl fmt::Display for LsnsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IOError(message, err) => write!(f, "{message}: {err}"),
}
}
}

impl UError for LsnsError {
fn code(&self) -> i32 {
1
}

fn usage(&self) -> bool {
false
}
}

impl std::error::Error for LsnsError {}

// Implement From trait for automatic conversion from std::io::Error
impl From<std::io::Error> for LsnsError {
fn from(err: std::io::Error) -> Self {
Self::IOError(String::new(), err)
}
}
Loading
Loading