]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/reject.c
ITS#2580 - avoid cache deadlock
[openldap] / servers / slurpd / reject.c
index b87f55145a9a9df1315f240940546f40315df502..0b4d5ee12e04f1de9d7c49cebc909464f0cc6baf 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1996 Regents of the University of Michigan.
  * All rights reserved.
  * to a replica LDAP server.
  */
 
-#define DISABLE_BRIDGE
 #include "portable.h"
 
 #include <stdio.h>
-#include <sys/types.h>
+
+#include <ac/stdlib.h>
+#include <ac/errno.h>
+#include <ac/unistd.h>
+
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
 
 #include "slurp.h"
 #include "globals.h"
 
-#ifndef DECL_SYS_ERRLIST
-extern char *sys_errlist[];
-#endif /* DECL_SYS_ERRLIST */
-
+#ifdef _WIN32
+#define        PORTSEP ","
+#else
+#define        PORTSEP ":"
+#endif
 
 /*
  * Write a replication record to a reject file.  The reject file has the
@@ -54,27 +62,38 @@ write_reject(
     FILE       *rfp, *lfp;
     int                rc;
 
-    pthread_mutex_lock( &sglob->rej_mutex );
-    sprintf( rejfile, "%s/%s:%d.rej", sglob->slurpd_rdir,
-           ri->ri_hostname, ri->ri_port );
+    ldap_pvt_thread_mutex_lock( &sglob->rej_mutex );
+    snprintf( rejfile, sizeof rejfile, "%s" LDAP_DIRSEP "%s" PORTSEP "%d.rej",
+               sglob->slurpd_rdir, ri->ri_hostname, ri->ri_port );
 
     if ( access( rejfile, F_OK ) < 0 ) {
        /* Doesn't exist - try to create */
        int rjfd;
-       if (( rjfd = open( rejfile, O_RDWR | O_APPEND | O_CREAT,
+       if (( rjfd = open( rejfile, O_RDWR|O_APPEND|O_CREAT|O_EXCL,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP )) < 0 ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG ( SLURPD, ERR, "write_reject: "
+                       "Error: Cannot create \"%s\":%s\n", 
+                       rejfile, sys_errlist[ errno ], 0 );
+#else
            Debug( LDAP_DEBUG_ANY,
                "Error: write_reject: Cannot create \"%s\": %s\n",
                rejfile, sys_errlist[ errno ], 0 );
-           pthread_mutex_unlock( &sglob->rej_mutex );
+#endif
+           ldap_pvt_thread_mutex_unlock( &sglob->rej_mutex );
            return;
        } else {
            close( rjfd );
        }
     }
     if (( rc = acquire_lock( rejfile, &rfp, &lfp )) < 0 ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "write_reject: "
+               "Error: Cannot open reject file \"%s\"\n", rejfile, 0, 0 );
+#else
        Debug( LDAP_DEBUG_ANY, "Error: cannot open reject file \"%s\"\n",
                rejfile, 0, 0 );
+#endif
     } else {
        fseek( rfp, 0, 2 );
        if ( errmsg != NULL ) {
@@ -83,16 +102,27 @@ write_reject(
            fprintf( rfp, "%s: %s\n", ERROR_STR, ldap_err2string( lderr ));
        }
        if ((rc = re->re_write( ri, re, rfp )) < 0 ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG ( SLURPD, ERR, "write_reject: "
+                       "Error: Cannot write reject file \"%s\"\n", rejfile, 0, 0 );
+#else
            Debug( LDAP_DEBUG_ANY,
                    "Error: cannot write reject file \"%s\"\n",
                    rejfile, 0, 0 );
+#endif
        }
        (void) relinquish_lock( rejfile, rfp, lfp );
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "write_reject: "
+               "Error: ldap operation failed, data written to \"%s\"\n", 
+               rejfile, 0, 0 );
+#else
        Debug( LDAP_DEBUG_ANY,
                "Error: ldap operation failed, data written to \"%s\"\n",
                rejfile, 0, 0 );
+#endif
     }
-    pthread_mutex_unlock( &sglob->rej_mutex );
+    ldap_pvt_thread_mutex_unlock( &sglob->rej_mutex );
     return;
 }