Просмотр исходного кода

objctl: add missing calls to dispatch notifications and fix memory corruption

when editing the objdb via objctl, we need to notify objdb users of changes.
That includes the logging subsystem.

In the process of adding the reload call, i spotted that objctl was passing
an incorrect value for key_value_len that was one off (0 byte end string)
that was corrupting the keys.

[root@rhel6-node2 ~]# corosync-objctl -w logging.debug=off
....
Apr 24 07:42:59 corosync [corosy] fabdebug: off2@

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Fabio M. Di Nitto 14 лет назад
Родитель
Сommit
dc9b04a719
1 измененных файлов с 18 добавлено и 4 удалено
  1. 18 4
      tools/corosync-objctl.c

+ 18 - 4
tools/corosync-objctl.c

@@ -240,6 +240,18 @@ static void print_config_tree(confdb_handle_t handle, hdb_handle_t parent_object
 	}
 	}
 }
 }
 
 
+static cs_error_t reload_db(confdb_handle_t handle)
+{
+	char error[1024];
+	cs_error_t ret;
+
+	ret = confdb_reload(handle, 0, error, sizeof(error) - 1);
+	if (ret != CONFDB_OK) {
+		fprintf (stderr, "Error reloading DB %d\n", ret);
+	}
+	return ret;
+}
+
 static int read_in_config_file (char * filename)
 static int read_in_config_file (char * filename)
 {
 {
 	confdb_handle_t handle;
 	confdb_handle_t handle;
@@ -310,7 +322,7 @@ static int read_in_config_file (char * filename)
 		/* write the attribute */
 		/* write the attribute */
 		write_key (handle, line);
 		write_key (handle, line);
 	}
 	}
-
+	reload_db(handle);
 	confdb_finalize (handle);
 	confdb_finalize (handle);
 	fclose (fh);
 	fclose (fh);
 	return 0;
 	return 0;
@@ -516,7 +528,7 @@ static void write_key(confdb_handle_t handle, char * path_pt)
 								  old_key_value,
 								  old_key_value,
 								  old_key_value_len,
 								  old_key_value_len,
 								  key_value,
 								  key_value,
-								  strlen(key_value));
+								  strlen(key_value)+1);
 
 
 		if (res != CS_OK)
 		if (res != CS_OK)
 			fprintf(stderr, "Failed to replace the key %s=%s. Error %d\n", key_name, key_value, res);
 			fprintf(stderr, "Failed to replace the key %s=%s. Error %d\n", key_name, key_value, res);
@@ -526,7 +538,7 @@ static void write_key(confdb_handle_t handle, char * path_pt)
 								 obj_handle,
 								 obj_handle,
 								 key_name,
 								 key_name,
 								 key_value,
 								 key_value,
-								 strlen(key_value),
+								 strlen(key_value)+1,
 								 CONFDB_VALUETYPE_STRING);
 								 CONFDB_VALUETYPE_STRING);
 		if (res != CS_OK)
 		if (res != CS_OK)
 			fprintf(stderr, "Failed to create the key %s=%s. Error %d\n", key_name, key_value, res);
 			fprintf(stderr, "Failed to create the key %s=%s. Error %d\n", key_name, key_value, res);
@@ -645,7 +657,7 @@ static void create_object_key(confdb_handle_t handle, char *name_pt)
 		obj_handle,
 		obj_handle,
 		key_name,
 		key_name,
 		key_value,
 		key_value,
-		strlen(key_value),
+		strlen(key_value)+1,
 		CONFDB_VALUETYPE_STRING);
 		CONFDB_VALUETYPE_STRING);
 	if (res != CS_OK) {
 	if (res != CS_OK) {
 		fprintf(stderr,
 		fprintf(stderr,
@@ -910,6 +922,8 @@ int main (int argc, char *argv[]) {
 	if (action == ACTION_TRACK) {
 	if (action == ACTION_TRACK) {
 		listen_for_object_changes(handle);
 		listen_for_object_changes(handle);
 		stop_tracking(handle);
 		stop_tracking(handle);
+	} else {
+		reload_db(handle);
 	}
 	}
 
 
 	result = confdb_finalize (handle);
 	result = confdb_finalize (handle);