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);
#define CRM_CHECK(expr, failure_action)
void(* callback)(svc_action_t *op)
gboolean services__ocf_agent_exists(const char *provider, const char *agent)
GList * resources_list_providers(const char *standard)
Get a list of providers.
gboolean services_action_async_fork_notify(svc_action_t *op, void(*action_callback)(svc_action_t *), void(*action_fork_callback)(svc_action_t *))
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
gboolean upstart_job_exists(const char *name)
gboolean mainloop_child_kill(pid_t pid)
mainloop_io_t * stderr_gsource
GList * resources_os_list_ocf_agents(const char *provider)
GList * resources_os_list_ocf_providers(void)
#define PCMK_RESOURCE_CLASS_SYSTEMD
gboolean recurring_action_timer(gpointer data)
int services__get_nagios_metadata(const char *type, char **output)
GList * services_os_get_directory_list(const char *root, gboolean files, gboolean executable)
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
gboolean services_os_action_execute(svc_action_t *op)
gboolean upstart_job_exec(svc_action_t *op)
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
gboolean is_op_blocked(const char *rsc)
Wrappers for and extensions to glib mainloop.
char * services__lsb_agent_path(const char *agent)
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
int services__get_lsb_metadata(const char *type, char **output)
GList * services__list_lsb_agents(void)
enum svc_action_flags flags
#define crm_warn(fmt, args...)
#define PCMK_RESOURCE_CLASS_OCF
gboolean cancel_recurring_action(svc_action_t *op)
svc_action_private_t * opaque
GList * upstart_job_listall(void)
#define crm_debug(fmt, args...)
gboolean operation_finalize(svc_action_t *op)
svc_action_t * services_alert_create(const char *id, const char *exec, int timeout, GHashTable *params, int sequence, void *cb_data)
Create an alert agent action.
gboolean systemd_unit_exists(const char *name)
#define PCMK_RESOURCE_CLASS_SERVICE
#define crm_trace(fmt, args...)
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
gboolean services__nagios_agent_exists(const char *name)
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
gboolean services_action_sync(svc_action_t *op)
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
GList * systemd_unit_listall(void)
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
void services_add_inflight_op(svc_action_t *op)
GList * resources_list_standards(void)
void services_untrack_op(svc_action_t *op)
GList * get_directory_list(const char *root, gboolean files, gboolean executable)
Get a list of files or directories in a given path.
#define PCMK_RESOURCE_CLASS_NAGIOS
#define PCMK_RESOURCE_CLASS_LSB
#define NAGIOS_PLUGIN_DIR
svc_action_t * resources_action_create(const char *name, const char *standard, const char *provider, const char *agent, const char *action, guint interval_ms, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
#define crm_err(fmt, args...)
#define PCMK_RESOURCE_CLASS_UPSTART
GList * services__list_nagios_agents(void)
int services_action_user(svc_action_t *op, const char *user)
Set the user and group that an action will execute as.
mainloop_io_t * stdout_gsource
#define XML_ATTR_CRM_VERSION
void mainloop_del_fd(mainloop_io_t *client)
void services_action_cleanup(svc_action_t *op)
void services_action_free(svc_action_t *op)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
void(* fork_callback)(svc_action_t *op)
gboolean systemd_unit_exec(svc_action_t *op)
#define crm_info(fmt, args...)
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
bool services__lsb_agent_exists(const char *agent)