Emit only sane pgid value for jobs output (#10833)

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.
This commit is contained in:
Mahmoud Al-Qudsi 2024-11-08 10:33:30 -06:00 committed by GitHub
parent 2279b47178
commit 9fddc3e887
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,8 +50,10 @@ fn cpu_use(j: &Job) -> f64 {
/// Print information about the specified job. /// Print information about the specified job.
fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut IoStreams) { 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 = match j.get_pgid() {
let pgid = j.get_pgid().unwrap_or(-2); // the old INVALID_PGID value Some(pgid) => pgid.to_string(),
None => "-".to_string(),
};
let mut out = WString::new(); let mut out = WString::new();
match mode { match mode {
@ -66,7 +68,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut
out += wgettext!("State\tCommand\n"); 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() { if have_proc_stat() {
sprintf!(=> &mut out, "%.0f%%\t", 100.0 * cpu_use(j)); sprintf!(=> &mut out, "%.0f%%\t", 100.0 * cpu_use(j));
@ -93,7 +95,7 @@ fn builtin_jobs_print(j: &Job, mode: JobsPrintMode, header: bool, streams: &mut
// Print table header before first job. // Print table header before first job.
out += wgettext!("Group\n"); out += wgettext!("Group\n");
} }
out += &sprintf!("%d\n", pgid)[..]; out += &sprintf!("%s\n", pgid)[..];
streams.out.append(out); streams.out.append(out);
} }
JobsPrintMode::PrintPid => { JobsPrintMode::PrintPid => {