]> git.sur5r.net Git - openldap/blob - servers/slurpd/replica.c
Suck in latest changes from HEAD
[openldap] / servers / slurpd / replica.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright (c) 1996 Regents of the University of Michigan.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * provided that this notice is preserved and that due credit is given
12  * to the University of Michigan at Ann Arbor. The name of the University
13  * may not be used to endorse or promote products derived from this
14  * software without specific prior written permission. This software
15  * is provided ``as is'' without express or implied warranty.
16  */
17
18
19 /*
20  * replica.c - code to start up replica threads.
21  */
22
23 #include "portable.h"
24
25 #include <stdio.h>
26 #include <ac/stdlib.h>
27
28 #include "slurp.h"
29 #include "globals.h"
30
31
32 /*
33  * Just invoke the Ri's process() member function, and log the start and
34  * finish.
35  */
36 static void *
37 replicate(
38     void        *ri_arg
39 )
40 {
41     Ri          *ri = (Ri *) ri_arg;
42
43 #ifdef NEW_LOGGING
44         LDAP_LOG (( "replica", LDAP_LEVEL_ARGS, "replicate: "
45                 "begin replication thread for %s:%d\n",
46             ((Ri *)ri)->ri_hostname, ((Ri *)ri)->ri_port ));
47 #else
48     Debug( LDAP_DEBUG_ARGS, "begin replication thread for %s:%d\n",
49             ((Ri *)ri)->ri_hostname, ((Ri *)ri)->ri_port, 0 );
50 #endif
51
52     ri->ri_process( ri );
53
54 #ifdef NEW_LOGGING
55         LDAP_LOG (( "replica", LDAP_LEVEL_ARGS, "replicate: "
56                 "begin replication thread for %s:%d\n",
57             ri->ri_hostname, ri->ri_port ));
58 #else
59     Debug( LDAP_DEBUG_ARGS, "end replication thread for %s:%d\n",
60             ri->ri_hostname, ri->ri_port, 0 );
61 #endif
62     return NULL;
63 }
64
65
66
67 /*
68  * Start a detached thread for the given replica.
69  */
70 int
71 start_replica_thread(
72     Ri  *ri
73 )
74 {
75     /* POSIX_THREADS or compatible */
76     if ( ldap_pvt_thread_create( &(ri->ri_tid), 0, replicate,
77             (void *) ri ) != 0 ) {
78 #ifdef NEW_LOGGING
79         LDAP_LOG (( "replica", LDAP_LEVEL_ERR, "start_replica_thread: "
80                 "replica %s:%d ldap_pvt_thread_create failed\n",
81             ri->ri_hostname, ri->ri_port ));
82 #else
83         Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" ldap_pvt_thread_create failed\n",
84                 ri->ri_hostname, ri->ri_port, 0 );
85 #endif
86         return -1;
87     }
88
89     return 0;
90 }