Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-6]: src/usr.bin/flock Pull up following revision(s) (requested by...
details: https://anonhg.NetBSD.org/src/rev/c1e3decf77da
branches: netbsd-6
changeset: 776747:c1e3decf77da
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Mon Nov 03 19:26:02 2014 +0000
description:
Pull up following revision(s) (requested by manu in ticket #1143):
usr.bin/flock/flock.c: revision 1.10
usr.bin/flock/flock.c: revision 1.11
usr.bin/flock/flock.1: revision 1.10
usr.bin/flock/flock.c: revision 1.8
PR/48351: Dennis Ferguson: Fix incorrect parsing of flock flags.
XXX: still flock -s 0 fails with EINVAL, why?
make this behave like linux.
remove XXX, fix error message
mention that -x is the default.
diffstat:
usr.bin/flock/flock.1 | 5 +++--
usr.bin/flock/flock.c | 28 ++++++++++++++++++++--------
2 files changed, 23 insertions(+), 10 deletions(-)
diffs (117 lines):
diff -r 994279b6d3f4 -r c1e3decf77da usr.bin/flock/flock.1
--- a/usr.bin/flock/flock.1 Mon Nov 03 19:18:09 2014 +0000
+++ b/usr.bin/flock/flock.1 Mon Nov 03 19:26:02 2014 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: flock.1,v 1.8.4.3 2013/09/21 16:39:58 riz Exp $
+.\" $NetBSD: flock.1,v 1.8.4.4 2014/11/03 19:26:02 msaitoh 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 @@
.Ar seconds .
.It Fl x , Fl Fl exclusive
Obtain an exclusive lock.
+This is the default.
.El
.Sh EXIT STATUS
.Ex -std
diff -r 994279b6d3f4 -r c1e3decf77da usr.bin/flock/flock.c
--- a/usr.bin/flock/flock.c Mon Nov 03 19:18:09 2014 +0000
+++ b/usr.bin/flock/flock.c Mon Nov 03 19:26:02 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: flock.c,v 1.6.4.3 2013/02/10 23:42:19 riz Exp $ */
+/* $NetBSD: flock.c,v 1.6.4.4 2014/11/03 19:26:02 msaitoh Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: flock.c,v 1.6.4.3 2013/02/10 23:42:19 riz Exp $");
+__RCSID("$NetBSD: flock.c,v 1.6.4.4 2014/11/03 19:26:02 msaitoh Exp $");
#include <stdio.h>
#include <string.h>
@@ -43,6 +43,7 @@
#include <errno.h>
#include <getopt.h>
#include <paths.h>
+#include <limits.h>
#include <time.h>
static struct option flock_longopts[] = {
@@ -149,12 +150,13 @@
main(int argc, char *argv[])
{
int c;
- int lock = LOCK_EX;
+ int lock = 0;
double timeout = 0;
int cls = 0;
int fd = -1;
int debug = 0;
int verbose = 0;
+ long l;
char *mcargv[] = {
__UNCONST(_PATH_BSHELL), __UNCONST("-c"), NULL, NULL
};
@@ -170,7 +172,8 @@
debug++;
break;
case 'x':
- if (lock & ~LOCK_NB)
+#define T(l) (lock & ~LOCK_NB) != (l) && (lock & ~LOCK_NB) != 0
+ if (T(LOCK_EX))
goto badlock;
lock |= LOCK_EX;
break;
@@ -178,12 +181,12 @@
lock |= LOCK_NB;
break;
case 's':
- if (lock & ~LOCK_NB)
+ if (T(LOCK_SH))
goto badlock;
lock |= LOCK_SH;
break;
case 'u':
- if (lock & ~LOCK_NB)
+ if (T(LOCK_UN))
goto badlock;
lock |= LOCK_UN;
break;
@@ -205,13 +208,22 @@
argc -= optind;
argv += optind;
+ if ((lock & ~LOCK_NB) == 0)
+ 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));
Home |
Main Index |
Thread Index |
Old Index