]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/abandon.c
Fixup bdb_entry_release now that entry_decode uses two memory blocks
[openldap] / servers / slapd / back-shell / abandon.c
1 /* abandon.c - shell backend abandon function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/signal.h>
13 #include <ac/socket.h>
14 #include <ac/string.h>
15
16 #include "slap.h"
17 #include "shell.h"
18
19 int
20 shell_back_abandon(
21     Backend     *be,
22     Connection  *conn,
23     Operation   *op,
24     int         msgid
25 )
26 {
27         struct shellinfo        *si = (struct shellinfo *) be->be_private;
28         FILE                    *rfp, *wfp;
29         pid_t                   pid;
30         Operation               *o;
31
32         /* no abandon command defined - just kill the process handling it */
33         if ( si->si_abandon == NULL ) {
34                 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
35                 pid = -1;
36                 for ( o = conn->c_ops; o != NULL; o = o->o_next ) {
37                         if ( o->o_msgid == msgid ) {
38                                 pid = (pid_t) o->o_private;
39                                 break;
40                         }
41                 }
42                 if( pid == -1 ) {
43                         for ( o = conn->c_pending_ops; o != NULL; o = o->o_next ) {
44                                 if ( o->o_msgid == msgid ) {
45                                         pid = (pid_t) o->o_private;
46                                         break;
47                                 }
48                         }
49                 }
50                 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
51
52                 if ( pid != -1 ) {
53                         Debug( LDAP_DEBUG_ARGS, "shell killing pid %d\n",
54                                (int) pid, 0, 0 );
55                         kill( pid, SIGTERM );
56                 } else {
57                         Debug( LDAP_DEBUG_ARGS, "shell could not find op %d\n",
58                             msgid, 0, 0 );
59                 }
60                 return 0;
61         }
62
63         if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
64                 return 0;
65         }
66
67         /* write out the request to the abandon process */
68         fprintf( wfp, "ABANDON\n" );
69         fprintf( wfp, "msgid: %d\n", msgid );
70         print_suffixes( wfp, be );
71         fclose( wfp );
72
73         /* no result from abandon */
74         fclose( rfp );
75
76         return 0;
77 }