]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/lock.c
Update BDB version number to 2.7.5... should rewrite this.
[openldap] / servers / slurpd / lock.c
index 048c42529c61df8b99c0cd812e14c7d9a30fa575..40c61a25171d2bc41280f96cb0432a61a6c1107b 100644 (file)
 
 #include <stdio.h>
 
+#include <ac/string.h>
 #include <ac/socket.h>
 #include <ac/time.h>
 #include <ac/unistd.h>
 
+#ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
+#endif
 
-#include "../slapd/slap.h"
-
+#include "slurp.h"
 
 
 FILE *
@@ -49,24 +53,15 @@ lock_fopen(
        }
 
        /* acquire the lock */
-#ifdef HAVE_FLOCK
-       while ( flock( fileno( *lfp ), LOCK_EX ) != 0 ) 
-#else
-       while ( lockf( fileno( *lfp ), F_LOCK, 0 ) != 0 )
-#endif
-       {
-               ;       /* NULL */
-       }
+       ldap_lockf( fileno(*lfp) );
 
        /* open the log file */
        if ( (fp = fopen( fname, type )) == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                        "Error: could not open \"%s\"\n", fname, 0, 0 );
-#ifdef HAVE_FLOCK
-               flock( fileno( *lfp ), LOCK_UN );
-#else
-               lockf( fileno( *lfp ), F_ULOCK, 0 );
-#endif
+               ldap_unlockf( fileno(*lfp) );
+               fclose( *lfp );
+               *lfp = NULL;
                return( NULL );
        }
 
@@ -82,11 +77,7 @@ lock_fclose(
 )
 {
        /* unlock */
-#ifdef HAVE_FLOCK
-       flock( fileno( lfp ), LOCK_UN );
-#else
-       lockf( fileno( lfp ), F_ULOCK, 0 );
-#endif
+       ldap_unlockf( fileno(lfp) );
        fclose( lfp );
 
        return( fclose( fp ) );
@@ -106,8 +97,8 @@ acquire_lock(
 {
     if (( *rfp = lock_fopen( file, "r+", lfp )) == NULL ) {
        Debug( LDAP_DEBUG_ANY,
-               "Error: acquire_lock(%d): Could not acquire lock on \"%s\"\n",
-               getpid(), file, 0);
+               "Error: acquire_lock(%ld): Could not acquire lock on \"%s\"\n",
+               (long) getpid(), file, 0);
        return( -1 );
     }
     return( 0 );
@@ -128,8 +119,8 @@ relinquish_lock(
 {
     if ( lock_fclose( rfp, lfp ) == EOF ) {
        Debug( LDAP_DEBUG_ANY,
-               "Error: relinquish_lock (%d): Error closing \"%s\"\n",
-               getpid(), file, 0 );
+               "Error: relinquish_lock (%ld): Error closing \"%s\"\n",
+               (long) getpid(), file, 0 );
        return( -1 );
     }
     return( 0 );