Module Name:    src
Committed By:   kre
Date:           Sun Sep 12 01:30:41 UTC 2021

Modified Files:
        src/bin/sh: jobs.c sh.1

Log Message:
Don't dereference NULL on "jobs -Z" (with no title given), instead
do setproctitle(NULL) (which is not the same thing at all).  Do the
same with jobs -Z '' as setting the title to "sh: " isn't useful.

Improve the way this is documented, and note that it is only done
this way because zsh did it first (ie: pass on the balme, doing this
in the jobs command is simply absurd.)


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/bin/sh/jobs.c
cvs rdiff -u -r1.230 -r1.231 src/bin/sh/sh.1

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/jobs.c
diff -u src/bin/sh/jobs.c:1.111 src/bin/sh/jobs.c:1.112
--- src/bin/sh/jobs.c:1.111	Sat Sep 11 20:43:32 2021
+++ src/bin/sh/jobs.c	Sun Sep 12 01:30:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: jobs.c,v 1.111 2021/09/11 20:43:32 christos Exp $	*/
+/*	$NetBSD: jobs.c,v 1.112 2021/09/12 01:30:41 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.111 2021/09/11 20:43:32 christos Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.112 2021/09/12 01:30:41 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -564,7 +564,10 @@ jobscmd(int argc, char **argv)
 		}
 
 	if (mode == SHOW_PROCTITLE) {
-		setproctitle("%s", *argptr);
+		if (*argptr && **argptr)
+			setproctitle("%s", *argptr);
+		else
+			setproctitle(NULL);
 		return 0;
 	}
 

Index: src/bin/sh/sh.1
diff -u src/bin/sh/sh.1:1.230 src/bin/sh/sh.1:1.231
--- src/bin/sh/sh.1:1.230	Sat Sep 11 20:43:32 2021
+++ src/bin/sh/sh.1	Sun Sep 12 01:30:41 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sh.1,v 1.230 2021/09/11 20:43:32 christos Exp $
+.\"	$NetBSD: sh.1,v 1.231 2021/09/12 01:30:41 kre Exp $
 .\" Copyright (c) 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -2977,7 +2977,8 @@ or with
 there is no process group leader (should not happen),
 and otherwise exits with status 0.
 .\"
-.It Ic jobs Oo Fl l Ns \&| Ns Fl p \&| Fl Z Oc Op Ar job ...
+.It Ic jobs Oo Fl l Ns \&| Ns Fl p Oc Op Ar job ...
+.It Ic jobs Fl Z Op Ar title
 Without
 .Ar job
 arguments,
@@ -3009,6 +3010,13 @@ With the
 .Fl Z
 flag, the process command line is set using
 .Xr setproctitle 3 .
+If
+.Ar title
+is omitted or a null string,
+.Xr setproctitle 3
+is called with a NULL format.
+.Pp
+These options are mutually exclusive, the last specified is used.
 .Pp
 In an interactive shell, each job shown as completed in the output
 from the jobs command is implicitly waited for, and is removed from
@@ -4736,5 +4744,13 @@ processed.
 .Pp
 Job control of compound statements (loops, etc) is a complete mess.
 .Pp
+The
+.Fl Z
+option to the
+.Ic jobs
+built-in command is bizarre, but is implemented this way to be
+compatible with the similar option in
+.Xr zsh 1 .
+.Pp
 Many, many, more.
 (But less than there were...)

Reply via email to