diff --git a/crm/pengine/main.c b/crm/pengine/main.c index d8b5f7dce4..078390191b 100644 --- a/crm/pengine/main.c +++ b/crm/pengine/main.c @@ -1,235 +1,204 @@ -/* $Id: main.c,v 1.5 2004/12/10 20:03:20 andrew Exp $ */ +/* $Id: main.c,v 1.6 2004/12/15 10:14:09 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define SYS_NAME CRM_SYSTEM_PENGINE #define OPTARGS "skrhVc" #define PID_FILE WORKING_DIR "/" SYS_NAME ".pid" #define DAEMON_LOG DEVEL_DIR"/"SYS_NAME".log" #define DAEMON_DEBUG DEVEL_DIR"/"SYS_NAME".debug" GMainLoop* mainloop = NULL; const char* crm_system_name = SYS_NAME; void usage(const char* cmd, int exit_status); int init_start(void); void pengine_shutdown(int nsig); extern gboolean process_pe_message(xmlNodePtr msg, IPC_Channel *sender); int main(int argc, char ** argv) { - gboolean allow_cores = TRUE; - int req_restart = FALSE; - int req_status = FALSE; - int req_stop = FALSE; - int argerr = 0; - int flag; + gboolean allow_cores = TRUE; + int req_restart = FALSE; + int req_status = FALSE; + int req_stop = FALSE; + int argerr = 0; + int flag; - /* Redirect messages from glib functions to our handler */ - g_log_set_handler(NULL, - G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL - | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE - | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG - | G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL, - cl_glib_msg_handler, NULL); - /* and for good measure... */ - g_log_set_always_fatal((GLogLevelFlags)0); + /* Redirect messages from glib functions to our handler */ + g_log_set_handler(NULL, + G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL + | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE + | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG + | G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL, + cl_glib_msg_handler, NULL); + /* and for good measure... */ + g_log_set_always_fatal((GLogLevelFlags)0); - cl_log_set_entity(crm_system_name); - cl_log_set_facility(LOG_USER); + cl_log_set_entity(crm_system_name); + cl_log_set_facility(LOG_LOCAL7); - cl_log_set_logfile(DAEMON_LOG); - cl_log_set_debugfile(DAEMON_DEBUG); - - while ((flag = getopt(argc, argv, OPTARGS)) != EOF) { + cl_log_set_logfile(DAEMON_LOG); + cl_log_set_debugfile(DAEMON_DEBUG); + + CL_SIGNAL(SIGTERM, pengine_shutdown); + + while ((flag = getopt(argc, argv, OPTARGS)) != EOF) { switch(flag) { case 'V': alter_debug(DEBUG_INC); break; case 's': /* Status */ req_status = TRUE; break; case 'k': /* Stop (kill) */ req_stop = TRUE; break; case 'r': /* Restart */ req_restart = TRUE; break; case 'h': /* Help message */ usage(crm_system_name, LSB_EXIT_OK); break; case 'c': allow_cores = TRUE; break; default: ++argerr; break; } - } + } - if (optind > argc) { + if (optind > argc) { ++argerr; - } + } - if (argerr) { + if (argerr) { usage(crm_system_name,LSB_EXIT_GENERIC); - } + } - /* read local config file */ - - if(allow_cores) { - cl_set_corerootdir(DEVEL_DIR); - cl_enable_coredumps(1); - cl_cdtocoredir(); - } + /* read local config file */ + + if(allow_cores) { + crm_info("Enabling coredumps"); + cl_set_corerootdir(DEVEL_DIR); + cl_enable_coredumps(1); + cl_cdtocoredir(); + } - if (req_status){ + if (req_status){ return init_status(PID_FILE, crm_system_name); - } + } - if (req_stop){ + if (req_stop){ return init_stop(PID_FILE); - } + } - if (req_restart) { + if (req_restart) { init_stop(PID_FILE); - } - - return init_start(); + } + return init_start(); } int init_start(void) { - ll_cluster_t* hb_fd = NULL; - int facility; - IPC_Channel *crm_ch = NULL; -#ifdef REALTIME_SUPPORT - static int crm_realtime = 1; -#endif - - /* change the logging facility to the one used by heartbeat daemon */ - hb_fd = ll_cluster_new("heartbeat"); - - crm_info("Switching to Heartbeat logger"); - if ((facility = hb_fd->llc_ops->get_logfacility(hb_fd))>0) { - cl_log_set_facility(facility); - } - - crm_info("Register PID"); - register_pid(PID_FILE, FALSE, pengine_shutdown); - - init_client_ipc_comms( - CRM_SYSTEM_CRMD, subsystem_msg_dispatch, - (void*)process_pe_message, &crm_ch); - - if(crm_ch != NULL) { - send_hello_message(crm_ch, "1234", CRM_SYSTEM_PENGINE, "0", "1"); - - /* Create the mainloop and run it... */ - mainloop = g_main_new(FALSE); - crm_info("Starting %s", crm_system_name); - - -#ifdef REALTIME_SUPPORT - if (crm_realtime == 1){ - cl_enable_realtime(); - }else if (crm_realtime == 0){ - cl_disable_realtime(); - } - cl_make_realtime(SCHED_RR, 5, 64, 64); -#endif - - g_main_run(mainloop); - - } else { - crm_err("Could not connect to the CRMd"); - } - - return_to_orig_privs(); - - if (unlink(PID_FILE) == 0) { - crm_info("[%s] stopped", crm_system_name); - } + IPC_Channel *crm_ch = NULL; + + init_client_ipc_comms( + CRM_SYSTEM_CRMD, subsystem_msg_dispatch, + (void*)process_pe_message, &crm_ch); + + if(crm_ch != NULL) { + send_hello_message(crm_ch, "1234", CRM_SYSTEM_PENGINE, "0", "1"); + + /* Create the mainloop and run it... */ + crm_info("Starting %s", crm_system_name); + + mainloop = g_main_new(FALSE); + g_main_run(mainloop); + return_to_orig_privs(); - if(crm_ch != NULL) - return 0; + crm_info("Exiting %s", crm_system_name); + return 0; + } - return 1; + crm_err("Could not connect to the CRMd"); + return 1; } void usage(const char* cmd, int exit_status) { - FILE* stream; + FILE* stream; - stream = exit_status ? stderr : stdout; + stream = exit_status ? stderr : stdout; - fprintf(stream, "usage: %s [-srkh]" - "[-c configure file]\n", cmd); + fprintf(stream, "usage: %s [-srkh]" + "[-c configure file]\n", cmd); /* fprintf(stream, "\t-d\tsets debug level\n"); */ /* fprintf(stream, "\t-s\tgets daemon status\n"); */ /* fprintf(stream, "\t-r\trestarts daemon\n"); */ /* fprintf(stream, "\t-k\tstops daemon\n"); */ /* fprintf(stream, "\t-h\thelp message\n"); */ - fflush(stream); + fflush(stream); - exit(exit_status); + exit(exit_status); } void pengine_shutdown(int nsig) { - static int shuttingdown = 0; - CL_SIGNAL(nsig, pengine_shutdown); + static int shuttingdown = 0; + CL_SIGNAL(nsig, pengine_shutdown); - if (!shuttingdown) { + if (!shuttingdown) { shuttingdown = 1; - } - if (mainloop != NULL && g_main_is_running(mainloop)) { + } + if (mainloop != NULL && g_main_is_running(mainloop)) { g_main_quit(mainloop); - }else{ + }else{ exit(LSB_EXIT_OK); - } + } } diff --git a/crm/pengine/pengine.c b/crm/pengine/pengine.c index fcecea76f8..ffcc12aef5 100755 --- a/crm/pengine/pengine.c +++ b/crm/pengine/pengine.c @@ -1,255 +1,260 @@ -/* $Id: pengine.c,v 1.49 2004/11/12 17:20:58 andrew Exp $ */ +/* $Id: pengine.c,v 1.50 2004/12/15 10:14:09 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include FILE *pemsg_strm = NULL; xmlNodePtr do_calculations(xmlNodePtr cib_object); int num_synapse = 0; gboolean process_pe_message(xmlNodePtr msg, IPC_Channel *sender) { char *msg_buffer = NULL; const char *sys_to = NULL; const char *op = get_xml_attr (msg, XML_TAG_OPTIONS, XML_ATTR_OP, TRUE); const char *ref = xmlGetProp(msg, XML_ATTR_REFERENCE); if(safe_str_eq(xmlGetProp(msg, XML_ATTR_MSGTYPE), XML_ATTR_REQUEST)) { crm_info( "Message was a response not a request." " Discarding"); } crm_verbose("Processing %s op (ref=%s)...", op, ref); if(pemsg_strm == NULL) { pemsg_strm = fopen(DEVEL_DIR"/pe.log", "w"); } msg_buffer = dump_xml_formatted(msg); fprintf(pemsg_strm, "%s: %s\n", "[in ]", msg_buffer); fflush(pemsg_strm); crm_free(msg_buffer); sys_to = xmlGetProp(msg, XML_ATTR_SYSTO); if(op == NULL){ /* error */ } else if(strcmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(sys_to == NULL || strcmp(sys_to, CRM_SYSTEM_PENGINE) != 0) { crm_verbose("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_PECALC) == 0) { - xmlNodePtr input_cib = find_xml_node(msg, XML_TAG_CIB); - xmlNodePtr output = do_calculations(input_cib); + xmlNodePtr output = NULL; + xmlNodePtr input_cib = find_xml_node(msg, XML_TAG_FRAGMENT); + + input_cib = find_xml_node(input_cib, XML_TAG_CIB); + output = do_calculations(input_cib); + msg_buffer = dump_xml_formatted(output); fprintf(pemsg_strm, "%s: %s\n", "[out ]", msg_buffer); fflush(pemsg_strm); crm_free(msg_buffer); + if (send_ipc_reply(sender, msg, output) ==FALSE) { crm_warn("Answer could not be sent"); } free_xml(output); } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_err("Received quit message, terminating"); exit(0); } return TRUE; } xmlNodePtr do_calculations(xmlNodePtr cib_object) { GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr placement_constraints = NULL; GListPtr actions = NULL; GListPtr ordering_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; xmlNodePtr graph = NULL; /* pe_debug_on(); */ crm_verbose("=#=#=#=#= Stage 0 =#=#=#=#="); stage0(cib_object, &resources, &nodes, &placement_constraints, &actions, &ordering_constraints, &stonith_list, &shutdown_list); crm_verbose("=#=#=#=#= Stage 1 =#=#=#=#="); stage1(placement_constraints, nodes, resources); crm_verbose("=#=#=#=#= Stage 2 =#=#=#=#="); stage2(resources, nodes, &colors); crm_verbose("========= Nodes ========="); crm_debug_action( slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE) ) ); crm_verbose("========= Resources ========="); crm_debug_action( slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 3 =#=#=#=#="); stage3(colors); crm_verbose("=#=#=#=#= Stage 4 =#=#=#=#="); stage4(colors); crm_verbose("========= Colors ========="); crm_debug_action( slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE) ) ); crm_verbose("=#=#=#=#= Stage 5 =#=#=#=#="); stage5(resources, &ordering_constraints); crm_verbose("=#=#=#=#= Stage 6 =#=#=#=#="); stage6(&actions, &ordering_constraints, nodes, resources); crm_verbose("========= Action List ========="); crm_debug_action( slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 7 =#=#=#=#="); stage7(resources, actions, ordering_constraints); crm_verbose("=#=#=#=#= Summary =#=#=#=#="); summary(resources); crm_verbose("========= Action Sets ========="); crm_verbose("\t========= Set %d (Un-runnable) =========", -1); crm_debug_action( slist_iter(action, action_t, actions, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("\t", action, TRUE); } ) ); crm_debug_action( slist_iter(action_set, GList, action_sets, lpc, crm_verbose("\t========= Set %d =========", lpc); slist_iter(action, action_t, action_set, lpc2, print_action("\t", action, TRUE); ) ) ); crm_verbose("========= Stonith List ========="); crm_debug_action( slist_iter(node, node_t, stonith_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("========= Shutdown List ========="); crm_debug_action( slist_iter(node, node_t, shutdown_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("=#=#=#=#= Stage 8 =#=#=#=#="); stage8(resources, actions, &graph); crm_verbose("=#=#=#=#= Cleanup =#=#=#=#="); crm_verbose("deleting node cons"); while(placement_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); placement_constraints = placement_constraints->next; } if(placement_constraints != NULL) { g_list_free(placement_constraints); } crm_verbose("deleting order cons"); pe_free_shallow(ordering_constraints); crm_verbose("deleting action sets"); slist_iter(action_set, GList, action_sets, lpc, pe_free_shallow_adv(action_set, FALSE); ); pe_free_shallow_adv(action_sets, FALSE); crm_verbose("deleting actions"); pe_free_actions(actions); crm_verbose("deleting resources"); pe_free_resources(resources); crm_verbose("deleting colors"); pe_free_colors(colors); crm_verbose("deleting nodes"); pe_free_nodes(nodes); if(shutdown_list != NULL) { g_list_free(shutdown_list); } if(stonith_list != NULL) { g_list_free(stonith_list); } return graph; }