diff --git a/src/builtins/disown.rs b/src/builtins/disown.rs index 41c4ef939..8c6408041 100644 --- a/src/builtins/disown.rs +++ b/src/builtins/disown.rs @@ -80,7 +80,6 @@ pub fn disown(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O retval = STATUS_CMD_ERROR; } } else { - // TODO: This is supposed to be deduplicated or a hash set per comments below! let mut jobs = vec![]; retval = STATUS_CMD_OK; @@ -116,6 +115,11 @@ pub fn disown(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O return retval; } + // One PID/JID may be repeated or multiple PIDs may refer to the same job; + // include the job only once. + jobs.sort_unstable_by_key(|job| job.job_id()); + jobs.dedup_by_key(|job| job.job_id()); + // Disown all target jobs. for j in jobs { disown_job(cmd, streams, &j); diff --git a/src/job_group.rs b/src/job_group.rs index 9bb9ed432..709482154 100644 --- a/src/job_group.rs +++ b/src/job_group.rs @@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex}; #[repr(transparent)] pub struct JobId(NonZeroU32); -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)] pub struct MaybeJobId(pub Option); impl std::ops::Deref for MaybeJobId {