Skip to content

Commit 1c2846b

Browse files
committed
Add more linux config markers
Signed-off-by: Malhar Vora <mlvora.2010@gmail.com>
1 parent c18bcf1 commit 1c2846b

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

src/uu/lsns/src/lsns.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![cfg_attr(not(target_os = "linux"), allow(dead_code))]
88

99
mod errors;
10+
#[cfg(target_os = "linux")]
1011
mod smartcols;
1112

1213
use std::fs::DirEntry;
@@ -15,10 +16,14 @@ use clap::{Command, crate_version};
1516
use std::fs;
1617
#[cfg(target_os = "linux")]
1718
use std::os::linux::fs::MetadataExt;
19+
#[cfg(target_os = "linux")]
1820
use uucore::entries;
19-
use uucore::{error::UResult, format_usage, help_about, help_usage};
21+
#[cfg(target_os = "linux")]
22+
use uucore::error::UResult;
23+
use uucore::{format_usage, help_about, help_usage};
2024

2125
use crate::errors::LsnsError;
26+
#[cfg(target_os = "linux")]
2227
use crate::smartcols::{Table, TableOperations};
2328

2429
const ABOUT: &str = help_about!("lsns.md");
@@ -80,7 +85,6 @@ struct Lsns {
8085
namespaces: Vec<Namespace>,
8186
}
8287

83-
#[cfg(target_os = "linux")]
8488
#[uucore::main]
8589
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
8690
let _matches = uu_app().try_get_matches_from(args)?;
@@ -146,15 +150,26 @@ fn parse_process_stat(stat: &str) -> Option<u32> {
146150
Some(pid)
147151
}
148152

153+
#[cfg(not(target_os = "linux"))]
154+
fn get_uid_from_entry(_entry: &DirEntry) -> Option<u32> {
155+
unimplemented!()
156+
}
157+
149158
#[cfg(target_os = "linux")]
150159
fn get_uid_from_entry(entry: &DirEntry) -> Option<u32> {
151160
let f = entry.metadata().ok()?;
152161
let uid = f.st_uid();
153162
Some(uid)
154163
}
155164

165+
#[cfg(not(target_os = "linux"))]
166+
fn get_pid_from_entry(_entry: &DirEntry) -> Option<u64> {
167+
unimplemented!()
168+
}
169+
156170
/// Check if a directory entry in /proc represents a process.
157171
/// If so, returns the PID, None otherwise
172+
#[cfg(target_os = "linux")]
158173
fn get_pid_from_entry(entry: &DirEntry) -> Option<u64> {
159174
let file_name = entry.file_name();
160175
let name = file_name.to_str()?;
@@ -167,9 +182,15 @@ fn get_pid_from_entry(entry: &DirEntry) -> Option<u64> {
167182
.then(|| name.parse::<u64>().ok())?
168183
}
169184

185+
#[cfg(not(target_os = "linux"))]
186+
fn get_ns_ino(_pid: u32, _nsname: &str) -> Option<u64> {
187+
unimplemented!()
188+
}
189+
170190
/// Get namespace inode number for a process
171191
///
172192
/// Reads /proc/[pid]/ns/[nsname] and returns the namespace's inode
193+
#[cfg(target_os = "linux")]
173194
fn get_ns_ino(pid: u32, nsname: &str) -> Option<u64> {
174195
let ns_path = format!("/proc/{}/ns/{}", pid, nsname);
175196

@@ -440,6 +461,7 @@ impl NamespaceType {
440461
}
441462

442463
/// Display namespaces in default format using smartcols
464+
#[cfg(target_os = "linux")]
443465
fn display_namespaces(lsns: &Lsns) -> Result<(), LsnsError> {
444466
use smartcols_sys::{SCOLS_FL_RIGHT, SCOLS_FL_TRUNC};
445467

@@ -518,6 +540,11 @@ fn display_namespaces(lsns: &Lsns) -> Result<(), LsnsError> {
518540
Ok(())
519541
}
520542

543+
#[cfg(not(target_os = "linux"))]
544+
fn display_namespaces(_lsns: &Lsns) -> Result<(), LsnsError> {
545+
unimplemented!()
546+
}
547+
521548
/// Get username from cache, querying the system if not cached
522549
fn get_username_from_cache(cache: &mut std::collections::HashMap<u32, String>, uid: u32) -> String {
523550
cache

0 commit comments

Comments
 (0)