Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-6]: src/bin/cat Pull up revision 1.32 (requested by mason in ti...



details:   https://anonhg.NetBSD.org/src/rev/3dcfa2d0adbc
branches:  netbsd-1-6
changeset: 527874:3dcfa2d0adbc
user:      lukem <lukem%NetBSD.org@localhost>
date:      Tue Jun 11 15:45:25 2002 +0000

description:
Pull up revision 1.32 (requested by mason in ticket #243):
Add -l option to cat(1), as discussed on tech-userlevel. This option
causes cat(1) to use fcntl(2) to set an exclusive advisory lock on stdout.
While being useful in its own right, this will shortly be used to
guarantee orderly writing to METALOG in the case of unprivileged builds
with NBUILDJOBS > 1.

diffstat:

 bin/cat/cat.c |  23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diffs (74 lines):

diff -r ac9106cd6760 -r 3dcfa2d0adbc bin/cat/cat.c
--- a/bin/cat/cat.c     Tue Jun 11 15:45:15 2002 +0000
+++ b/bin/cat/cat.c     Tue Jun 11 15:45:25 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cat.c,v 1.31 2002/05/09 02:19:42 simonb Exp $      */
+/* $NetBSD: cat.c,v 1.31.2.1 2002/06/11 15:45:25 lukem Exp $   */
 
 /*
  * Copyright (c) 1989, 1993
@@ -47,7 +47,7 @@
 #if 0
 static char sccsid[] = "@(#)cat.c      8.2 (Berkeley) 4/27/95";
 #else
-__RCSID("$NetBSD: cat.c,v 1.31 2002/05/09 02:19:42 simonb Exp $");
+__RCSID("$NetBSD: cat.c,v 1.31.2.1 2002/06/11 15:45:25 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -64,7 +64,7 @@
 #include <string.h>
 #include <unistd.h>
 
-int bflag, eflag, fflag, nflag, sflag, tflag, vflag;
+int bflag, eflag, fflag, lflag, nflag, sflag, tflag, vflag;
 int rval;
 const char *filename;
 
@@ -78,11 +78,12 @@
 main(int argc, char *argv[])
 {
        int ch;
+       struct flock stdout_lock;
 
        setprogname(argv[0]);
        (void)setlocale(LC_ALL, "");
 
-       while ((ch = getopt(argc, argv, "befnstuv")) != -1)
+       while ((ch = getopt(argc, argv, "beflnstuv")) != -1)
                switch (ch) {
                case 'b':
                        bflag = nflag = 1;      /* -b implies -n */
@@ -93,6 +94,9 @@
                case 'f':
                        fflag = 1;
                        break;
+               case 'l':
+                       lflag = 1;
+                       break;
                case 'n':
                        nflag = 1;
                        break;
@@ -111,12 +115,21 @@
                default:
                case '?':
                        (void)fprintf(stderr,
-                           "usage: cat [-befnstuv] [-] [file ...]\n");
+                           "usage: cat [-beflnstuv] [-] [file ...]\n");
                        exit(1);
                        /* NOTREACHED */
                }
        argv += optind;
 
+       if (lflag) {
+               stdout_lock.l_len = 0;
+               stdout_lock.l_start = 0;
+               stdout_lock.l_type = F_WRLCK;
+               stdout_lock.l_whence = SEEK_SET;
+               if (fcntl(STDOUT_FILENO, F_SETLKW, &stdout_lock) == -1)
+                       err(EXIT_FAILURE, "stdout");
+       }
+
        if (bflag || eflag || nflag || sflag || tflag || vflag)
                cook_args(argv);
        else



Home | Main Index | Thread Index | Old Index