14 #include <sys/types.h>
39 static int operations = 0;
40 static GHashTable *recurring_actions = NULL;
44 static GList *blocked_ops = NULL;
47 static GList *inflight_ops = NULL;
49 static void handle_blocked_ops(
void);
84 init_recurring_actions(
void)
86 if (recurring_actions == NULL) {
87 recurring_actions = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
100 static inline gboolean
105 && (g_list_find(inflight_ops, op) != NULL);
121 expand_resource_class(
const char *rsc,
const char *standard,
const char *agent)
123 char *expanded_class = NULL;
129 crm_debug(
"Found %s agent %s for %s", found_class, agent, rsc);
130 expanded_class = strdup(found_class);
132 crm_info(
"Assuming resource class lsb for agent %s for %s",
137 expanded_class = strdup(standard);
140 return expanded_class;
152 dup_file_path(
const char *filename,
const char *dirname)
154 return (*filename ==
'/')? strdup(filename)
160 const char *provider,
const char *agent,
161 const char *action, guint interval_ms,
int timeout,
165 uint32_t ra_caps = 0;
172 if (crm_strlen_zero(name)) {
173 crm_err(
"Cannot create operation without resource name");
177 if (crm_strlen_zero(standard)) {
178 crm_err(
"Cannot create operation for %s without resource class", name);
184 crm_err(
"Cannot create operation for %s without provider", name);
188 if (crm_strlen_zero(agent)) {
189 crm_err(
"Cannot create operation for %s without agent name", name);
193 if (crm_strlen_zero(action)) {
194 crm_err(
"Cannot create operation for %s without operation name", name);
204 op->
rsc = strdup(name);
207 op->
standard = expand_resource_class(name, standard, agent);
208 op->
agent = strdup(agent);
214 op->
action = strdup(
"status");
216 op->
action = strdup(action);
261 static int args_size =
sizeof(op->
opaque->
args) /
sizeof(
char *);
263 g_hash_table_iter_init(&iter, op->
params);
265 while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value) &&
266 index <= args_size - 3) {
278 g_hash_table_destroy(op->
params);
288 g_hash_table_destroy(params);
294 g_hash_table_destroy(params);
305 unsigned int cur_arg;
307 op = calloc(1,
sizeof(*op));
313 for (cur_arg = 1; args && args[cur_arg - 1]; cur_arg++) {
314 op->
opaque->
args[cur_arg] = strdup(args[cur_arg - 1]);
317 crm_err(
"svc_action_t args list not long enough for '%s' execution request.", exec);
341 GHashTable *params,
int sequence,
void *cb_data)
347 action->
id = strdup(
id);
372 CRM_CHECK((op != NULL) && (user != NULL),
return -EINVAL);
404 services_set_op_pending(
svc_action_t *op, DBusPendingCall *pending)
406 if (op->
opaque->pending && (op->
opaque->pending != pending)) {
412 dbus_pending_call_unref(op->
opaque->pending);
414 op->
opaque->pending = pending;
416 crm_trace(
"Updated pending %s DBus call (%p)", op->
id, pending);
426 if ((op == NULL) || (op->
opaque == NULL)) {
431 if(op->
opaque->timerid != 0) {
433 g_source_remove(op->
opaque->timerid);
438 if (dbus_pending_call_get_completed(op->
opaque->pending)) {
440 crm_warn(
"Result of %s op %s was unhandled",
443 crm_debug(
"Will ignore any result of canceled %s op %s",
446 dbus_pending_call_cancel(op->
opaque->pending);
447 services_set_op_pending(op, NULL);
475 CRM_CHECK(g_list_find(inflight_ops, op) == NULL,
return);
476 CRM_CHECK(g_list_find(blocked_ops, op) == NULL,
return);
478 || (g_hash_table_lookup(recurring_actions, op->
id) == NULL),
507 g_hash_table_destroy(op->
params);
519 if (recurring_actions) {
520 g_hash_table_remove(recurring_actions, op->
id);
543 gboolean cancelled = FALSE;
548 init_recurring_actions();
549 op = g_hash_table_lookup(recurring_actions,
id);
567 crm_info(
"Terminating in-flight op %s (pid %d) early because it was cancelled",
570 if (cancelled == FALSE) {
571 crm_err(
"Termination of %s (pid %d) failed",
id, op->
pid);
578 if (inflight_systemd_or_upstart(op)) {
579 inflight_ops = g_list_remove(inflight_ops, op);
597 blocked_ops = g_list_remove(blocked_ops, op);
613 init_recurring_actions();
614 op = g_hash_table_lookup(recurring_actions,
id);
622 if (op->
pid || inflight_systemd_or_upstart(op)) {
649 dup = g_hash_table_lookup(recurring_actions, op->
id);
651 if (dup && (dup != op)) {
674 inline static gboolean
709 inflight_ops = g_list_append(inflight_ops, op);
723 inflight_ops = g_list_remove(inflight_ops, op);
724 blocked_ops = g_list_remove(blocked_ops, op);
727 handle_blocked_ops();
736 if (action_callback) {
739 if (action_fork_callback) {
744 init_recurring_actions();
745 if (handle_duplicate_recurring(op) == TRUE) {
750 g_hash_table_replace(recurring_actions, op->
id, op);
755 blocked_ops = g_list_append(blocked_ops, op);
759 return action_exec_helper(op);
769 static gboolean processing_blocked_ops = FALSE;
777 for (gIter = inflight_ops; gIter != NULL; gIter = gIter->next) {
788 handle_blocked_ops(
void)
790 GList *executed_ops = NULL;
793 gboolean res = FALSE;
795 if (processing_blocked_ops) {
800 processing_blocked_ops = TRUE;
804 for (gIter = blocked_ops; gIter != NULL; gIter = gIter->next) {
809 executed_ops = g_list_append(executed_ops, op);
810 res = action_exec_helper(op);
819 for (gIter = executed_ops; gIter != NULL; gIter = gIter->next) {
821 blocked_ops = g_list_remove(blocked_ops, op);
823 g_list_free(executed_ops);
825 processing_blocked_ops = FALSE;
830 nagios_get_metadata(
const char *
type,
char **output)
833 FILE *file_strm = NULL;
834 int start = 0, length = 0, read_len = 0;
838 file_strm = fopen(metadata_file,
"r");
839 if (file_strm == NULL) {
840 crm_err(
"Metadata file %s does not exist", metadata_file);
846 start = ftell(file_strm);
847 fseek(file_strm, 0L, SEEK_END);
848 length = ftell(file_strm);
849 fseek(file_strm, 0L, start);
855 crm_info(
"%s was not valid", metadata_file);
861 crm_trace(
"Reading %d bytes from file", length);
862 *output = calloc(1, (length + 1));
863 read_len = fread(*output, 1, length, file_strm);
864 if (read_len != length) {
865 crm_err(
"Calculated and read bytes differ: %d vs. %d",
882 const char *
class = op->standard;
884 if (op->
agent == NULL) {
885 crm_err(
"meta-data requested without specifying agent");
890 crm_err(
"meta-data requested for agent %s without specifying class",
900 crm_err(
"meta-data requested for %s, but could not determine class",
915 return action_exec_helper(op);
938 rc = action_get_metadata(op);
940 rc = action_exec_helper(op);
962 GList *standards = NULL;
963 GList *agents = NULL;
972 standards = g_list_append(standards,
974 g_list_free_full(agents, free);
981 standards = g_list_append(standards,
983 g_list_free_full(agents, free);
990 standards = g_list_append(standards,
992 g_list_free_full(agents, free);
1012 if ((standard == NULL)
1019 if (standard == NULL) {
1023 result = g_list_concat(tmp1, tmp2);
1030 result = g_list_concat(tmp1, tmp2);
1038 result = g_list_concat(tmp1, tmp2);
1068 GList *standards = NULL;
1069 GList *providers = NULL;
1071 gboolean rc = FALSE;
1072 gboolean has_providers = FALSE;
1075 for (iter = standards; iter != NULL; iter = iter->next) {
1076 if (
crm_str_eq(iter->data, standard, TRUE)) {
1089 if (has_providers == TRUE && provider != NULL) {
1091 for (iter = providers; iter != NULL; iter = iter->next) {
1092 if (
crm_str_eq(iter->data, provider, TRUE)) {
1097 }
else if (has_providers == FALSE && provider == NULL) {
1147 g_list_free(standards);
1148 g_list_free(providers);