Przeglądaj źródła

Call a service's config_init_fn() as soon as it is loaded.
Then call exec_init_fn() after other initialisation has happened.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@958 fd59a12c-fef9-0310-b244-a6a79926bd2f

Patrick Caulfield 20 lat temu
rodzic
commit
472e59e30a
3 zmienionych plików z 28 dodań i 13 usunięć
  1. 2 1
      exec/main.c
  2. 20 10
      exec/service.c
  3. 6 2
      exec/service.h

+ 2 - 1
exec/main.c

@@ -1185,6 +1185,7 @@ int main (int argc, char **argv)
 		
 		
 	objdb->objdb_init ();
 	objdb->objdb_init ();
 	openais_service_default_objdb_set (objdb);
 	openais_service_default_objdb_set (objdb);
+	openais_service_link_all (objdb, &openais_config);
 
 
 	res = openais_main_config_read (objdb, &error_string, &openais_config, 1);
 	res = openais_main_config_read (objdb, &error_string, &openais_config, 1);
 	if (res == -1) {
 	if (res == -1) {
@@ -1271,7 +1272,7 @@ int main (int argc, char **argv)
 	 * This must occur after totempg is initialized because "this_ip" must be set
 	 * This must occur after totempg is initialized because "this_ip" must be set
 	 */
 	 */
 	this_ip = &openais_config.totem_config.interfaces[0].boundto;
 	this_ip = &openais_config.totem_config.interfaces[0].boundto;
-	openais_service_link_all (objdb, &openais_config);
+	openais_service_init_all (service_count, &openais_config);
 	
 	
 
 
 	sync_register (openais_sync_callbacks_retrieve, openais_sync_completed);
 	sync_register (openais_sync_callbacks_retrieve, openais_sync_completed);

+ 20 - 10
exec/service.c

@@ -8,7 +8,7 @@
  * Author: Steven Dake (sdake@mvista.com)
  * Author: Steven Dake (sdake@mvista.com)
  *
  *
  * This software licensed under BSD license, the text of which follows:
  * This software licensed under BSD license, the text of which follows:
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  * modification, are permitted provided that the following conditions are met:
  *
  *
@@ -111,7 +111,7 @@ int openais_service_objdb_add (
 	return (0);
 	return (0);
 }
 }
 
 
-static int service_handler_register (
+static int service_handler_config (
 	struct openais_service_handler *handler,
 	struct openais_service_handler *handler,
 	struct openais_config *config)
 	struct openais_config *config)
 {
 {
@@ -122,11 +122,6 @@ static int service_handler_register (
 	if (ais_service[handler->id]->config_init_fn) {
 	if (ais_service[handler->id]->config_init_fn) {
 		res = ais_service[handler->id]->config_init_fn (config);
 		res = ais_service[handler->id]->config_init_fn (config);
 	}
 	}
-	//TODO error correction
-	log_printf (LOG_LEVEL_NOTICE, "Initializing service handler '%s'\n", handler->name);
-	if (ais_service[handler->id]->exec_init_fn) {
-		res = ais_service[handler->id]->exec_init_fn (config);
-	}
 	return (res);
 	return (res);
 }
 }
 
 
@@ -169,7 +164,7 @@ int openais_service_link_all (struct objdb_iface_ver0 *objdb,
 			strlen ("name"),
 			strlen ("name"),
 			(void *)&service_name,
 			(void *)&service_name,
 			NULL);
 			NULL);
-	
+
 		ret = objdb->object_key_get (object_service_handle,
 		ret = objdb->object_key_get (object_service_handle,
 			"ver",
 			"ver",
 			strlen ("ver"),
 			strlen ("ver"),
@@ -179,7 +174,7 @@ int openais_service_link_all (struct objdb_iface_ver0 *objdb,
 		ver_int = atoi (service_ver);
 		ver_int = atoi (service_ver);
 
 
 		/*
 		/*
-		 * reference the interfafce and register it
+		 * reference the interface and register it
 		 */
 		 */
 		lcr_ifact_reference (
 		lcr_ifact_reference (
 			&handle,
 			&handle,
@@ -195,8 +190,23 @@ int openais_service_link_all (struct objdb_iface_ver0 *objdb,
 			log_printf(LOG_LEVEL_NOTICE, "openais component %s loaded.\n", service_name);
 			log_printf(LOG_LEVEL_NOTICE, "openais component %s loaded.\n", service_name);
 		}
 		}
 
 
-		service_handler_register (
+		service_handler_config (
 			iface_ver0->openais_get_service_handler_ver0(), openais_config);
 			iface_ver0->openais_get_service_handler_ver0(), openais_config);
 	}
 	}
 	return (0);
 	return (0);
 }
 }
+
+int openais_service_init_all (int service_count,
+			      struct openais_config *openais_config)
+{
+	int i;
+	int res=0;
+
+	for (i = 0; i < service_count; i++) {
+		if (ais_service[i] && ais_service[i]->exec_init_fn) {
+			log_printf (LOG_LEVEL_NOTICE, "Initialising service handler '%s'\n", ais_service[i]->name);
+			res = ais_service[i]->exec_init_fn (openais_config);
+		}
+	}
+	return (res);
+}

+ 6 - 2
exec/service.h

@@ -6,7 +6,7 @@
  * Author: Steven Dake (sdake@mvista.com)
  * Author: Steven Dake (sdake@mvista.com)
  *
  *
  * This software licensed under BSD license, the text of which follows:
  * This software licensed under BSD license, the text of which follows:
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  * modification, are permitted provided that the following conditions are met:
  *
  *
@@ -59,7 +59,7 @@ struct openais_exec_handler {
 	void (*exec_handler_fn) (void *msg, struct totem_ip_address *source_addr);
 	void (*exec_handler_fn) (void *msg, struct totem_ip_address *source_addr);
 	void (*exec_endian_convert_fn) (void *msg);
 	void (*exec_endian_convert_fn) (void *msg);
 };
 };
-	
+
 struct openais_service_handler {
 struct openais_service_handler {
 	unsigned char *name;
 	unsigned char *name;
 	unsigned short id;
 	unsigned short id;
@@ -106,6 +106,10 @@ extern int openais_service_link_all (
 	struct objdb_iface_ver0 *objdb,
 	struct objdb_iface_ver0 *objdb,
 	struct openais_config *openais_config);
 	struct openais_config *openais_config);
 
 
+extern int openais_service_init_all (
+	int service_count,
+	struct openais_config *openais_config);
+
 extern struct openais_service_handler *ais_service[];
 extern struct openais_service_handler *ais_service[];
 
 
 #endif /* SERVICE_H_DEFINED */
 #endif /* SERVICE_H_DEFINED */