61
63
static void usage(int ex)
63
fputs("flock (" PACKAGE_STRING ")\n", stderr);
65
fputs(_("\nUsage:\n"), stderr);
65
_("Usage: %1$s [-sxun][-w #] fd#\n"
66
" %1$s [-sxon][-w #] file [-c] command...\n"
67
" %1$s [-sxon][-w #] directory [-c] command...\n"
68
" -s --shared Get a shared lock\n"
69
" -x --exclusive Get an exclusive lock\n"
70
" -u --unlock Remove a lock\n"
71
" -n --nonblock Fail rather than wait\n"
72
" -w --timeout Wait for a limited amount of time\n"
73
" -o --close Close file descriptor before running command\n"
74
" -c --command Run a single command string through the shell\n"
75
" -h --help Display this text\n"
76
" -V --version Display version\n"),
67
_(" %1$s [-sxun][-w #] fd#\n"
68
" %1$s [-sxon][-w #] file [-c] command...\n"
69
" %1$s [-sxon][-w #] directory [-c] command...\n"), program);
71
fputs(_("\nOptions:\n"), stderr);
72
fputs(_(" -s --shared Get a shared lock\n"
73
" -x --exclusive Get an exclusive lock\n"
74
" -u --unlock Remove a lock\n"
75
" -n --nonblock Fail rather than wait\n"
76
" -w --timeout Wait for a limited amount of time\n"
77
" -o --close Close file descriptor before running command\n"
78
" -c --command Run a single command string through the shell\n"
79
" -h --help Display this text\n"
80
" -V --version Display version\n\n"), stderr);
210
214
filename = argv[optind];
211
fd = open(filename, O_RDONLY|O_NOCTTY|O_CREAT, 0666);
215
open_accmode = ((type == LOCK_SH || access(filename, R_OK|W_OK) < 0) ?
217
fd = open(filename, open_accmode|O_NOCTTY|O_CREAT, 0666);
212
218
/* Linux doesn't like O_CREAT on a directory, even though it should be a
219
no-op; POSIX doesn't allow O_RDWR or O_WRONLY */
214
220
if (fd < 0 && errno == EISDIR)
215
221
fd = open(filename, O_RDONLY|O_NOCTTY);