summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2005-07-10 07:10:58 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2005-07-10 07:10:58 (GMT)
commit86dd19a26e206bd84477aec4bacc214e26f852aa (patch)
treecda643aef5ff646794ba1b15a439fccb6c36043d
parent7aa182fa09daf8b857ac53ca043e54eeccf1a3ff (diff)
downloadflock-86dd19a26e206bd84477aec4bacc214e26f852aa.zip
flock-86dd19a26e206bd84477aec4bacc214e26f852aa.tar.gz
flock-86dd19a26e206bd84477aec4bacc214e26f852aa.tar.bz2
flock-86dd19a26e206bd84477aec4bacc214e26f852aa.tar.xz
Avoid libiberty, handle -w 0 as -n
-rw-r--r--Makefile2
-rw-r--r--flock.c26
-rw-r--r--flock.spec5
-rw-r--r--version2
4 files changed, 22 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 869f0d6..642c00e 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CC = cc
CFLAGS = -g -O -W -Wall
LDFLAGS =
INSTALL = install
-LIBS = -liberty # For xmalloc()
+LIBS =
prefix = /usr/local
BINDIR = $(prefix)/bin
MANDIR = $(prefix)/man/man1
diff --git a/flock.c b/flock.c
index f08a685..d5572f0 100644
--- a/flock.c
+++ b/flock.c
@@ -26,8 +26,6 @@
#include <sys/time.h>
#include <sys/wait.h>
-extern void *xmalloc(size_t); /* in libiberty.a */
-
static const struct option long_options[] = {
{ "shared", 0, NULL, 's' },
{ "exclusive", 0, NULL, 'x' },
@@ -117,7 +115,7 @@ int main(int argc, char *argv[])
int err;
int status;
char *eon;
- char **cmd_argv = NULL;
+ char **cmd_argv = NULL, *sh_c_argv[4];
const char *filename = NULL;
struct sigaction sa, old_sa;
@@ -173,7 +171,7 @@ int main(int argc, char *argv[])
exit(EX_USAGE);
}
- cmd_argv = xmalloc(4*sizeof(char *));
+ cmd_argv = sh_c_argv;
cmd_argv[0] = getenv("SHELL");
if ( !cmd_argv[0] || !*cmd_argv[0] )
@@ -210,13 +208,21 @@ int main(int argc, char *argv[])
}
if ( have_timeout ) {
- memset(&sa, 0, sizeof sa);
-
- sa.sa_handler = timeout_handler;
- sa.sa_flags = SA_ONESHOT;
- sigaction(SIGALRM, &sa, &old_sa);
+ if ( timeout.it_value.tv_sec == 0 &&
+ timeout.it_value.tv_usec == 0 ) {
+ /* -w 0 is equivalent to -n */
- setitimer(ITIMER_REAL, &timeout, &old_timer);
+ have_timeout = 0;
+ block = LOCK_NB;
+ } else {
+ memset(&sa, 0, sizeof sa);
+
+ sa.sa_handler = timeout_handler;
+ sa.sa_flags = SA_ONESHOT;
+ sigaction(SIGALRM, &sa, &old_sa);
+
+ setitimer(ITIMER_REAL, &timeout, &old_timer);
+ }
}
while ( flock(fd, type|block) ) {
diff --git a/flock.spec b/flock.spec
index dded5ed..e35a363 100644
--- a/flock.spec
+++ b/flock.spec
@@ -1,6 +1,6 @@
Summary: A program to manage locks from shell scripts
Name: flock
-Version: 2.0
+Version: 2.0.1
Release: 1
License: MIT
Group: Applications/System
@@ -35,6 +35,9 @@ rm -rf $RPM_BUILD_ROOT
%changelog
* Sat Jul 9 2005 H. Peter Anvin <hpa@zytor.com>
+- Release 2.0.1, -w 0 fix.
+
+* Sat Jul 9 2005 H. Peter Anvin <hpa@zytor.com>
- Release 2.0, add the ability to spawn a process.
* Fri May 2 2003 H. Peter Anvin <hpa@zytor.com>
diff --git a/version b/version
index cd5ac03..38f77a6 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-2.0
+2.0.1