1998-08-09 08:43:13 +08:00
|
|
|
/* abandon.c - shell backend abandon function */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2000-05-16 00:35:48 +08:00
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
2000-05-16 00:35:48 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/signal.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "shell.h"
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
int
|
1998-08-09 08:43:13 +08:00
|
|
|
shell_back_abandon(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
int msgid
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct shellinfo *si = (struct shellinfo *) be->be_private;
|
|
|
|
FILE *rfp, *wfp;
|
1999-01-26 12:32:26 +08:00
|
|
|
pid_t pid;
|
1998-08-09 08:43:13 +08:00
|
|
|
Operation *o;
|
|
|
|
|
|
|
|
/* no abandon command defined - just kill the process handling it */
|
|
|
|
if ( si->si_abandon == NULL ) {
|
1999-03-22 15:38:27 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
pid = -1;
|
2002-01-03 08:12:46 +08:00
|
|
|
LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( o->o_msgid == msgid ) {
|
1999-01-26 12:32:26 +08:00
|
|
|
pid = (pid_t) o->o_private;
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-03-22 15:38:27 +08:00
|
|
|
if( pid == -1 ) {
|
2002-01-03 08:12:46 +08:00
|
|
|
LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) {
|
1999-03-22 15:38:27 +08:00
|
|
|
if ( o->o_msgid == msgid ) {
|
|
|
|
pid = (pid_t) o->o_private;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( pid != -1 ) {
|
1999-09-02 16:11:54 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "shell killing pid %d\n",
|
|
|
|
(int) pid, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
kill( pid, SIGTERM );
|
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n",
|
|
|
|
msgid, 0, 0 );
|
|
|
|
}
|
1999-02-05 17:03:47 +08:00
|
|
|
return 0;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
|
1999-02-05 17:03:47 +08:00
|
|
|
return 0;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write out the request to the abandon process */
|
|
|
|
fprintf( wfp, "ABANDON\n" );
|
|
|
|
fprintf( wfp, "msgid: %d\n", msgid );
|
|
|
|
print_suffixes( wfp, be );
|
|
|
|
fclose( wfp );
|
|
|
|
|
|
|
|
/* no result from abandon */
|
|
|
|
fclose( rfp );
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
return 0;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|