Skip to content

Implement basic lsns utility#554

Open
vbmade2000 wants to merge 12 commits into
uutils:mainfrom
vbmade2000:lsns-basic-functionality
Open

Implement basic lsns utility#554
vbmade2000 wants to merge 12 commits into
uutils:mainfrom
vbmade2000:lsns-basic-functionality

Conversation

@vbmade2000
Copy link
Copy Markdown

Implements a basic lsns utility. The output shown currently is same as the original lsns Linux utility.

This commit implements a basic lsns utility. The output shown
currently is same as the original lsns Linux utility.

Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
@vbmade2000 vbmade2000 force-pushed the lsns-basic-functionality branch 3 times, most recently from 4e6e906 to 1c2846b Compare May 26, 2026 16:33
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
@vbmade2000 vbmade2000 force-pushed the lsns-basic-functionality branch from 1c2846b to 423de67 Compare May 27, 2026 07:37
Comment thread src/uu/lsns/Cargo.toml Outdated
[dependencies]
uucore = { workspace = true, features = ["entries"] }
clap = { workspace = true }
smartcols-sys = { workspace = true } No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a \n here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread src/uu/lsns/src/lsns.rs Outdated
read_persistent_namespaces(lsns)?;

// Sort namespaces by inode number (NS column)
// This matches the C code: list_sort(&ls->namespaces, cmp_namespaces, NULL);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is GPL code, you must not read it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean I must not read the original C code or just remove this line?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both
the code is trivial, so, you can keep it but don't reference C code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I had comments from C code. I have removed them. Will keep this in mind from now on.

@sylvestre
Copy link
Copy Markdown
Contributor

it needs tests

Comment thread src/uu/lsns/src/lsns.rs Outdated
5 => NamespaceType::User,
6 => NamespaceType::Uts,
7 => NamespaceType::Time,
_ => panic!("Invalid namespace type index: {}", idx),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic isn't allowed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Returned error instead of that.

Comment thread src/uu/lsns/src/lsns.rs Outdated
Comment on lines +516 to +525
let ns_str = std::ffi::CString::new(ns.id.to_string()).unwrap();
let type_str = std::ffi::CString::new(ns_type).unwrap();
let nprocs_str = std::ffi::CString::new(ns.nprocs.to_string()).unwrap();
let pid_str = if rep_pid > 0 {
std::ffi::CString::new(rep_pid.to_string()).unwrap()
} else {
std::ffi::CString::new("").unwrap()
};
let user_str = std::ffi::CString::new(user).unwrap();
let command_str = std::ffi::CString::new(command).unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

way too many unwrap() here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returned proper error instead of unwrapping in all the functions.

Comment thread src/uu/lsns/src/lsns.rs Outdated

#[cfg(not(target_os = "linux"))]
fn display_namespaces(_lsns: &Lsns) -> Result<(), LsnsError> {
unimplemented!()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use unimplemented - handle the error instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unimplemented. Returned error.

@sylvestre
Copy link
Copy Markdown
Contributor

u64 namespace inode truncated to u32, can we try to keep it to as u64 ?

- New line in Cargo.toml
- Remove comment mentioning reading of C code

Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
- Return error instead of unwrap in display_namespace
- Put std::ffi import at the top

Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
@vbmade2000
Copy link
Copy Markdown
Author

u64 namespace inode truncated to u32, can we try to keep it to as u64 ?

Done. That was a mistake from my side. The actual type is u64 (from https://docs.rs/libc/latest/libc/type.ino_t.html).

Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
@sylvestre
Copy link
Copy Markdown
Contributor

please add tests in https://github.com/uutils/util-linux/tree/main/tests/by-util

Comment thread src/uu/lsns/src/errors.rs Outdated
/// Invalid namespace type index
InvalidNamespaceType(usize),
/// Unsupported platform
#[allow(dead_code)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please refactor a bit to avoid this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
@vbmade2000
Copy link
Copy Markdown
Author

please add tests in https://github.com/uutils/util-linux/tree/main/tests/by-util

Added few tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants