diff --git a/crm/crmd/pengine.c b/crm/crmd/pengine.c index 69f38ffe9e..18d6cb1cad 100644 --- a/crm/crmd/pengine.c +++ b/crm/crmd/pengine.c @@ -1,146 +1,147 @@ /* * 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 /* for access */ #include #include #include /* for calls to open */ #include /* for calls to open */ #include /* for calls to open */ #include /* for getpwuid */ #include /* for initgroups */ #include /* for getrlimit */ #include /* for getrlimit */ #include #include #include #include #include #include #include #include #define CLIENT_EXIT_WAIT 30 struct crm_subsystem_s *pe_subsystem = NULL; /* A_PE_START, A_PE_STOP, A_TE_RESTART */ enum crmd_fsa_input do_pe_control(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input result = I_NULL; struct crm_subsystem_s *this_subsys = pe_subsystem; long long stop_actions = A_PE_STOP; long long start_actions = A_PE_START; if(action & stop_actions) { crm_info("Stopping %s", this_subsys->command); if(stop_subsystem(this_subsys) == FALSE) { result = I_FAIL; } else if(this_subsys->pid > 0) { int lpc = CLIENT_EXIT_WAIT; int pid_status = -1; while(lpc-- > 0 && this_subsys->pid > 0 && CL_PID_EXISTS(this_subsys->pid)) { sleep(1); - waitpid(this_subsys->pid, &pid_status, WNOHANG); + + if(waitpid(this_subsys->pid, + &pid_status, WNOHANG) > 0) { + this_subsys->pid = -1; + break; + } } - if(CL_PID_EXISTS(this_subsys->pid)) { - crm_err("Process %s is still active with pid=%d", + if(this_subsys->pid != -1) { + crm_err("Proc %s is still active with pid=%d", this_subsys->command, this_subsys->pid); result = I_FAIL; } } cleanup_subsystem(this_subsys); } if(action & start_actions) { if(cur_state != S_STOPPING) { crm_info("Starting %s", this_subsys->command); if(start_subsystem(this_subsys) == FALSE) { result = I_FAIL; cleanup_subsystem(this_subsys); } } else { crm_info("Ignoring request to start %s while shutting down", this_subsys->command); } } return result; } char *fsa_pe_ref = NULL; /* A_PE_INVOKE */ enum crmd_fsa_input do_pe_invoke(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { xmlNodePtr local_cib = NULL; if(is_set(fsa_input_register, R_PE_CONNECTED) == FALSE){ crm_info("Waiting for the PE to connect"); crmd_fsa_stall(); return I_NULL; } local_cib = get_cib_copy(); crm_verbose("Invoking %s with %p", CRM_SYSTEM_PENGINE, local_cib); if(fsa_pe_ref) { crm_free(fsa_pe_ref); fsa_pe_ref = NULL; } send_request(NULL, local_cib, CRM_OP_PECALC, NULL, CRM_SYSTEM_PENGINE, &fsa_pe_ref); return I_NULL; } - - - - diff --git a/crm/crmd/tengine.c b/crm/crmd/tengine.c index 1f2ae35c25..e862973eb7 100644 --- a/crm/crmd/tengine.c +++ b/crm/crmd/tengine.c @@ -1,225 +1,230 @@ /* * 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 /* for access */ #include #include #include /* for calls to open */ #include /* for calls to open */ #include /* for calls to open */ #include /* for getpwuid */ #include /* for initgroups */ #include /* for getrlimit */ #include /* for getrlimit */ #include #include #include #include #include #include #include #include struct crm_subsystem_s *te_subsystem = NULL; /* A_TE_START, A_TE_STOP, A_TE_RESTART */ enum crmd_fsa_input do_te_control(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input result = I_NULL; struct crm_subsystem_s *this_subsys = te_subsystem; long long stop_actions = A_TE_STOP; long long start_actions = A_TE_START; int lpc, pid_status; /* if(action & stop_actions && cur_state != S_STOPPING */ /* && is_set(fsa_input_register, R_TE_PEND)) { */ /* result = I_WAIT_FOR_EVENT; */ /* return result; */ /* } */ if(action & stop_actions) { if(stop_subsystem(this_subsys) == FALSE) result = I_FAIL; else if(this_subsys->pid > 0){ lpc = CLIENT_EXIT_WAIT; pid_status = -1; while(lpc-- > 0 && this_subsys->pid > 0 && CL_PID_EXISTS(this_subsys->pid)) { sleep(1); - waitpid(this_subsys->pid, &pid_status, WNOHANG); + + if(waitpid(this_subsys->pid, + &pid_status, WNOHANG) > 0) { + this_subsys->pid = -1; + break; + } } - if(CL_PID_EXISTS(this_subsys->pid)) { - crm_err("Process %s is still active with pid=%d", + if(this_subsys->pid != -1) { + crm_err("Proc %s is still active with pid=%d", this_subsys->command, this_subsys->pid); result = I_FAIL; } } cleanup_subsystem(this_subsys); } if(action & start_actions) { if(cur_state != S_STOPPING) { if(start_subsystem(this_subsys) == FALSE) { result = I_FAIL; cleanup_subsystem(this_subsys); } } else { crm_info("Ignoring request to start %s while shutting down", this_subsys->command); } } return result; } static xmlNodePtr te_last_input = NULL; static xmlNodePtr te_lastcc = NULL; /* A_TE_COPYTO */ enum crmd_fsa_input do_te_copyto(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { xmlNodePtr message = (xmlNodePtr)msg_data->data; xmlNodePtr message_copy = NULL; xmlNodePtr opts = NULL; const char *true_op = NULL; if(message != NULL) { crm_xml_devel(message, "[TE input]"); message_copy = copy_xml_node_recursive(message); opts = find_xml_node(message_copy, XML_TAG_OPTIONS); true_op = xmlGetProp(opts, XML_ATTR_OP); set_xml_property_copy(opts, XML_ATTR_OP, CRM_OP_EVENTCC); set_xml_property_copy(opts, XML_ATTR_TRUEOP, true_op); set_xml_property_copy( message_copy, XML_ATTR_SYSTO, CRM_SYSTEM_TENGINE); /* crm_xml_devel(message_copy, "[TE input copy]"); */ } if(is_set(fsa_input_register, R_TE_CONNECTED) == FALSE){ crm_info("Waiting for the TE to connect"); if(message_copy != NULL) { crm_debug("Freeing old data - 1"); free_xml(te_lastcc); te_lastcc = message_copy; } crmd_fsa_stall(); return I_NULL; } if(message_copy == NULL) { message_copy = te_lastcc; te_lastcc = NULL; } else { crm_debug("Freeing old data - 2"); free_xml(te_lastcc); te_lastcc = NULL; } crm_debug("relaying message to the TE"); relay_message(message_copy, FALSE); crm_debug("Freeing processed data"); free_xml(message_copy); return I_NULL; } /* A_TE_INVOKE, A_TE_CANCEL */ enum crmd_fsa_input do_te_invoke(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { xmlNodePtr graph = NULL; xmlNodePtr msg = (xmlNodePtr)msg_data->data; enum crmd_fsa_input ret = I_NULL; if(is_set(fsa_input_register, R_TE_CONNECTED) == FALSE){ crm_info("Waiting for the TE to connect"); if(msg != NULL) { free_xml(te_last_input); te_last_input = copy_xml_node_recursive(msg); } crmd_fsa_stall(); return I_NULL; } if(msg == NULL) { msg = te_last_input; } if(action & A_TE_INVOKE) { graph = find_xml_node(msg, "transition_graph"); if(graph != NULL) { send_request(NULL, graph, CRM_OP_TRANSITION, NULL, CRM_SYSTEM_TENGINE, NULL); } else { ret = I_FAIL; } } else { send_request(NULL, graph, CRM_OP_ABORT, NULL, CRM_SYSTEM_TENGINE, NULL); } /* only free it if it was a local copy */ free_xml(te_last_input); te_last_input = NULL; return ret; }