]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/abandon.c
Import cache_delete_entry_internal/dntree&idtree delete fix from -devel.
[openldap] / servers / slapd / back-shell / abandon.c
1 /* abandon.c - shell backend abandon function */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <signal.h>
8 #include "slap.h"
9 #include "shell.h"
10
11 void
12 shell_back_abandon(
13     Backend     *be,
14     Connection  *conn,
15     Operation   *op,
16     int         msgid
17 )
18 {
19         struct shellinfo        *si = (struct shellinfo *) be->be_private;
20         FILE                    *rfp, *wfp;
21         int                     pid;
22         Operation               *o;
23
24         /* no abandon command defined - just kill the process handling it */
25         if ( si->si_abandon == NULL ) {
26                 pthread_mutex_lock( &conn->c_opsmutex );
27                 pid = -1;
28                 for ( o = conn->c_ops; o != NULL; o = o->o_next ) {
29                         if ( o->o_msgid == msgid ) {
30                                 pid = o->o_private;
31                                 break;
32                         }
33                 }
34                 pthread_mutex_unlock( &conn->c_opsmutex );
35
36                 if ( pid != -1 ) {
37                         Debug( LDAP_DEBUG_ARGS, "shell killing pid %d\n", pid,
38                             0, 0 );
39                         kill( pid, SIGTERM );
40                 } else {
41                         Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n",
42                             msgid, 0, 0 );
43                 }
44                 return;
45         }
46
47         if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
48                 return;
49         }
50
51         /* write out the request to the abandon process */
52         fprintf( wfp, "ABANDON\n" );
53         fprintf( wfp, "msgid: %d\n", msgid );
54         print_suffixes( wfp, be );
55         fclose( wfp );
56
57         /* no result from abandon */
58         fclose( rfp );
59 }