]> git.sur5r.net Git - openldap/blob - servers/slurpd/replica.c
ITS#2970 fix build_new_dn for zero-length parent DN
[openldap] / servers / slurpd / replica.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2004 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* Portions Copyright (c) 1996 Regents of the University of Michigan.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * provided that this notice is preserved and that due credit is given
20  * to the University of Michigan at Ann Arbor. The name of the University
21  * may not be used to endorse or promote products derived from this
22  * software without specific prior written permission. This software
23  * is provided ``as is'' without express or implied warranty.
24  */
25 /* ACKNOWLEDGEMENTS:
26  * This work was originally developed by the University of Michigan
27  * (as part of U-MICH LDAP).
28  */
29
30
31 /*
32  * replica.c - code to start up replica threads.
33  */
34
35 #include "portable.h"
36
37 #include <stdio.h>
38 #include <ac/stdlib.h>
39
40 #include "slurp.h"
41 #include "globals.h"
42
43 /*
44  * Just invoke the Ri's process() member function, and log the start and
45  * finish.
46  */
47 static void *
48 replicate(
49     void        *ri_arg
50 )
51 {
52     Ri          *ri = (Ri *) ri_arg;
53
54 #ifdef NEW_LOGGING
55         LDAP_LOG ( SLURPD, ARGS, "replicate: "
56                 "begin replication thread for %s:%d\n",
57             ((Ri *)ri)->ri_hostname, ((Ri *)ri)->ri_port, 0 );
58 #else
59     Debug( LDAP_DEBUG_ARGS, "begin replication thread for %s:%d\n",
60             ((Ri *)ri)->ri_hostname, ((Ri *)ri)->ri_port, 0 );
61 #endif
62
63     ri->ri_process( ri );
64
65 #ifdef NEW_LOGGING
66         LDAP_LOG ( SLURPD, ARGS, "replicate: "
67                 "begin replication thread for %s:%d\n",
68             ri->ri_hostname, ri->ri_port, 0 );
69 #else
70     Debug( LDAP_DEBUG_ARGS, "end replication thread for %s:%d\n",
71             ri->ri_hostname, ri->ri_port, 0 );
72 #endif
73     return NULL;
74 }
75
76
77
78 /*
79  * Start a detached thread for the given replica.
80  */
81 int
82 start_replica_thread(
83     Ri  *ri
84 )
85 {
86     /* POSIX_THREADS or compatible */
87     if ( ldap_pvt_thread_create( &(ri->ri_tid), 0, replicate,
88             (void *) ri ) != 0 ) {
89 #ifdef NEW_LOGGING
90         LDAP_LOG ( SLURPD, ERR, "start_replica_thread: "
91                 "replica %s:%d ldap_pvt_thread_create failed\n",
92             ri->ri_hostname, ri->ri_port, 0 );
93 #else
94         Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" ldap_pvt_thread_create failed\n",
95                 ri->ri_hostname, ri->ri_port, 0 );
96 #endif
97         return -1;
98     }
99
100     return 0;
101 }