summaryrefslogtreecommitdiffstats
path: root/sys-utils/flock.c
diff options
context:
space:
mode:
authorAlexey Gladkov2008-11-24 16:15:36 +0100
committerKarel Zak2008-12-03 10:33:53 +0100
commitff5717391c3cebb4799c8e5d6dd9876fc5005fd0 (patch)
tree85a4f5c1c2cc88def62403810de87fa2643ae673 /sys-utils/flock.c
parentdocs: add feature-requests from RH bugzilla to TODO list (diff)
downloadkernel-qcow2-util-linux-ff5717391c3cebb4799c8e5d6dd9876fc5005fd0.tar.gz
kernel-qcow2-util-linux-ff5717391c3cebb4799c8e5d6dd9876fc5005fd0.tar.xz
kernel-qcow2-util-linux-ff5717391c3cebb4799c8e5d6dd9876fc5005fd0.zip
flock: Allow lock directory
With this patch, you can lock directory. Additionally, lockfile opens with O_NOCTTY. Try to open file with O_CREAT flag first, and without it if open fails with EISDIR. Suggested by H. Peter Anvin. Signed-off-by: Alexey Gladkov <legion@altlinux.org>
Diffstat (limited to 'sys-utils/flock.c')
-rw-r--r--sys-utils/flock.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sys-utils/flock.c b/sys-utils/flock.c
index 6c1acc32f..029e43647 100644
--- a/sys-utils/flock.c
+++ b/sys-utils/flock.c
@@ -62,6 +62,7 @@ static void usage(int ex)
"flock (%s)\n"
"Usage: %s [-sxun][-w #] fd#\n"
" %s [-sxon][-w #] file [-c] command...\n"
+ " %s [-sxon][-w #] directory [-c] command...\n"
" -s --shared Get a shared lock\n"
" -x --exclusive Get an exclusive lock\n"
" -u --unlock Remove a lock\n"
@@ -201,7 +202,11 @@ int main(int argc, char *argv[])
}
filename = argv[optind];
- fd = open(filename, O_RDONLY|O_CREAT, 0666);
+ fd = open(filename, O_RDONLY|O_NOCTTY|O_CREAT, 0666);
+ /* Linux doesn't like O_CREAT on a directory, even though it should be a
+ no-op */
+ if (fd < 0 && errno == EISDIR)
+ fd = open(filename, O_RDONLY|O_NOCTTY);
if ( fd < 0 ) {
err = errno;