Module Name:    src
Committed By:   martin
Date:           Sat Aug 30 14:06:55 UTC 2014

Modified Files:
        src/usr.bin/flock [netbsd-7]: flock.1 flock.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #68):
        usr.bin/flock/flock.c: revision 1.9 - 1.11
        usr.bin/flock/flock.1: revision 1.10
Annotate functions using format strings.
Improve Linux compatibility, by making exclusive lock the default.
Also check for file descriptor value being sane.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.9.4.1 src/usr.bin/flock/flock.1 \
    src/usr.bin/flock/flock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/flock/flock.1
diff -u src/usr.bin/flock/flock.1:1.9 src/usr.bin/flock/flock.1:1.9.4.1
--- src/usr.bin/flock/flock.1:1.9	Sat Sep 21 15:01:14 2013
+++ src/usr.bin/flock/flock.1	Sat Aug 30 14:06:55 2014
@@ -1,4 +1,4 @@
-.\"	$NetBSD: flock.1,v 1.9 2013/09/21 15:01:14 khorben Exp $
+.\"	$NetBSD: flock.1,v 1.9.4.1 2014/08/30 14:06:55 martin Exp $
 .\"
 .\" Copyright (c) 2012 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\"
-.Dd November 2, 2012
+.Dd August 18, 2014
 .Dt FLOCK 1
 .Os
 .Sh NAME
@@ -87,6 +87,7 @@ Fail if the lock could not be obtained a
 .Ar seconds .
 .It Fl x , Fl Fl exclusive
 Obtain an exclusive lock.
+This is the default.
 .El
 .Sh EXIT STATUS
 .Ex -std
Index: src/usr.bin/flock/flock.c
diff -u src/usr.bin/flock/flock.c:1.9 src/usr.bin/flock/flock.c:1.9.4.1
--- src/usr.bin/flock/flock.c:1.9	Tue Jan  7 02:07:08 2014
+++ src/usr.bin/flock/flock.c	Sat Aug 30 14:06:55 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: flock.c,v 1.9 2014/01/07 02:07:08 joerg Exp $	*/
+/*	$NetBSD: flock.c,v 1.9.4.1 2014/08/30 14:06:55 martin Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: flock.c,v 1.9 2014/01/07 02:07:08 joerg Exp $");
+__RCSID("$NetBSD: flock.c,v 1.9.4.1 2014/08/30 14:06:55 martin Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -43,6 +43,7 @@ __RCSID("$NetBSD: flock.c,v 1.9 2014/01/
 #include <errno.h>
 #include <getopt.h>
 #include <paths.h>
+#include <limits.h>
 #include <time.h>
 
 static struct option flock_longopts[] = {
@@ -155,6 +156,7 @@ main(int argc, char *argv[])
 	int fd = -1;
 	int debug = 0;
 	int verbose = 0;
+	long l;
 	char *mcargv[] = {
 	    __UNCONST(_PATH_BSHELL), __UNCONST("-c"), NULL, NULL
 	};
@@ -207,15 +209,21 @@ main(int argc, char *argv[])
 	argv += optind;
 
 	if ((lock & ~LOCK_NB) == 0)
-		usage("Missing lock type flag");
+		lock |= LOCK_EX;	/* default to exclusive like linux */
 
 	switch (argc) {
 	case 0:
 		usage("Missing lock file argument");
 	case 1:
 		if (cls)
-			usage("Close is valid only for descriptors");
-		fd = strtol(argv[0], NULL, 0);	// XXX: error checking
+			usage("Close is not valid for descriptors");
+		errno = 0;
+		l = strtol(argv[0], &v, 0);
+		if ((l == LONG_MIN || l == LONG_MAX) && errno == ERANGE)
+			err(EXIT_FAILURE, "Bad file descriptor `%s'", argv[0]);
+		if (l > INT_MAX || l < 0 || *v)
+			errx(EXIT_FAILURE, "Bad file descriptor `%s'", argv[0]);
+		fd = (int)l;
 		if (debug) {
 			fprintf(stderr, "descriptor %s lock %s\n",
 			    argv[0], lock2name(lock));

Reply via email to