Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/flock make this behave like linux; make -x the default



details:   https://anonhg.NetBSD.org/src/rev/d0ff38da7c6f
branches:  trunk
changeset: 801803:d0ff38da7c6f
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Aug 18 09:14:03 2014 +0000

description:
make this behave like linux; make -x the default

diffstat:

 usr.bin/flock/flock.c |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (58 lines):

diff -r d70189ada500 -r d0ff38da7c6f usr.bin/flock/flock.c
--- a/usr.bin/flock/flock.c     Mon Aug 18 08:07:02 2014 +0000
+++ b/usr.bin/flock/flock.c     Mon Aug 18 09:14:03 2014 +0000
@@ -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 @@
 #include <errno.h>
 #include <getopt.h>
 #include <paths.h>
+#include <limits.h>
 #include <time.h>
 
 static struct option flock_longopts[] = {
@@ -155,6 +156,7 @@
        int fd = -1;
        int debug = 0;
        int verbose = 0;
+       long l;
        char *mcargv[] = {
            __UNCONST(_PATH_BSHELL), __UNCONST("-c"), NULL, NULL
        };
@@ -207,7 +209,7 @@
        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 @@
        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));



Home | Main Index | Thread Index | Old Index