Skip to content

Commit 423de67

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

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

src/uu/lsns/src/lsns.rs

Lines changed: 35 additions & 1 deletion
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,12 @@ 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;
1921
use uucore::{error::UResult, format_usage, help_about, help_usage};
2022

2123
use crate::errors::LsnsError;
24+
#[cfg(target_os = "linux")]
2225
use crate::smartcols::{Table, TableOperations};
2326

2427
const ABOUT: &str = help_about!("lsns.md");
@@ -80,7 +83,6 @@ struct Lsns {
8083
namespaces: Vec<Namespace>,
8184
}
8285

83-
#[cfg(target_os = "linux")]
8486
#[uucore::main]
8587
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
8688
let _matches = uu_app().try_get_matches_from(args)?;
@@ -146,15 +148,26 @@ fn parse_process_stat(stat: &str) -> Option<u32> {
146148
Some(pid)
147149
}
148150

151+
#[cfg(not(target_os = "linux"))]
152+
fn get_uid_from_entry(_entry: &DirEntry) -> Option<u32> {
153+
unimplemented!()
154+
}
155+
149156
#[cfg(target_os = "linux")]
150157
fn get_uid_from_entry(entry: &DirEntry) -> Option<u32> {
151158
let f = entry.metadata().ok()?;
152159
let uid = f.st_uid();
153160
Some(uid)
154161
}
155162

163+
#[cfg(not(target_os = "linux"))]
164+
fn get_pid_from_entry(_entry: &DirEntry) -> Option<u64> {
165+
unimplemented!()
166+
}
167+
156168
/// Check if a directory entry in /proc represents a process.
157169
/// If so, returns the PID, None otherwise
170+
#[cfg(target_os = "linux")]
158171
fn get_pid_from_entry(entry: &DirEntry) -> Option<u64> {
159172
let file_name = entry.file_name();
160173
let name = file_name.to_str()?;
@@ -167,9 +180,15 @@ fn get_pid_from_entry(entry: &DirEntry) -> Option<u64> {
167180
.then(|| name.parse::<u64>().ok())?
168181
}
169182

183+
#[cfg(not(target_os = "linux"))]
184+
fn get_ns_ino(_pid: u32, _nsname: &str) -> Option<u64> {
185+
unimplemented!()
186+
}
187+
170188
/// Get namespace inode number for a process
171189
///
172190
/// Reads /proc/[pid]/ns/[nsname] and returns the namespace's inode
191+
#[cfg(target_os = "linux")]
173192
fn get_ns_ino(pid: u32, nsname: &str) -> Option<u64> {
174193
let ns_path = format!("/proc/{}/ns/{}", pid, nsname);
175194

@@ -440,6 +459,7 @@ impl NamespaceType {
440459
}
441460

442461
/// Display namespaces in default format using smartcols
462+
#[cfg(target_os = "linux")]
443463
fn display_namespaces(lsns: &Lsns) -> Result<(), LsnsError> {
444464
use smartcols_sys::{SCOLS_FL_RIGHT, SCOLS_FL_TRUNC};
445465

@@ -518,7 +538,13 @@ fn display_namespaces(lsns: &Lsns) -> Result<(), LsnsError> {
518538
Ok(())
519539
}
520540

541+
#[cfg(not(target_os = "linux"))]
542+
fn display_namespaces(_lsns: &Lsns) -> Result<(), LsnsError> {
543+
unimplemented!()
544+
}
545+
521546
/// Get username from cache, querying the system if not cached
547+
#[cfg(target_os = "linux")]
522548
fn get_username_from_cache(cache: &mut std::collections::HashMap<u32, String>, uid: u32) -> String {
523549
cache
524550
.entry(uid)
@@ -528,3 +554,11 @@ fn get_username_from_cache(cache: &mut std::collections::HashMap<u32, String>, u
528554
})
529555
.clone()
530556
}
557+
558+
#[cfg(not(target_os = "linux"))]
559+
fn get_username_from_cache(
560+
_cache: &mut std::collections::HashMap<u32, String>,
561+
_uid: u32,
562+
) -> String {
563+
unimplemented!()
564+
}

0 commit comments

Comments
 (0)