16 #include <sys/types.h>
45 static int operations = 0;
46 static GHashTable *recurring_actions = NULL;
50 static GList *blocked_ops = NULL;
53 static GList *inflight_ops = NULL;
55 static void handle_blocked_ops(
void);
90 init_recurring_actions(
void)
92 if (recurring_actions == NULL) {
93 recurring_actions = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
106 static inline gboolean
111 g_list_find(inflight_ops, op) != NULL;
127 expand_resource_class(
const char *rsc,
const char *standard,
const char *agent)
129 char *expanded_class = NULL;
135 crm_debug(
"Found %s agent %s for %s", found_class, agent, rsc);
136 expanded_class = strdup(found_class);
138 crm_info(
"Assuming resource class lsb for agent %s for %s",
143 expanded_class = strdup(standard);
146 return expanded_class;
158 dup_file_path(
const char *filename,
const char *dirname)
160 return (*filename ==
'/')? strdup(filename)
166 const char *provider,
const char *agent,
171 uint32_t ra_caps = 0;
178 if (pcmk__str_empty(
name)) {
179 crm_err(
"Cannot create operation without resource name");
183 if (pcmk__str_empty(standard)) {
184 crm_err(
"Cannot create operation for %s without resource class",
name);
190 && pcmk__str_empty(provider)) {
191 crm_err(
"Cannot create operation for %s without provider",
name);
195 if (pcmk__str_empty(agent)) {
196 crm_err(
"Cannot create operation for %s without agent name",
name);
200 if (pcmk__str_empty(
action)) {
201 crm_err(
"Cannot create operation for %s without operation name",
name);
214 op->
standard = expand_resource_class(
name, standard, agent);
215 op->
agent = strdup(agent);
223 op->
action = strdup(
"status");
270 static int args_size =
sizeof(op->
opaque->
args) /
sizeof(
char *);
272 g_hash_table_iter_init(&iter, op->
params);
274 while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value) &&
275 index <= args_size - 3) {
287 g_hash_table_destroy(op->
params);
297 g_hash_table_destroy(params);
303 g_hash_table_destroy(params);
314 unsigned int cur_arg;
316 op = calloc(1,
sizeof(*op));
322 for (cur_arg = 1; args && args[cur_arg - 1]; cur_arg++) {
323 op->
opaque->
args[cur_arg] = strdup(args[cur_arg - 1]);
326 crm_err(
"svc_action_t args list not long enough for '%s' execution request.", exec);
350 GHashTable *params,
int sequence,
void *cb_data)
358 action->sequence = sequence;
359 action->cb_data = cb_data;
381 CRM_CHECK((op != NULL) && (user != NULL),
return -EINVAL);
399 action->synchronous =
false;
400 action->opaque->callback = cb;
413 services_set_op_pending(
svc_action_t *op, DBusPendingCall *pending)
415 if (op->
opaque->pending && (op->
opaque->pending != pending)) {
421 dbus_pending_call_unref(op->
opaque->pending);
423 op->
opaque->pending = pending;
425 crm_trace(
"Updated pending %s DBus call (%p)", op->
id, pending);
435 if ((op == NULL) || (op->
opaque == NULL)) {
440 if(op->
opaque->timerid != 0) {
442 g_source_remove(op->
opaque->timerid);
447 if (dbus_pending_call_get_completed(op->
opaque->pending)) {
449 crm_warn(
"Result of %s op %s was unhandled",
452 crm_debug(
"Will ignore any result of canceled %s op %s",
455 dbus_pending_call_cancel(op->
opaque->pending);
456 services_set_op_pending(op, NULL);
484 CRM_CHECK(g_list_find(inflight_ops, op) == NULL,
return);
485 CRM_CHECK(g_list_find(blocked_ops, op) == NULL,
return);
487 || (g_hash_table_lookup(recurring_actions, op->
id) == NULL),
516 g_hash_table_destroy(op->
params);
528 if (recurring_actions) {
529 g_hash_table_remove(recurring_actions, op->
id);
552 gboolean cancelled = FALSE;
557 init_recurring_actions();
558 op = g_hash_table_lookup(recurring_actions,
id);
576 crm_info(
"Terminating in-flight op %s[%d] early because it was cancelled",
579 if (cancelled == FALSE) {
580 crm_err(
"Termination of %s[%d] failed",
id, op->
pid);
587 if (inflight_systemd_or_upstart(op)) {
588 inflight_ops = g_list_remove(inflight_ops, op);
606 blocked_ops = g_list_remove(blocked_ops, op);
622 init_recurring_actions();
623 op = g_hash_table_lookup(recurring_actions,
id);
631 if (op->
pid || inflight_systemd_or_upstart(op)) {
658 dup = g_hash_table_lookup(recurring_actions, op->
id);
660 if (dup && (dup != op)) {
683 inline static gboolean
718 inflight_ops = g_list_append(inflight_ops, op);
732 inflight_ops = g_list_remove(inflight_ops, op);
733 blocked_ops = g_list_remove(blocked_ops, op);
736 handle_blocked_ops();
745 if (action_callback) {
748 if (action_fork_callback) {
753 init_recurring_actions();
754 if (handle_duplicate_recurring(op) == TRUE) {
759 g_hash_table_replace(recurring_actions, op->
id, op);
764 blocked_ops = g_list_append(blocked_ops, op);
768 return action_exec_helper(op);
778 static gboolean processing_blocked_ops = FALSE;
786 for (gIter = inflight_ops; gIter != NULL; gIter = gIter->next) {
797 handle_blocked_ops(
void)
799 GList *executed_ops = NULL;
802 gboolean res = FALSE;
804 if (processing_blocked_ops) {
809 processing_blocked_ops = TRUE;
813 for (gIter = blocked_ops; gIter != NULL; gIter = gIter->next) {
818 executed_ops = g_list_append(executed_ops, op);
819 res = action_exec_helper(op);
828 for (gIter = executed_ops; gIter != NULL; gIter = gIter->next) {
830 blocked_ops = g_list_remove(blocked_ops, op);
832 g_list_free(executed_ops);
834 processing_blocked_ops = FALSE;
840 const char *
class = op->standard;
842 if (op->
agent == NULL) {
843 crm_err(
"meta-data requested without specifying agent");
848 crm_err(
"meta-data requested for agent %s without specifying class",
858 crm_err(
"meta-data requested for %s, but could not determine class",
873 return action_exec_helper(op);
896 rc = action_get_metadata(op);
898 rc = action_exec_helper(op);
920 GList *standards = NULL;
921 GList *agents = NULL;
930 standards = g_list_append(standards,
932 g_list_free_full(agents, free);
939 standards = g_list_append(standards,
941 g_list_free_full(agents, free);
948 standards = g_list_append(standards,
950 g_list_free_full(agents, free);
970 if ((standard == NULL)
977 if (standard == NULL) {
981 result = g_list_concat(tmp1, tmp2);
988 result = g_list_concat(tmp1, tmp2);
996 result = g_list_concat(tmp1, tmp2);
1026 GList *standards = NULL;
1027 GList *providers = NULL;
1029 gboolean
rc = FALSE;
1030 gboolean has_providers = FALSE;
1033 for (iter = standards; iter != NULL; iter = iter->next) {
1047 if (has_providers == TRUE && provider != NULL) {
1049 for (iter = providers; iter != NULL; iter = iter->next) {
1055 }
else if (has_providers == FALSE && provider == NULL) {
1105 g_list_free(standards);
1106 g_list_free(providers);