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

On Fri, Jun 07, 2002 at 06:47:08PM -0400, Mason Loring Bliss wrote:

> FWIW, it's been pointed out to me that I should be using fcntl, and not
> flock. I'll whip up a new patch to post presently.

Here's an equivalent patch using fcntl(2) directly, instead of flock(2).

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/08 01:02:10
@@ -44,7 +44,7 @@
 .Nd concatenate and print files
 .Sh SYNOPSIS
 .Nm
-.Op Fl befnstuv
+.Op Fl beflnstuv
 .Op Fl
 .Op Ar
 .Sh DESCRIPTION
@@ -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/08 01:02:11
@@ -78,11 +78,12 @@
 main(int argc, char *argv[])
 {
 	int ch;
+	struct flock stdout_lock;
=20
 	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 +94,13 @@
 		case 'f':
 			fflag =3D 1;
 			break;
+		case 'l':
+			stdout_lock.l_start =3D 0;
+			stdout_lock.l_len =3D 0;
+			stdout_lock.l_type =3D F_WRLCK;
+			stdout_lock.l_whence =3D SEEK_SET;
+			fcntl(STDOUT_FILENO, F_SETLKW, &stdout_lock);
+			break;
 		case 'n':
 			nflag =3D 1;
 			break;
@@ -111,7 +119,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;

--adJ1OR3c6QgCpb/j
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

iD8DBQE9AVpKykMMY715wXIRAqwSAJ4qsCFFom8HHXF/kPcbBZ68MiXyrQCdEQOs
QJT4Qd+Cd/w39mEBF1XriCI=
=gd2y
-----END PGP SIGNATURE-----

--adJ1OR3c6QgCpb/j--