Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jan 26, 2024
1 parent 5e5ded2 commit 2335202
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/uu/pwdx/src/pwdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use clap::Arg;
use clap::{crate_version, Command};
use std::env;
use std::fs;
Expand All @@ -16,14 +17,15 @@ const USAGE: &str = help_usage!("pwdx.md");

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args: Vec<String> = env::args().collect();

if args.len() != 2 {
eprintln!("Usage: pwdx <pid>");
let matches = uu_app().try_get_matches_from(args)?;

let pid_str = matches.get_one::<String>("pid").unwrap();
let pid = pid_str.parse::<i32>().unwrap_or_else(|_| {
eprintln!("Invalid PID");
process::exit(1);
}
});

let pid = &args[1];
let cwd_link = format!("/proc/{}/cwd", pid);

match fs::read_link(Path::new(&cwd_link)) {
Expand All @@ -42,4 +44,9 @@ pub fn uu_app() -> Command {
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(true)
.arg(Arg::new("pid")
.value_name("PID")
.help("Process ID")
.required(true)
.index(1))
}
1 change: 0 additions & 1 deletion src/uu/renice/src/renice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use libc::PRIO_PROCESS;
use std::env;
use std::io::Error;
use std::process;
use std::str::FromStr;
use uucore::{error::UResult, format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("renice.md");
const USAGE: &str = help_usage!("renice.md");
Expand Down

0 comments on commit 2335202

Please sign in to comment.