]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/abandon.c
fixes
[openldap] / servers / slapd / back-shell / abandon.c
1 /* abandon.c - shell backend abandon function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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     Operation   *op,
21     SlapReply   *rs )
22 {
23         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
24         FILE                    *rfp, *wfp;
25         pid_t                   pid;
26         Operation               *o;
27
28         if ( si->si_abandon == NULL ) {
29                 return 0;
30         }
31
32         pid = -1;
33         LDAP_STAILQ_FOREACH( o, &op->o_conn->c_ops, o_next ) {
34                 if ( o->o_msgid == op->oq_abandon.rs_msgid ) {
35                         pid = (pid_t) o->o_private;
36                         break;
37                 }
38         }
39
40         if ( pid == -1 ) {
41                 Debug( LDAP_DEBUG_ARGS, "shell could not find op %ld\n",
42                        (long) op->oq_abandon.rs_msgid, 0, 0 );
43                 return 0;
44         }
45
46         if ( forkandexec( si->si_abandon, &rfp, &wfp ) == -1 ) {
47                 return 0;
48         }
49
50         /* write out the request to the abandon process */
51         fprintf( wfp, "ABANDON\n" );
52         fprintf( wfp, "msgid: %d\n", op->oq_abandon.rs_msgid );
53         print_suffixes( wfp, op->o_bd );
54         fprintf( wfp, "pid: %ld\n", (long) pid );
55         fclose( wfp );
56
57         /* no result from abandon */
58         fclose( rfp );
59
60         return 0;
61 }