summaryrefslogtreecommitdiff
path: root/www/xitami/files/patch-ac
blob: cf30ef326524d7305ab37e86fac09e06324fc49d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--- src/sfl/.vimbk/sflproc.c.vimbk	Sat Apr  1 18:11:24 2000
+++ src/sfl/sflproc.c	Tue Nov  7 11:29:34 2000
@@ -1711,8 +1711,6 @@
         file_handle;
     char
         pid_buffer [10];
-    struct flock
-        lock_file;                      /*  flock() argument block           */
 #endif
     int
         argi = 0,                       /*  Input arguments iterator         */
@@ -1787,17 +1785,21 @@
 
     if (lockfile && strused (lockfile))
       {
-        file_handle = open (lockfile, O_RDWR | O_CREAT, 0640);
-        if (file_handle < 0)
+        if ((file_handle = (open (lockfile, O_RDONLY | O_CREAT, 0640))) == -1)
             return (-1);                /*  We could not open lock file      */
-        else
+        if (flock(file_handle, LOCK_EX | LOCK_NB) == -1 && errno == EWOULDBLOCK)
           {
-            lock_file.l_type = F_WRLCK;
-            if (fcntl (file_handle, F_SETLK, &lock_file))
-                return (-1);            /*  We could not obtain a lock       */
+            close (file_handle);
+            return (-1);                /*  The file is already locked       */
           }
+        close (file_handle);
+
+        if ((file_handle = (open (lockfile, O_RDWR | O_TRUNC, 0640))) == -1)
+            return (-1);                /*  We could not open lock file      */
+        if (flock(file_handle, LOCK_EX | LOCK_NB) == -1)
+            return (-1);                /*  We could not obtain a lock       */
         /*  We record the server's process id in the lock file               */
-        sprintf (pid_buffer, "%6d\n", getpid ());
+        sprintf (pid_buffer, "%ld\n", (long)getpid ());
         write   (file_handle, pid_buffer, strlen (pid_buffer));
       }