discoteq / flock Goto Github PK
View Code? Open in Web Editor NEWflock(1) locks files
License: ISC License
flock(1) locks files
License: ISC License
[janpoboril@web470 flock-0.2.0]$ ./configure
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking whether make supports nested variables... yes
checking how to create a pax tar archive... gnutar
checking dependency style of gcc... gcc3
checking whether make supports nested variables... (cached) yes
checking for gawk... (cached) gawk
checking for gcc option to accept ISO C99... -std=gnu99
checking for gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for an ANSI C-conforming const... yes
checking for working volatile... yes
checking whether byte ordering is bigendian... no
checking err.h usability... yes
checking err.h presence... yes
checking for err.h... yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking signal.h usability... yes
checking signal.h presence... yes
checking for signal.h... yes
checking stdio.h usability... yes
checking stdio.h presence... yes
checking for stdio.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sysexits.h usability... yes
checking sysexits.h presence... yes
checking for sysexits.h... yes
checking for unistd.h... (cached) yes
checking for err... yes
checking for errx... yes
checking for warn... yes
checking for warnx... yes
checking for flock... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
[janpoboril@web470 flock-0.2.0]$ make
make all-am
make[1]: Entering directory `/home/janpoboril/flock-0.2.0'
CC src/flock.o
cc1: error: unrecognized command line option "-Wunused-result"
make[1]: *** [src/flock.o] Error 1
make[1]: Leaving directory `/home/janpoboril/flock-0.2.0'
make: *** [all] Error 2
At the very least, we should automatically run tests on linux. Having access to other environments would be gravy.
So I have this code that I stole for Linux. I am hoping that it works on BSD:
(
flock -x 200
my_file="$HOME/.locking/counts/counts.json"
touch "$my_file"
my_str=$(cat "$my_file");
typeset -i my_num="${my_str:-"1"}"
echo "$((my_num=my_num+$1))" | tee "$my_file"
) 200 >>/var/lock/mylockfile
my question is - can you explain what this syntax is doing? The 200 is not being passed to flock as a timeout is it? So what is the 200 doing?
>brew tap discoteq/discoteq
>brew install flock
==> Installing flock from discoteq/discoteq
==> Downloading https://github.com/discoteq/flock/releases/download/v0.2.3/flock-0.2.3.tar.xz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/23032276/003d8852-a57e-11e5-97b9-c3b1a6767edc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F
curl: (22) The requested URL returned error: 407
Error: Failed to download resource "flock"
Download failed: https://github.com/discoteq/flock/releases/download/v0.2.3/flock-0.2.3.tar.xz
I'm just a little confused, please advise if I'm doing something wrong. My understanding is that flock should CREATE a file to lock if it doesn't exist, but nothing is ever created. From man page: "It locks a specified file or directory, which is created (assuming appropriate permissions), if it does not already exist."
I'm trying to only run a script from cron if a lock cannot be acquired in order to avoid running it if it is already running (because it creates incoming connections to a server).
I have this in crontab:
* 10 * * * /usr/bin/flock -n /tmp/somescript.lockfile sh /Users/me/somescript.sh
I'm on Mac OSX mojave, 10.14.6.
I think a precompiled *.1 file should be included with the project so people don't have to install Ronn to get a man page. I'd submit a pull request adding this, but I don't have Ronn installed to generate it.
Would be nice to have a -h
/--help
option that returns with exit status 0.
When building flock 0.4.0 with GCC 11.1.0, I get the following compilation error:
src/flock.c: In function ‘main’:
src/flock.c:323:32: error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘__suseconds_t’ {aka ‘long int’} [-Werror=format=]
323 | printf("took %1u microseconds\n", (t_l_acq.tv_usec - t_l_req.tv_usec)); // not adding due to time constraints
| ~~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| unsigned int __suseconds_t {aka long int}
| %1lu
cc1: all warnings being treated as errors
As the compiler recommends, it can be fixed by simply replacing %1u
with %1lu
. After making this change Flock was successfully built on my system.
First of all, thanks for this project. It's great! ⭐️
On Linux, flock(1)
will only accept a single string argument as the -c
argument. This does not work with discoteq/flock
:
$ touch test.txt
$ flock test.txt -c 'echo 1'
1
$ flock test.txt -c echo 1
flock: -c requires exactly one command argument
$ touch test.txt
$ ./flock -x test.txt -c "echo 1"
flock: failed to execute command: echo 1: No such file or directory
Interestingly, BusyBox also fails:
$ flock -x test.txt -c 'echo 1'; echo $?
255
commit 49c73617a18be069bf9f922b07d466511d1d3f5f
Merge: c02fc6b ec6f09e
Author: Joseph Anthony Pasquale Holsten <[email protected]>
Date: Thu Dec 1 15:25:23 2016 -0800
on macos
Build command failed.
Error while executing process /Users/xxxx/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /Users/xxxxx/Downloads/wireguard-android/tunnel/.cxx/Debug/515k7116/arm64-v8a libwg-quick.so libwg.so}
ninja: Entering directory `/Users/xxxxx/Downloads/wireguard-android/tunnel/.cxx/Debug/515k7116/arm64-v8a'
[1/15] Building wireguard-go
FAILED: CMakeFiles/libwg-go.so
.......................
.....................
96 137M 96 132M 0 0 4431k 0 0:00:31 0:00:30 0:00:01 4892k
100 137M 100 137M 0 0 4461k 0 0:00:31 0:00:31 --:--:-- 4949k
zsh:1: command not found: sha256sum
make: *** [/Users/xxxx/.gradle/caches/golang/go1.18.2.darwin-amd64.tar.gz] Error 127
ninja: build stopped: subcommand failed.
because I can't remember how to bootstrap, much less expect others to.
I have just tried to use it on macOS Mojave but can't.
flock -n ~/my-lock.lock -c "rsync -avEr --progress --delete-after -e \"ssh -p 5443 -o StrictHostKeyChecking=no\" ~/Documents [email protected]:/Documents/"
The command above says
flock: failed to execute command: -c: No such file or directory
Then tried without -c
and got No such file or directory
as well.
Any ideas?
Thanks
Create a package: http://www.perkin.org.uk/posts/creating-local-smartos-packages.html
Ultimately try to get it upstream into pkgsrc.
support a traditional port according to the porter's handbook
perhaps also a pkgng binary as well
No release in 5 years, yet there have been changes that are useful (such as -x
).
Could you tag a release please?
omnios does not support the full set of features defined in t/default.bats
, presumably because it does not have a native implementation of flock(2)
.
Either these features should be fixed, or disabled so users can't accidentally perform dangerous operations with a broken flock.
The usage shown with --help
suggests that --version
or -V
will "output version information and exit". This is not the case:
$ ./flock --help
Usage:
flock [-sxun][-w #] fd#
flock [-sxon][-w #] file [-c] command...
flock [-sxon][-w #] directory [-c] command...
Options:
-s --shared Get a shared lock
-x --exclusive Get an exclusive lock
-u --unlock Remove a lock
-n --nonblock Fail rather than wait
-w --timeout Wait for a limited amount of time
-o --close Close file descriptor before running command
-c --command Run a single command string through the shell
-h --help Display this text
-V --version Display version
$ ./flock --version
flock: unrecognized option `--version'
<prints usage info>
$ ./flock -V
flock: invalid option -- V
<prints usage info>
time-sensitive tests do not perform well on extremely small virtual machines. Probably they should be modified to check order of execution.
on debian 8.2.2, getting
vagrant@debian-jessie:~/flock-0.2.0$ make
make all-am
make[1]: Entering directory '/home/vagrant/flock-0.2.0'
CC src/flock.o
src/flock.c: In function ‘main’:
src/flock.c:223:2: error: implicit declaration of function ‘flock’ [-Werror=implicit-function-declaration]
while (0 != flock(fd, type | block)) {
^
src/flock.c:223:2: error: nested extern declaration of ‘flock’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
Makefile:657: recipe for target 'src/flock.o' failed
make[1]: *** [src/flock.o] Error 1
make[1]: Leaving directory '/home/vagrant/flock-0.2.0'
Makefile:540: recipe for target 'all' failed
make: *** [all] Error 2
Just a heads up more than an issue. I added flock to macports as of de9339a0adf26fa745aaeb1d1cf32985f3e3069f
Thus, if you want, you can add
port install flock
to the readme for macports.
resource.h:215:2: error: unknown type name 'uint64_t'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.