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