]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/replog.c
Converted ch_malloc and ch_calloc calls to SLAP_MALLOC and SLAP_CALLOC.
[openldap] / servers / slurpd / replog.c
index 5573215cc52e9c7b38aeb4d63296c0e52ca26ab8..471275a6dfc11b0d4aeaf5be36407427ce08362d 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1996 Regents of the University of Michigan.
  * All rights reserved.
 
 #include <stdio.h>
 
+#include <ac/stdlib.h>
 #include <ac/errno.h>
+#include <ac/param.h>
 #include <ac/string.h>
 #include <ac/syslog.h>
 #include <ac/time.h>
 #include <ac/unistd.h>
 
 #include <sys/stat.h>
-#include <sys/param.h>
+
 #include <fcntl.h>
 
 #include "slurp.h"
 #include "globals.h"
 
-/*
- * Externs
- */
-extern FILE *lock_fopen LDAP_P(( char *, char *, FILE ** ));
-extern char *ch_malloc LDAP_P(( unsigned long ));
-
-/*
- * Forward declarations
- */
-int file_nonempty LDAP_P(( char * ));
-
-
-/*
- * Forward declarations
- */
-static int duplicate_replog( char *, char * );
-
-
 /*
  * Copy the replication log.  Returns 0 on success, 1 if a temporary
  * error occurs, and -1 if a fatal error occurs.
@@ -69,62 +58,91 @@ copy_replog(
     static char        rbuf[ 1024 ];
     char       *p;
 
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ARGS, "copy_replog: "
+               "copy replog \"%s\" to \"%s\"\n", src, dst, 0 );
+#else
     Debug( LDAP_DEBUG_ARGS,
            "copy replog \"%s\" to \"%s\"\n", 
            src, dst, 0 );
+#endif
 
     /*
      * Make sure the destination directory is writable.  If not, exit
      * with a fatal error.
      */
     strcpy( buf, src );
-    if (( p = strrchr( buf, '/' )) == NULL ) {
+    if (( p = strrchr( buf, LDAP_DIRSEP[0] )) == NULL ) {
        strcpy( buf, "." );
     } else {
        *p = '\0';
     }
     if ( access( buf, W_OK ) < 0 ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "copy_replog: "
+               "Error: (%ld): Directory %s is not writable\n",
+               (long) getpid(), buf, 0 );
+#else
        Debug( LDAP_DEBUG_ANY,
-               "Error: copy_replog (%d): Directory %s is not writable\n",
-               getpid(), buf, 0 );
+               "Error: copy_replog (%ld): Directory %s is not writable\n",
+               (long) getpid(), buf, 0 );
+#endif
        return( -1 );
     }
     strcpy( buf, dst );
-    if (( p = strrchr( buf, '/' )) == NULL ) {
+    if (( p = strrchr( buf, LDAP_DIRSEP[0] )) == NULL ) {
        strcpy( buf, "." );
     } else {
        *p = '\0';
     }
     if ( access( buf, W_OK ) < 0 ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "copy_replog: "
+               "Error: (%ld): Directory %s is not writable\n",
+               (long) getpid(), buf, 0 );
+#else
        Debug( LDAP_DEBUG_ANY,
-               "Error: copy_replog (%d): Directory %s is not writable\n",
-               getpid(), buf, 0 );
+               "Error: copy_replog (%ld): Directory %s is not writable\n",
+               (long) getpid(), buf, 0 );
+#endif
        return( -1 );
     }
 
     /* lock src */
     rfp = lock_fopen( src, "r", &lfp );
     if ( rfp == NULL ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "copy_replog: "
+               "Error: Can't lock replog \"%s\" for read: %s\n",
+               src, sys_errlist[ errno ], 0 );
+#else
        Debug( LDAP_DEBUG_ANY,
                "Error: copy_replog: Can't lock replog \"%s\" for read: %s\n",
                src, sys_errlist[ errno ], 0 );
+#endif
        return( 1 );
     }
 
     /* lock dst */
     dfp = lock_fopen( dst, "a", &dlfp );
     if ( dfp == NULL ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "copy_replog: "
+               "Error: Can't lock replog \"%s\" for write: %s\n",
+               src, sys_errlist[ errno ], 0 );
+#else
        Debug( LDAP_DEBUG_ANY,
                "Error: copy_replog: Can't lock replog \"%s\" for write: %s\n",
                src, sys_errlist[ errno ], 0 );
-       lock_fclose( rfp );
+#endif
+       lock_fclose( rfp, lfp );
        return( 1 );
     }
 
     /*
      * Make our own private copy of the replication log.
      */
-    while (( p = fgets( rbuf, sizeof( buf ), rfp )) != NULL ) {
+    while (( p = fgets( rbuf, sizeof( rbuf ), rfp )) != NULL ) {
        fputs( rbuf, dfp );
     }
     /* Only truncate the source file if we're not in one-shot mode */
@@ -133,15 +151,25 @@ copy_replog(
        truncate( src, (off_t) 0 );
     }
 
-    if ( lock_fclose( rfp, lfp ) == EOF ) {
+    if ( lock_fclose( dfp, dlfp ) == EOF ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "copy_replog: "
+               "Error: Error closing \"%s\"\n", src, 0, 0 );
+#else
        Debug( LDAP_DEBUG_ANY,
                "Error: copy_replog: Error closing \"%s\"\n",
                src, 0, 0 );
+#endif
     }
-    if ( lock_fclose( dfp, dlfp ) == EOF ) {
+    if ( lock_fclose( rfp, lfp ) == EOF ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG ( SLURPD, ERR, "copy_replog: "
+               "Error: Error closing \"%s\"\n", src, 0, 0 );
+#else
        Debug( LDAP_DEBUG_ANY,
                "Error: copy_replog: Error closing \"%s\"\n",
                src, 0, 0 );
+#endif
     }
     return( rc );
 }