]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/abandon.c
updates from HEAD
[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                 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
42         }
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         if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
50                 return 0;
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         fprintf( wfp, "pid: %ld\n", (long) pid );
58         fclose( wfp );
59
60         /* no result from abandon */
61         fclose( rfp );
62
63         return 0;
64 }