From 8fe7576158da0174e3c50b916964730cb2f5d46a Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 10 Jun 2005 20:14:32 +0000 Subject: [PATCH] ITS#3764 add signal handlers so slapcat will cleanup if interrupted. (Just slapcat for now, other tools don't seem to be critical.) --- servers/slapd/slapcat.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/servers/slapd/slapcat.c b/servers/slapd/slapcat.c index 3e4d7ae12b..a87c8eb325 100644 --- a/servers/slapd/slapcat.c +++ b/servers/slapd/slapcat.c @@ -32,6 +32,14 @@ #include "slapcommon.h" #include "ldif.h" +static int 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; -- 2.39.5