mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-12 10:54:48 +08:00
4e51bba217
================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ A surrogate parent is supposed to keep back-shell children from deadlocking due to resources locked by a threading parent. Implementation note: The surrogate parent closes all unused file descriptors, so it logs errors to stderr instead of via Debug() and uses relloc() instead of ch_realloc(). Also close a file descriptor leak if fork() fails in fork.c. Hallvard B. Furuseth <h.b.furuseth@usit.uio.no>, May 2002.
79 lines
1.7 KiB
C
79 lines
1.7 KiB
C
/* abandon.c - shell backend abandon function */
|
|
/* $OpenLDAP$ */
|
|
/*
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
*/
|
|
|
|
#include "portable.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/socket.h>
|
|
#include <ac/string.h>
|
|
|
|
#include "slap.h"
|
|
#include "shell.h"
|
|
|
|
int
|
|
shell_back_abandon(
|
|
Backend *be,
|
|
Connection *conn,
|
|
Operation *op,
|
|
int msgid
|
|
)
|
|
{
|
|
struct shellinfo *si = (struct shellinfo *) be->be_private;
|
|
FILE *rfp, *wfp;
|
|
pid_t pid;
|
|
Operation *o;
|
|
|
|
/* no abandon command defined - just kill the process handling it */
|
|
if ( IS_NULLCMD( si->si_abandon ) ) {
|
|
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
|
|
pid = -1;
|
|
LDAP_STAILQ_FOREACH( o, &conn->c_ops, o_next ) {
|
|
if ( o->o_msgid == msgid ) {
|
|
pid = (pid_t) o->o_private;
|
|
break;
|
|
}
|
|
}
|
|
if( pid == -1 ) {
|
|
LDAP_STAILQ_FOREACH( o, &conn->c_pending_ops, o_next ) {
|
|
if ( o->o_msgid == msgid ) {
|
|
pid = (pid_t) o->o_private;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
|
|
|
|
if ( pid != -1 ) {
|
|
Debug( LDAP_DEBUG_ARGS, "shell killing pid %d\n",
|
|
(int) pid, 0, 0 );
|
|
kill( pid, SIGTERM );
|
|
} else {
|
|
Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n",
|
|
msgid, 0, 0 );
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
|
|
return 0;
|
|
}
|
|
|
|
/* write out the request to the abandon process */
|
|
fprintf( wfp, "ABANDON\n" );
|
|
fprintf( wfp, "opid: %ld/%ld\n", op->o_connid, (long) op->o_msgid );
|
|
fprintf( wfp, "msgid: %d\n", msgid );
|
|
print_suffixes( wfp, be );
|
|
fprintf( wfp, "abandonid: %ld/%d\n", op->o_connid, msgid );
|
|
fclose( wfp );
|
|
|
|
/* no result from abandon */
|
|
fclose( rfp );
|
|
|
|
return 0;
|
|
}
|