From owner-freebsd-standards@FreeBSD.ORG Sun Sep 17 17:10:26 2006 Return-Path: X-Original-To: freebsd-standards@hub.freebsd.org Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E482B16A407 for ; Sun, 17 Sep 2006 17:10:26 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 50AA943D53 for ; Sun, 17 Sep 2006 17:10:26 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k8HHAQwu041283 for ; Sun, 17 Sep 2006 17:10:26 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k8HHAQP3041282; Sun, 17 Sep 2006 17:10:26 GMT (envelope-from gnats) Resent-Date: Sun, 17 Sep 2006 17:10:26 GMT Resent-Message-Id: <200609171710.k8HHAQP3041282@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Roman Bogorodskiy Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8C3A016A47C for ; Sun, 17 Sep 2006 17:08:43 +0000 (UTC) (envelope-from novel@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id DD15343D88 for ; Sun, 17 Sep 2006 17:08:35 +0000 (GMT) (envelope-from novel@FreeBSD.org) Received: from freefall.freebsd.org (novel@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k8HH8ZEl041158 for ; Sun, 17 Sep 2006 17:08:35 GMT (envelope-from novel@freefall.freebsd.org) Received: (from novel@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k8HH8ZYU041157; Sun, 17 Sep 2006 17:08:35 GMT (envelope-from novel) Message-Id: <200609171708.k8HH8ZYU041157@freefall.freebsd.org> Date: Sun, 17 Sep 2006 17:08:35 GMT From: Roman Bogorodskiy To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: standards/103331: [ patch ] add '-p' support for jobs sh(1) builtin X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Roman Bogorodskiy List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Sep 2006 17:10:27 -0000 >Number: 103331 >Category: standards >Synopsis: [ patch ] add '-p' support for jobs sh(1) builtin >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Sep 17 17:10:25 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Roman Bogorodskiy >Release: FreeBSD 6.0-STABLE i386 >Organization: >Environment: >Description: Add '-p' support for sh(1)'s job builtin. References: http://www.opengroup.org/onlinepubs/000095399/utilities/jobs.html PS Maybe it would make sense to rewrite it in a way that it used only one varible for all formats (i.e. introduce format codes) or use one bit-varible instead of one varible per format like it is done now. >How-To-Repeat: >Fix: --- src_bin_sh_jobs_p.diff begins here --- Index: jobs.c =================================================================== RCS file: /home/ncvs/src/bin/sh/jobs.c,v retrieving revision 1.71 diff -u -r1.71 jobs.c --- jobs.c 4 Feb 2006 14:37:50 -0000 1.71 +++ jobs.c 17 Sep 2006 16:39:29 -0000 @@ -98,7 +98,7 @@ STATIC void deljob(struct job *); STATIC struct job *getcurjob(struct job *); #endif -STATIC void showjob(struct job *, pid_t, int, int); +STATIC void showjob(struct job *, pid_t, int, int, int); /* @@ -265,16 +265,19 @@ jobscmd(int argc, char *argv[]) { char *id; - int ch, sformat, lformat; + int ch, sformat, lformat, pformat; optind = optreset = 1; opterr = 0; sformat = lformat = 0; - while ((ch = getopt(argc, argv, "ls")) != -1) { + while ((ch = getopt(argc, argv, "lps")) != -1) { switch (ch) { case 'l': lformat = 1; break; + case 'p': + pformat = 1; + break; case 's': sformat = 1; break; @@ -287,16 +290,16 @@ argv += optind; if (argc == 0) - showjobs(0, sformat, lformat); + showjobs(0, sformat, lformat, pformat); else while ((id = *argv++) != NULL) - showjob(getjob(id), 0, sformat, lformat); + showjob(getjob(id), 0, sformat, lformat, pformat); return (0); } STATIC void -showjob(struct job *jp, pid_t pid, int sformat, int lformat) +showjob(struct job *jp, pid_t pid, int sformat, int lformat, int pformat) { char s[64]; struct procstat *ps; @@ -319,6 +322,10 @@ out1fmt("%d\n", (int)ps->pid); goto skip; } + if (pformat) { + out1fmt("%d\n", (int)getpgid(ps->pid)); + goto skip; + } if (!lformat && ps != jp->ps && pid == 0) goto skip; if (pid != 0 && pid != ps->pid) @@ -388,7 +395,7 @@ */ void -showjobs(int change, int sformat, int lformat) +showjobs(int change, int sformat, int lformat, int pformat) { int jobno; struct job *jp; @@ -404,7 +411,7 @@ } if (change && ! jp->changed) continue; - showjob(jp, 0, sformat, lformat); + showjob(jp, 0, sformat, lformat, pformat); jp->changed = 0; if (jp->state == JOBDONE) { freejob(jp); @@ -992,7 +999,7 @@ out1str(" (core dumped)"); out1c('\n'); } else - showjob(thisjob, pid, 0, 0); + showjob(thisjob, pid, 0, 0, 0); } } else { TRACE(("Not printing status, rootshell=%d, job=%p\n", rootshell, job)); Index: jobs.h =================================================================== RCS file: /home/ncvs/src/bin/sh/jobs.h,v retrieving revision 1.18 diff -u -r1.18 jobs.h --- jobs.h 6 Apr 2004 20:06:51 -0000 1.18 +++ jobs.h 17 Sep 2006 16:39:29 -0000 @@ -84,7 +84,7 @@ int fgcmd(int, char **); int bgcmd(int, char **); int jobscmd(int, char **); -void showjobs(int, int, int); +void showjobs(int, int, int, int); int waitcmd(int, char **); int jobidcmd(int, char **); struct job *makejob(union node *, int); Index: main.c =================================================================== RCS file: /home/ncvs/src/bin/sh/main.c,v retrieving revision 1.28 diff -u -r1.28 main.c --- main.c 2 Apr 2006 18:51:32 -0000 1.28 +++ main.c 17 Sep 2006 16:39:29 -0000 @@ -211,7 +211,7 @@ inter = 0; if (iflag && top) { inter++; - showjobs(1, 0, 0); + showjobs(1, 0, 0, 0); chkmail(0); flushout(&output); } Index: sh.1 =================================================================== RCS file: /home/ncvs/src/bin/sh/sh.1,v retrieving revision 1.122 diff -u -r1.122 sh.1 --- sh.1 29 Jul 2006 09:56:29 -0000 1.122 +++ sh.1 17 Sep 2006 16:39:46 -0000 @@ -1777,7 +1777,7 @@ If the .Ar job argument is omitted, use the current job. -.It Ic jobs Oo Fl ls Oc Op Ar job ... +.It Ic jobs Oo Fl lps Oc Op Ar job ... Print information about the specified jobs, or all jobs if no .Ar job argument is given. @@ -1787,6 +1787,10 @@ .Fl l option is specified, the PID of each job is also printed. If the +.Fl p +option is specified, only the process IDs for the process group leaders +are printed, one per line. +If the .Fl s option is specified, only the PIDs of the jobs are printed, one per line. .It Ic local Oo Ar variable ... Oc Op Fl --- src_bin_sh_jobs_p.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: