Implement basic lsns utility#554
Conversation
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>
4e6e906 to
1c2846b
Compare
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
1c2846b to
423de67
Compare
| [dependencies] | ||
| uucore = { workspace = true, features = ["entries"] } | ||
| clap = { workspace = true } | ||
| smartcols-sys = { workspace = true } No newline at end of file |
| read_persistent_namespaces(lsns)?; | ||
|
|
||
| // Sort namespaces by inode number (NS column) | ||
| // This matches the C code: list_sort(&ls->namespaces, cmp_namespaces, NULL); |
There was a problem hiding this comment.
this is GPL code, you must not read it.
There was a problem hiding this comment.
Do you mean I must not read the original C code or just remove this line?
There was a problem hiding this comment.
both
the code is trivial, so, you can keep it but don't reference C code
There was a problem hiding this comment.
Got it. I had comments from C code. I have removed them. Will keep this in mind from now on.
|
it needs tests |
| 5 => NamespaceType::User, | ||
| 6 => NamespaceType::Uts, | ||
| 7 => NamespaceType::Time, | ||
| _ => panic!("Invalid namespace type index: {}", idx), |
There was a problem hiding this comment.
Removed. Returned error instead of that.
| 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(); |
There was a problem hiding this comment.
way too many unwrap() here
There was a problem hiding this comment.
Returned proper error instead of unwrapping in all the functions.
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn display_namespaces(_lsns: &Lsns) -> Result<(), LsnsError> { | ||
| unimplemented!() |
There was a problem hiding this comment.
please don't use unimplemented - handle the error instead
There was a problem hiding this comment.
Removed unimplemented. Returned error.
|
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>
Done. That was a mistake from my side. The actual type is |
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
|
please add tests in https://github.com/uutils/util-linux/tree/main/tests/by-util |
| /// Invalid namespace type index | ||
| InvalidNamespaceType(usize), | ||
| /// Unsupported platform | ||
| #[allow(dead_code)] |
There was a problem hiding this comment.
please refactor a bit to avoid this
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
Added few tests. |
Implements a basic
lsnsutility. The output shown currently is same as the originallsnsLinux utility.