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