Get rid of the registry saving level hack.
Make periodic saving the default behavior.
diff --git a/server/registry.c b/server/registry.c
index d4fca7e..5b7474e 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -72,8 +72,7 @@
int last_value; /* last in use value */
int nb_values; /* count of allocated values in array */
struct key_value *values; /* values array */
- short flags; /* flags */
- short level; /* saving level */
+ unsigned int flags; /* flags */
time_t modif; /* last modification time */
struct list notify_list; /* list of notifications */
};
@@ -99,16 +98,11 @@
/* the root of the registry tree */
static struct key *root_key;
-/* keys saving level */
-/* current_level is the level that is put into all newly created or modified keys */
-/* saving_level is the minimum level that a key needs in order to get saved */
-static int current_level;
-static int saving_level;
-
-static struct timeval next_save_time; /* absolute time of next periodic save */
-static int save_period; /* delay between periodic saves (ms) */
+static const int save_period = 30000; /* delay between periodic saves (in ms) */
static struct timeout_user *save_timeout_user; /* saving timer */
+static void set_periodic_save_timer(void);
+
/* information about where to save a registry branch */
struct save_branch_info
{
@@ -235,9 +229,9 @@
int i;
if (key->flags & KEY_VOLATILE) return;
- /* save key if it has the proper level, and has either some values or no subkeys */
+ /* save key if it has either some values or no subkeys */
/* keys with no values but subkeys are saved implicitly by saving the subkeys */
- if ((key->level >= saving_level) && ((key->last_value >= 0) || (key->last_subkey == -1)))
+ if ((key->last_value >= 0) || (key->last_subkey == -1))
{
fprintf( f, "\n[" );
if (key != base) dump_path( key, base, f );
@@ -419,7 +413,6 @@
key->nb_values = 0;
key->last_value = -1;
key->values = NULL;
- key->level = current_level;
key->modif = modif;
key->parent = NULL;
list_init( &key->notify_list );
@@ -473,7 +466,6 @@
struct key *k;
key->modif = time(NULL);
- key->level = max( key->level, current_level );
make_dirty( key );
/* do notifications */
@@ -1290,8 +1282,6 @@
value->data = newptr;
value->len = len;
value->type = type;
- /* update the key level but not the modification time */
- key->level = max( key->level, current_level );
make_dirty( key );
return 1;
@@ -1472,6 +1462,9 @@
load_init_registry_from_file( filename, key_current_user );
free( filename );
+
+ /* start the periodic save timer */
+ set_periodic_save_timer();
}
/* registry initialisation */
@@ -1507,20 +1500,6 @@
free( filename );
}
-/* update the level of the parents of a key (only needed for the old format) */
-static int update_level( struct key *key )
-{
- int i;
- int max = key->level;
- for (i = 0; i <= key->last_subkey; i++)
- {
- int sub = update_level( key->subkeys[i] );
- if (sub > max) max = sub;
- }
- key->level = max;
- return max;
-}
-
/* save a registry branch to a file */
static void save_all_subkeys( struct key *key, FILE *f )
{
@@ -1652,10 +1631,22 @@
static void periodic_save( void *arg )
{
int i;
+
+ save_timeout_user = NULL;
for (i = 0; i < save_branch_count; i++)
save_branch( save_branch_info[i].key, save_branch_info[i].path );
- add_timeout( &next_save_time, save_period );
- save_timeout_user = add_timeout_user( &next_save_time, periodic_save, 0 );
+ set_periodic_save_timer();
+}
+
+/* start the periodic save timer */
+static void set_periodic_save_timer(void)
+{
+ struct timeval next;
+
+ gettimeofday( &next, 0 );
+ add_timeout( &next, save_period );
+ if (save_timeout_user) remove_timeout_user( save_timeout_user );
+ save_timeout_user = add_timeout_user( &next, periodic_save, 0 );
}
/* save the modified registry branches to disk */
@@ -1679,6 +1670,8 @@
{
int i;
+ if (save_timeout_user) remove_timeout_user( save_timeout_user );
+ save_timeout_user = NULL;
for (i = 0; i < save_branch_count; i++) release_object( save_branch_info[i].key );
release_object( root_key );
}
@@ -1879,29 +1872,11 @@
{
struct key *key;
- current_level = 1;
- saving_level = req->saving;
-
if ((key = get_hkey_obj( req->hkey, KEY_SET_VALUE | KEY_CREATE_SUB_KEY )))
{
load_user_registries( key );
release_object( key );
}
-
- /* set periodic save timer */
-
- if (save_timeout_user)
- {
- remove_timeout_user( save_timeout_user );
- save_timeout_user = NULL;
- }
- if ((save_period = req->period))
- {
- if (save_period < 10000) save_period = 10000; /* limit rate */
- gettimeofday( &next_save_time, 0 );
- add_timeout( &next_save_time, save_period );
- save_timeout_user = add_timeout_user( &next_save_time, periodic_save, 0 );
- }
}
/* add a registry key change notification */