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