summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-04-29 17:37:35 +0200
committerMichael Adam <obnox@samba.org>2008-04-30 12:42:32 +0200
commit9fe870affa2b19aeee8f45f05cc1407d448c3bf7 (patch)
treee90a68a0e2f96e9a446fa3448c46317e9095cc64 /source3/registry
parented6a9edb1ef129f82aa7841dd18151da28b7ce6d (diff)
downloadsamba-9fe870affa2b19aeee8f45f05cc1407d448c3bf7.tar.gz
samba-9fe870affa2b19aeee8f45f05cc1407d448c3bf7.tar.bz2
samba-9fe870affa2b19aeee8f45f05cc1407d448c3bf7.zip
registry: save writes in init_registry_data() if data does already exist.
This is done by first checking if all data (keys and values) exists (using new regdb_key_exists()) and kompletely skipping all writes if it does. Michael (This used to be commit 7c5f1583cb43d473544f161aa9c864e1d78944e5)
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_backend_db.c55
1 files changed, 43 insertions, 12 deletions
diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index e10cfb520b..81f5edcb7b 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -237,12 +237,45 @@ fail:
WERROR init_registry_data(void)
{
WERROR werr;
- TALLOC_CTX *frame = NULL;
+ TALLOC_CTX *frame = talloc_stackframe();
REGVAL_CTR *values;
int i;
UNISTR2 data;
/*
+ * First, check for the existence of the needed keys and values.
+ * If all do already exist, we can save the writes.
+ */
+ for (i=0; builtin_registry_paths[i] != NULL; i++) {
+ if (!regdb_key_exists(builtin_registry_paths[i])) {
+ goto do_init;
+ }
+ }
+
+ for (i=0; builtin_registry_values[i].path != NULL; i++) {
+ values = TALLOC_ZERO_P(frame, REGVAL_CTR);
+ if (values == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+
+ regdb_fetch_values(builtin_registry_values[i].path, values);
+ if (!regval_ctr_key_exists(values,
+ builtin_registry_values[i].valuename))
+ {
+ TALLOC_FREE(values);
+ goto do_init;
+ }
+
+ TALLOC_FREE(values);
+ }
+
+ werr = WERR_OK;
+ goto done;
+
+do_init:
+
+ /*
* There are potentially quite a few store operations which are all
* indiviually wrapped in tdb transactions. Wrapping them in a single
* transaction gives just a single transaction_commit() to actually do
@@ -253,7 +286,8 @@ WERROR init_registry_data(void)
if (regdb->transaction_start(regdb) != 0) {
DEBUG(0, ("init_registry_data: tdb_transaction_start "
"failed\n"));
- return WERR_REG_IO_FAILURE;
+ werr = WERR_REG_IO_FAILURE;
+ goto done;
}
/* loop over all of the predefined paths and add each component */
@@ -267,8 +301,6 @@ WERROR init_registry_data(void)
/* loop over all of the predefined values and add each component */
- frame = talloc_stackframe();
-
for (i=0; builtin_registry_values[i].path != NULL; i++) {
values = TALLOC_ZERO_P(frame, REGVAL_CTR);
@@ -316,25 +348,24 @@ WERROR init_registry_data(void)
TALLOC_FREE(values);
}
- TALLOC_FREE(frame);
-
if (regdb->transaction_commit(regdb) != 0) {
DEBUG(0, ("init_registry_data: Could not commit "
"transaction\n"));
- return WERR_REG_IO_FAILURE;
+ werr = WERR_REG_IO_FAILURE;
+ } else {
+ werr = WERR_OK;
}
- return WERR_OK;
-
- fail:
-
- TALLOC_FREE(frame);
+ goto done;
+fail:
if (regdb->transaction_cancel(regdb) != 0) {
smb_panic("init_registry_data: tdb_transaction_cancel "
"failed\n");
}
+done:
+ TALLOC_FREE(frame);
return werr;
}