X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=servers%2Fslurpd%2Fst.c;h=c99a4868f5372fff055db9bf1205094be0b94047;hb=62da0b6738e9329e2715699b7ac9556575ba83f1;hp=fed678b88de87db306542436427afa048baf6f84;hpb=72ba4cfb715001d30a6e48a2d7012f060f29d684;p=openldap diff --git a/servers/slurpd/st.c b/servers/slurpd/st.c index fed678b88d..c99a4868f5 100644 --- a/servers/slurpd/st.c +++ b/servers/slurpd/st.c @@ -1,5 +1,18 @@ -/* - * Copyright (c) 1996 Regents of the University of Michigan. +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2004 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* Portions Copyright (c) 1996 Regents of the University of Michigan. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -9,6 +22,10 @@ * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by the University of Michigan + * (as part of U-MICH LDAP). + */ /* @@ -19,7 +36,8 @@ #include "portable.h" #include -#include + +#include #include #include @@ -61,7 +79,7 @@ St_add( 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; ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); @@ -91,9 +109,15 @@ St_write ( 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; ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return -1; @@ -108,8 +132,9 @@ 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 ); @@ -136,7 +161,7 @@ St_update( } ldap_pvt_thread_mutex_lock( &(st->st_mutex )); - strcpy( stel->last, re->re_timestamp ); + stel->last = re->re_timestamp; stel->seq = re->re_seq; ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return 0; @@ -170,15 +195,26 @@ St_read( * 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 ); +#endif ldap_pvt_thread_mutex_unlock( &(st->st_mutex )); return -1; } (void) fclose( fp ); 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 ) { @@ -214,7 +250,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; } @@ -223,12 +259,23 @@ 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);