Use lockf instead of flock, the former works on NFS.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Sat, 16 Feb 2008 22:09:30 +0000 (22:09 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Sat, 16 Feb 2008 22:09:30 +0000 (22:09 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2678 94cd875c-1c1d-0410-91d2-eb244daf1a30

lib_internal/util-lockfile.c
src/lockfile.c
src/secure-mount.c
vserver-start/main.c

index b08f5a3..bbfd18c 100644 (file)
@@ -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;
   }
 
index d94b196..eabfe68 100644 (file)
@@ -44,7 +44,7 @@ showHelp(char const *cmd)
            "  2.  'lockfile' will be called\n"
            "  3a. 'lockfile' waits until somebody opens the <syncpipe> for reading\n"
            "  3b. parent (shell) opens the pipe for reading and blocks\n"
-           "  4.  'lockfile' calls flock() on the <lockfile>\n"
+           "  4.  'lockfile' calls lockf() on the <lockfile>\n"
            "  5.  'lockfile' closes the <syncpipe>\n"
            "  6.  parent (shell) unlocks since <syncpipe> 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);
index a722f1f..a76f7a0 100644 (file)
@@ -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;
   }
 
index 634a734..1ba419e 100644 (file)
@@ -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, "': ");