Module Name: src Committed By: kre Date: Sat Jun 15 05:18:48 UTC 2024
Modified Files: src/bin/sh: eval.c jobs.c jobs.h Log Message: POSIX.1-2024 requires that when an async (background) job is started at the top level (ie: not in any kind of subshell environment) of an interactive shell, that the shell print the job number assigned, and the process id of the lead (or only) process in the job, in the form: [JN] pid Make that happen. (Other shells have been doing this for ages). To generate a diff of this commit: cvs rdiff -u -r1.191 -r1.192 src/bin/sh/eval.c cvs rdiff -u -r1.119 -r1.120 src/bin/sh/jobs.c cvs rdiff -u -r1.26 -r1.27 src/bin/sh/jobs.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/eval.c diff -u src/bin/sh/eval.c:1.191 src/bin/sh/eval.c:1.192 --- src/bin/sh/eval.c:1.191 Mon Dec 25 04:52:38 2023 +++ src/bin/sh/eval.c Sat Jun 15 05:18:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: eval.c,v 1.191 2023/12/25 04:52:38 kre Exp $ */ +/* $NetBSD: eval.c,v 1.192 2024/06/15 05:18:48 kre Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: eval.c,v 1.191 2023/12/25 04:52:38 kre Exp $"); +__RCSID("$NetBSD: eval.c,v 1.192 2024/06/15 05:18:48 kre Exp $"); #endif #endif /* not lint */ @@ -574,9 +574,10 @@ evalsubshell(union node *n, int flags) INTON; redirect(n->nredir.redirect, REDIR_KEEP); evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */ - } else if (backgnd) + } else if (backgnd) { + jobstarted(jp); exitstatus = 0; - else + } else exitstatus = waitforjob(jp); INTON; @@ -744,8 +745,10 @@ evalpipe(union node *n) exitstatus = waitforjob(jp); CTRACE(DBG_EVAL, ("evalpipe: job done exit status %d\n", exitstatus)); - } else + } else { + jobstarted(jp); exitstatus = 0; + } INTON; } @@ -1419,7 +1422,9 @@ evalcommand(union node *cmd, int flgs, s backcmd->fd = pip[0]; close(pip[1]); backcmd->jp = jp; - } + } else + jobstarted(jp); + FORCEINTON; out: Index: src/bin/sh/jobs.c diff -u src/bin/sh/jobs.c:1.119 src/bin/sh/jobs.c:1.120 --- src/bin/sh/jobs.c:1.119 Tue Jan 30 19:05:07 2024 +++ src/bin/sh/jobs.c Sat Jun 15 05:18:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.c,v 1.119 2024/01/30 19:05:07 kre Exp $ */ +/* $NetBSD: jobs.c,v 1.120 2024/06/15 05:18:48 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: jobs.c,v 1.119 2024/01/30 19:05:07 kre Exp $"); +__RCSID("$NetBSD: jobs.c,v 1.120 2024/06/15 05:18:48 kre Exp $"); #endif #endif /* not lint */ @@ -1099,6 +1099,21 @@ anyjobs(void) } /* + * Output the (new) POSIX required "[%d] %d" string whenever an + * async (ie: background) job is started in an interactive shell. + * Note that a subshell environment is not regarded as interactive. + */ +void +jobstarted(struct job *jp) +{ + if (!iflag || !rootshell) + return; + + outfmt(out2, "[%d] %ld\n", JNUM(jp), + jp->pgrp != 0 ? (long)jp->pgrp : (long)jp->ps->pid); +} + +/* * Return a new job structure, */ Index: src/bin/sh/jobs.h diff -u src/bin/sh/jobs.h:1.26 src/bin/sh/jobs.h:1.27 --- src/bin/sh/jobs.h:1.26 Fri Apr 7 10:34:13 2023 +++ src/bin/sh/jobs.h Sat Jun 15 05:18:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: jobs.h,v 1.26 2023/04/07 10:34:13 kre Exp $ */ +/* $NetBSD: jobs.h,v 1.27 2024/06/15 05:18:48 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -101,6 +101,7 @@ int stoppedjobs(void); void commandtext(struct procstat *, union node *); int getjobpgrp(const char *); int anyjobs(void); +void jobstarted(struct job *); #if ! JOBS #define setjobctl(on) /* do nothing */