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