From 65ee8e8556e0c293b039fcea0cdcde40cf412483 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sat, 16 Feb 2008 22:09:30 +0000 Subject: [PATCH] Use lockf instead of flock, the former works on NFS. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2678 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- lib_internal/util-lockfile.c | 4 ++-- src/lockfile.c | 6 +++--- src/secure-mount.c | 4 ++-- vserver-start/main.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib_internal/util-lockfile.c b/lib_internal/util-lockfile.c index b08f5a3..bbfd18c 100644 --- a/lib_internal/util-lockfile.c +++ b/lib_internal/util-lockfile.c @@ -61,8 +61,8 @@ lockfile(int *fd, char const *filename, int op, long timeout, alarm(timeout); } - errstr = "flock()"; - while (flock(*fd, op)==-1) { + errstr = "lockf()"; + while (lockf(*fd, op, 0)==-1) { if ((errno!=EINTR && errno!=EINTR) || alarm_flag) goto err; } diff --git a/src/lockfile.c b/src/lockfile.c index d94b196..eabfe68 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -44,7 +44,7 @@ showHelp(char const *cmd) " 2. 'lockfile' will be called\n" " 3a. 'lockfile' waits until somebody opens the for reading\n" " 3b. parent (shell) opens the pipe for reading and blocks\n" - " 4. 'lockfile' calls flock() on the \n" + " 4. 'lockfile' calls lockf() on the \n" " 5. 'lockfile' closes the \n" " 6. parent (shell) unlocks since is closed\n" " 7. 'lockfile' goes into infinite loop\n" @@ -123,9 +123,9 @@ int main(int argc, char *argv[]) int duration = end_time-time(0); alarm(MIN(10, MAX(duration,1))); - if (flock(fd,LOCK_EX)==-1) { + if (lockf(fd,F_LOCK,0)==-1) { if (errno==EINTR) continue; - perror("lockfile: flock()"); + perror("lockfile: lockf()"); break; } signal(SIGALRM, SIG_IGN); diff --git a/src/secure-mount.c b/src/secure-mount.c index a722f1f..a76f7a0 100644 --- a/src/secure-mount.c +++ b/src/secure-mount.c @@ -279,8 +279,8 @@ updateMtab(struct MountInfo const *mnt, struct Options const *opt) goto err0; } - if (flock(fd, LOCK_EX)==-1) { - perror("secure-mount: flock()"); + if (lockf(fd, F_LOCK, 0)==-1) { + perror("secure-mount: lockf()"); goto err1; } diff --git a/vserver-start/main.c b/vserver-start/main.c index 634a734..1ba419e 100644 --- a/vserver-start/main.c +++ b/vserver-start/main.c @@ -98,7 +98,7 @@ initLock() ptr = Xmemcpy(ptr, ".startup", sizeof(".startup")); *ptr = '\0'; - if (!lockfile(&fd, tmp, LOCK_EX, 30, &err)) { + if (!lockfile(&fd, tmp, F_LOCK, 30, &err)) { WRITE_MSG(2, "vserver.start: failed to lock '"); WRITE_STR(2, tmp); WRITE_MSG(2, "': "); -- 1.8.1.5