]> git.sur5r.net Git - openldap/blob - servers/slurpd/replica.c
Sync with HEAD
[openldap] / servers / slurpd / replica.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2005 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     Debug( LDAP_DEBUG_ARGS, "begin replication thread for %s:%d\n",
55             ((Ri *)ri)->ri_hostname, ((Ri *)ri)->ri_port, 0 );
56
57     ri->ri_process( ri );
58
59     Debug( LDAP_DEBUG_ARGS, "end replication thread for %s:%d\n",
60             ri->ri_hostname, ri->ri_port, 0 );
61     return NULL;
62 }
63
64
65
66 /*
67  * Start a detached thread for the given replica.
68  */
69 int
70 start_replica_thread(
71     Ri  *ri
72 )
73 {
74     /* POSIX_THREADS or compatible */
75     if ( ldap_pvt_thread_create( &(ri->ri_tid), 0, replicate,
76             (void *) ri ) != 0 ) {
77         Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" ldap_pvt_thread_create failed\n",
78                 ri->ri_hostname, ri->ri_port, 0 );
79         return -1;
80     }
81
82     return 0;
83 }