X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fslapcat.c;h=6ea1952006502541080756408981bf00ea2f8039;hb=3bf9998d7885ef6bbc4690d4229e5cb5068a35de;hp=3e4d7ae12b0f0c61ddebfce96a1ce5ee51ccbb81;hpb=c225c4af34700c6a5be880ae8eeaf67fede803fb;p=openldap diff --git a/servers/slapd/slapcat.c b/servers/slapd/slapcat.c index 3e4d7ae12b..6ea1952006 100644 --- a/servers/slapd/slapcat.c +++ b/servers/slapd/slapcat.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2005 The OpenLDAP Foundation. + * Copyright 1998-2008 The OpenLDAP Foundation. * Portions Copyright 1998-2003 Kurt D. Zeilenga. * Portions Copyright 2003 IBM Corporation. * All rights reserved. @@ -32,6 +32,14 @@ #include "slapcommon.h" #include "ldif.h" +static volatile sig_atomic_t gotsig; + +static RETSIGTYPE +slapcat_sig( int sig ) +{ + gotsig=1; +} + int slapcat( int argc, char **argv ) { @@ -42,6 +50,15 @@ slapcat( int argc, char **argv ) slap_tool_init( progname, SLAPCAT, argc, argv ); +#ifdef SIGPIPE + (void) SIGNAL( SIGPIPE, slapcat_sig ); +#endif +#ifdef SIGHUP + (void) SIGNAL( SIGHUP, slapcat_sig ); +#endif + (void) SIGNAL( SIGINT, slapcat_sig ); + (void) SIGNAL( SIGTERM, slapcat_sig ); + if( !be->be_entry_open || !be->be_entry_close || !be->be_entry_first || @@ -59,15 +76,19 @@ slapcat( int argc, char **argv ) exit( EXIT_FAILURE ); } + op.o_bd = be; for ( id = be->be_entry_first( be ); id != NOID; id = be->be_entry_next( be ) ) { char *data; int len; - Entry* e = be->be_entry_get( be, id ); - op.o_bd = be; + Entry* e; + if ( gotsig ) + break; + + e = be->be_entry_get( be, id ); if ( e == NULL ) { printf("# no data for entry id=%08lx\n\n", (long) id ); rc = EXIT_FAILURE; @@ -102,8 +123,13 @@ slapcat( int argc, char **argv ) break; } - fputs( data, ldiffp->fp ); - fputs( "\n", ldiffp->fp ); + if ( fputs( data, ldiffp->fp ) == EOF || + fputs( "\n", ldiffp->fp ) == EOF ) { + fprintf(stderr, "%s: error writing output.\n", + progname); + rc = EXIT_FAILURE; + break; + } } be->be_entry_close( be );