Don't crash if "flock" is used to lock a file descriptor e.g. via

"flock --nb 8".
This commit is contained in:
tron 2013-02-07 13:57:40 +00:00
parent aa178e99e1
commit b981f2c3d3
1 changed files with 6 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: flock.c,v 1.6 2012/11/02 17:03:16 christos Exp $ */
/* $NetBSD: flock.c,v 1.7 2013/02/07 13:57:40 tron Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: flock.c,v 1.6 2012/11/02 17:03:16 christos Exp $");
__RCSID("$NetBSD: flock.c,v 1.7 2013/02/07 13:57:40 tron Exp $");
#include <stdio.h>
#include <string.h>
@ -212,9 +212,12 @@ main(int argc, char *argv[])
if (cls)
usage("Close is valid only for descriptors");
fd = strtol(argv[0], NULL, 0); // XXX: error checking
if (debug)
if (debug) {
fprintf(stderr, "descriptor %s lock %s\n",
argv[0], lock2name(lock));
}
break;
default:
if ((lock & LOCK_NB) == LOCK_UN)
usage("Unlock is only valid for descriptors");