Module Name: src
Committed By: christos
Date: Mon Aug 18 09:14:03 UTC 2014
Modified Files:
src/usr.bin/flock: flock.c
Log Message:
make this behave like linux.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.c
diff -u src/usr.bin/flock/flock.c:1.9 src/usr.bin/flock/flock.c:1.10
--- src/usr.bin/flock/flock.c:1.9 Mon Jan 6 21:07:08 2014
+++ src/usr.bin/flock/flock.c Mon Aug 18 05:14:03 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: flock.c,v 1.9 2014/01/07 02:07:08 joerg Exp $ */
+/* $NetBSD: flock.c,v 1.10 2014/08/18 09:14:03 christos 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.10 2014/08/18 09:14:03 christos 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,7 +209,7 @@ 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:
@@ -215,7 +217,13 @@ main(int argc, char *argv[])
case 1:
if (cls)
usage("Close is valid only for descriptors");
- fd = strtol(argv[0], NULL, 0); // XXX: error checking
+ errno = 0;
+ l = strtol(argv[0], &v, 0); // XXX: error checking
+ 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));