Skip to content

Commit

Permalink
Emit only sane pgid value for jobs output
Browse files Browse the repository at this point in the history
We were previously printing the internal INVALID_PID value (since removed),
which was a meaningless `-2` constant, when there was no pgid associated with a
job.

This PR changes that to `-` to indicate no pgid available, which I prefer over
something like `0` or `-1`, but will cause problems for code that is hardcoded
to convert this field to an integral value.

Other options include 0 or -1 as mentioned above, or printing fish's own pgid.
  • Loading branch information
mqudsi committed Nov 5, 2024
1 parent 24a077f commit 512c588
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/builtins/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ fn cpu_use(j: &Job) -> f64 {

/// Print information about the specified job.
fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut IoStreams) {
// TODO: Breaking change, but don't print meaningless -2 for jobs without a pgid
let pgid = j.get_pgid().unwrap_or(-2); // the old INVALID_PGID value
let pgid = match j.get_pgid() {
Some(pgid) => pgid.to_string(),
None => "-".to_string(),
};

let mut out = WString::new();
match mode {
Expand All @@ -66,7 +68,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut
out += wgettext!("State\tCommand\n");
}

sprintf!(=> &mut out, "%d\t%d\t", j.job_id(), pgid);
sprintf!(=> &mut out, "%d\t%s\t", j.job_id(), pgid);

if have_proc_stat() {
sprintf!(=> &mut out, "%.0f%%\t", 100.0 * cpu_use(j));
Expand All @@ -93,7 +95,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut
// Print table header before first job.
out += wgettext!("Group\n");
}
out += &sprintf!("%d\n", pgid)[..];
out += &sprintf!("%s\n", pgid)[..];
streams.out.append(out);
}
JobsPrintMode::PrintPid => {
Expand Down

0 comments on commit 512c588

Please sign in to comment.