3 * Copyright (c) 1996 Regents of the University of Michigan.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that this notice is preserved and that due credit is given
8 * to the University of Michigan at Ann Arbor. The name of the University
9 * may not be used to endorse or promote products derived from this
10 * software without specific prior written permission. This software
11 * is provided ``as is'' without express or implied warranty.
15 * lock.c - routines to open and apply an advisory lock to a file
23 #include <ac/string.h>
24 #include <ac/socket.h>
26 #include <ac/unistd.h>
28 #ifdef HAVE_SYS_FILE_H
45 /* open the lock file */
47 strcat( buf, ".lock" );
48 if ( (*lfp = fopen( buf, "w" )) == NULL ) {
49 Debug( LDAP_DEBUG_ANY,
50 "Error: could not open \"%s\"\n", buf, 0, 0 );
54 /* acquire the lock */
55 ldap_lockf( fileno(*lfp) );
57 /* open the log file */
58 if ( (fp = fopen( fname, type )) == NULL ) {
59 Debug( LDAP_DEBUG_ANY,
60 "Error: could not open \"%s\"\n", fname, 0, 0 );
61 ldap_unlockf( fileno(*lfp) );
79 ldap_unlockf( fileno(lfp) );
82 return( fclose( fp ) );
88 * Apply an advisory lock on a file. Just calls lock_fopen()
97 if (( *rfp = lock_fopen( file, "r+", lfp )) == NULL ) {
98 Debug( LDAP_DEBUG_ANY,
99 "Error: acquire_lock(%ld): Could not acquire lock on \"%s\"\n",
100 (long) getpid(), file, 0);
109 * Relinquish a lock on a file. Calls lock_fclose() and also removes the
119 if ( lock_fclose( rfp, lfp ) == EOF ) {
120 Debug( LDAP_DEBUG_ANY,
121 "Error: relinquish_lock (%ld): Error closing \"%s\"\n",
122 (long) getpid(), file, 0 );