summaryrefslogtreecommitdiffstats
path: root/ldap/servers/plugins/replication/cl5_init.c
blob: 435299c09ace7e8dc31ffba1bf39a85bcea75bc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/** BEGIN COPYRIGHT BLOCK
 * Copyright 2001 Sun Microsystems, Inc.
 * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/

/* cl5_init.c - implments initialization/cleanup functions for 
                4.0 style changelog
 */

#include "slapi-plugin.h"
#include "cl5.h"
#include "repl5.h"

/* initializes changelog*/
int changelog5_init()
{
	int rc;
	changelog5Config config;

	rc = cl5Init ();
	if (rc != CL5_SUCCESS)
	{
		slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl, 
						"changelog5_init: failed to initialize changelog\n");
		return 1;
	}

	/* read changelog configuration */
	changelog5_config_init ();
	changelog5_read_config (&config);

	if (config.dir == NULL)
	{
		/* changelog is not configured - bail out */
		rc = 0; /* OK */
        goto done;
	}

	/* start changelog */
	rc = cl5Open (config.dir, &config.dbconfig);
	if (rc != CL5_SUCCESS)
	{
		slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl, 
					"changelog5_init: failed to start changelog at %s\n", 
					config.dir);
		rc = 1;
        goto done;
	}	

	/* set trimming parameters */
	rc = cl5ConfigTrimming (config.maxEntries, config.maxAge);
	if (rc != CL5_SUCCESS)
	{
		slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name_cl, 
						"changelog5_init: failed to configure changelog trimming\n");
		rc = 1;
        goto done;
	}

	rc = 0;

done:
    changelog5_config_done (&config);
    return rc;
}

/* cleanups changelog data */
void changelog5_cleanup()
{
	/* close changelog */
	cl5Close ();
	cl5Cleanup ();

	/* cleanup config */
	changelog5_config_cleanup ();
}