X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Fst.c;h=e2a00299b6ea444204a39ce7557b840f4ab5b6e4;hb=7c41666c5e92beb301c10b9a71f45834255dcc21;hp=d18f5381fd2bb9fefeedbbf2d8c7d0a84ba1b810;hpb=2a869f5a99f537b246ba8640502e2a86117cb6e8;p=openldap diff --git a/servers/slurpd/st.c b/servers/slurpd/st.c index d18f5381fd..e2a00299b6 100644 --- a/servers/slurpd/st.c +++ b/servers/slurpd/st.c @@ -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. @@ -19,6 +24,8 @@ #include "portable.h" #include + +#include #include #include @@ -42,28 +49,28 @@ St_add( } /* Serialize access to the St struct */ - pthread_mutex_lock( &(st->st_mutex )); + ldap_pvt_thread_mutex_lock( &(st->st_mutex )); st->st_nreplicas++; ind = st->st_nreplicas - 1; st->st_data = ( Stel ** ) ch_realloc( st->st_data, ( st->st_nreplicas * sizeof( Stel * ))); if ( st->st_data == NULL ) { - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return NULL; } st->st_data[ ind ] = ( Stel * ) ch_malloc( sizeof( Stel ) ); if ( st->st_data[ ind ] == NULL ) { - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return NULL; } st->st_data[ ind ]->hostname = strdup( ri->ri_hostname ); st->st_data[ ind ]->port = ri->ri_port; - memset( st->st_data[ ind ]->last, 0, sizeof( st->st_data[ ind ]->last )); + st->st_data[ ind ]->last = 0; st->st_data[ ind ]->seq = 0; - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return st->st_data[ ind ]; } @@ -84,17 +91,23 @@ St_write ( if ( st == NULL ) { return -1; } - pthread_mutex_lock( &(st->st_mutex )); + ldap_pvt_thread_mutex_lock( &(st->st_mutex )); if ( st->st_fp == NULL ) { /* Open file */ if (( rc = acquire_lock( sglob->slurpd_status_file, &(st->st_fp), &(st->st_lfp))) < 0 ) { if ( !st->st_err_logged ) { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, "St_write: " + "Error: cannot open status file \"%s\":%s\n", + sglob->slurpd_status_file, sys_errlist[ errno ], 0 ); +#else Debug( LDAP_DEBUG_ANY, "Error: cannot open status file \"%s\": %s\n", sglob->slurpd_status_file, sys_errlist[ errno ], 0 ); +#endif st->st_err_logged = 1; - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return -1; } } else { @@ -107,12 +120,13 @@ St_write ( fseek( st->st_fp, 0L, 0 ); for ( i = 0; i < st->st_nreplicas; i++ ) { stel = st->st_data[ i ]; - fprintf( st->st_fp, "%s:%d:%s:%d\n", stel->hostname, stel->port, - stel->last, stel->seq ); + fprintf( st->st_fp, "%s:%d:%ld:%d\n", + stel->hostname, stel->port, + (long) stel->last, stel->seq ); } fflush( st->st_fp ); - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return 0; } @@ -134,10 +148,10 @@ St_update( return -1; } - pthread_mutex_lock( &(st->st_mutex )); - strcpy( stel->last, re->re_timestamp ); + ldap_pvt_thread_mutex_lock( &(st->st_mutex )); + stel->last = re->re_timestamp; stel->seq = re->re_seq; - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return 0; } @@ -163,24 +177,36 @@ St_read( if ( st == NULL ) { return -1; } - pthread_mutex_lock( &(st->st_mutex )); + ldap_pvt_thread_mutex_lock( &(st->st_mutex )); if ( access( sglob->slurpd_status_file, F_OK ) < 0 ) { /* * File doesn't exist, so create it and return. */ if (( fp = fopen( sglob->slurpd_status_file, "w" )) == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, "St_write: " + "Error: cannot create status file \"%s\"\n", + sglob->slurpd_status_file, 0, 0 ); +#else Debug( LDAP_DEBUG_ANY, "Error: cannot create status file \"%s\"\n", sglob->slurpd_status_file, 0, 0 ); - pthread_mutex_unlock( &(st->st_mutex )); +#endif + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return -1; } (void) fclose( fp ); - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, DETAIL1, "St_write: " + "No status file found, defaulting values\n", 0, 0, 0 ); +#else Debug( LDAP_DEBUG_ARGS, "No status file found, defaulting values\n", 0, 0, 0 ); +#endif return 0; } if (( rc = acquire_lock( sglob->slurpd_status_file, &fp, &lfp)) < 0 ) { + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return 0; } while ( fgets( buf, sizeof( buf ), fp ) != NULL ) { @@ -212,7 +238,7 @@ St_read( if ( !strcmp( hostname, sglob->st->st_data[ i ]->hostname ) && atoi( port ) == sglob->st->st_data[ i ]->port ) { found = 1; - strcpy( sglob->st->st_data[ i ]->last, timestamp ); + sglob->st->st_data[ i ]->last = atol( timestamp ); sglob->st->st_data[ i ]->seq = atoi( seq ); break; } @@ -221,21 +247,32 @@ St_read( char tbuf[ 255 ]; sprintf( tbuf, "%s:%s (timestamp %s.%s)", hostname, port, timestamp, seq ); +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, DETAIL1, "St_write: " + "Retrieved state information for %s\n", tbuf, 0, 0 ); +#else Debug( LDAP_DEBUG_ARGS, "Retrieved state information for %s\n", tbuf, 0, 0 ); +#endif } else { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, WARNING, "St_write: " + "Warning: saved state for %s:%s, not a known replica\n", + hostname, port, 0 ); +#else Debug( LDAP_DEBUG_ANY, "Warning: saved state for %s:%s, not a known replica\n", hostname, port, 0 ); +#endif } } (void) relinquish_lock( sglob->slurpd_status_file, fp, lfp); - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return 0; bad: (void) relinquish_lock( sglob->slurpd_status_file, fp, lfp); - pthread_mutex_unlock( &(st->st_mutex )); + ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return -1; } @@ -250,7 +287,7 @@ St_lock( St *st ) { - return( pthread_mutex_lock( &st->st_mutex )); + return( ldap_pvt_thread_mutex_lock( &st->st_mutex )); } @@ -264,7 +301,7 @@ St_unlock( St *st ) { - return( pthread_mutex_unlock( &st->st_mutex )); + return( ldap_pvt_thread_mutex_unlock( &st->st_mutex )); } @@ -287,7 +324,7 @@ St_init( return -1; } - pthread_mutex_init( &((*st)->st_mutex), pthread_mutexattr_default ); + ldap_pvt_thread_mutex_init( &((*st)->st_mutex) ); (*st)->st_data = NULL; (*st)->st_fp = NULL; (*st)->st_lfp = NULL;