Subject: New cat(1) option (was: Re: Possible solution to toolchain/16963 - NBUILDJOBS/METALOG conflict)
To: Martin Husemann <martin@duskware.de>
From: Mason Loring Bliss <mason@acheron.middleboro.ma.us>
List: tech-userlevel
Date: 06/07/2002 15:46:06
--XUMBhxr+x2Jl+q54
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Jun 07, 2002 at 08:42:47AM +0200, Martin Husemann wrote:

> > Since this works, locking stdout would seem to be a useful option for
> > cat(1), perhaps.
>=20
> Sounds good, and cat even has free option letters left ;-)

It's the simplest solution of the lot, additionally.


> Any hint from relevant standards?

There's nothing that I can see. The only argument to cat noted in SuS2 is
"-u". I would suggest "-l" for "lock".

If no one objects to this, I'd like to apply the following patches to cat.
I'll give it until Monday for objections, unless discussions ensues in the
interim.

Along with this, I'd like to make basesrc/share/man/Makefile and
basesrc/share/zoneinfo/Makefile use this to lock METALOG, so that builds
with -j > 1 can complete. I'd also like to submit a pull-up request so that
netbsd-1-6 can build with -j > 1. However, this would require having cat as
a host tool, and I need to read more to see how to do that.  So, for
starters, I'd like to simply add this useful cat functionality to the base
system.

Thanks in advance for constructive comments.


Index: cat.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/basesrc/bin/cat/cat.1,v
retrieving revision 1.25
diff -u -w -r1.25 cat.1
--- cat.1       2002/05/15 06:52:54     1.25
+++ cat.1       2002/06/07 19:39:38
@@ -79,6 +79,8 @@
 as well.
 .It Fl f
 Only attempt to display regular files.
+.It Fl l
+Set an exclusive advisory lock on the standard output file descriptor.
 .It Fl n
 Number the output lines, starting at 1.
 .It Fl s


Index: cat.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/basesrc/bin/cat/cat.c,v
retrieving revision 1.31
diff -u -w -r1.31 cat.c
--- cat.c	2002/05/09 02:19:42	1.31
+++ cat.c	2002/06/07 19:40:23
@@ -82,7 +82,7 @@
 	setprogname(argv[0]);
 	(void)setlocale(LC_ALL, "");
=20
-	while ((ch =3D getopt(argc, argv, "befnstuv")) !=3D -1)
+	while ((ch =3D getopt(argc, argv, "beflnstuv")) !=3D -1)
 		switch (ch) {
 		case 'b':
 			bflag =3D nflag =3D 1;	/* -b implies -n */
@@ -93,6 +93,9 @@
 		case 'f':
 			fflag =3D 1;
 			break;
+		case 'l':
+			flock(STDOUT_FILENO, LOCK_EX);
+			break;
 		case 'n':
 			nflag =3D 1;
 			break;
@@ -111,7 +114,7 @@
 		default:
 		case '?':
 			(void)fprintf(stderr,
-			    "usage: cat [-befnstuv] [-] [file ...]\n");
+			    "usage: cat [-beflnstuv] [-] [file ...]\n");
 			exit(1);
 			/* NOTREACHED */
 		}


--=20
Mason Loring Bliss   mason@acheron.middleboro.ma.us   Ewige Blumenkraft!
https://www.deadsexy.org/  awake ? sleep : random() & 2 ? dream : sleep;

--XUMBhxr+x2Jl+q54
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (NetBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE9AQ1+ykMMY715wXIRAi6SAKCp22Nwz4iNX76iXlxLvG9pHu8eFgCgtdq3
KANdpy6QXaAz25C5ZixT3pc=
=18g1
-----END PGP SIGNATURE-----

--XUMBhxr+x2Jl+q54--