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