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);
754 blocked_ops = g_list_append(blocked_ops, op);
758 return action_exec_helper(op);
768 static gboolean processing_blocked_ops = FALSE;
776 for (gIter = inflight_ops; gIter != NULL; gIter = gIter->next) {
787 handle_blocked_ops(
void)
789 GList *executed_ops = NULL;
792 gboolean res = FALSE;
794 if (processing_blocked_ops) {
799 processing_blocked_ops = TRUE;
803 for (gIter = blocked_ops; gIter != NULL; gIter = gIter->next) {
808 executed_ops = g_list_append(executed_ops, op);
809 res = action_exec_helper(op);
818 for (gIter = executed_ops; gIter != NULL; gIter = gIter->next) {
820 blocked_ops = g_list_remove(blocked_ops, op);
822 g_list_free(executed_ops);
824 processing_blocked_ops = FALSE;
829 nagios_get_metadata(
const char *
type,
char **output)
832 FILE *file_strm = NULL;
833 int start = 0, length = 0, read_len = 0;
837 file_strm = fopen(metadata_file,
"r");
838 if (file_strm == NULL) {
839 crm_err(
"Metadata file %s does not exist", metadata_file);
845 start = ftell(file_strm);
846 fseek(file_strm, 0L, SEEK_END);
847 length = ftell(file_strm);
848 fseek(file_strm, 0L, start);
854 crm_info(
"%s was not valid", metadata_file);
860 crm_trace(
"Reading %d bytes from file", length);
861 *output = calloc(1, (length + 1));
862 read_len = fread(*output, 1, length, file_strm);
863 if (read_len != length) {
864 crm_err(
"Calculated and read bytes differ: %d vs. %d",
881 const char *
class = op->standard;
883 if (op->
agent == NULL) {
884 crm_err(
"meta-data requested without specifying agent");
889 crm_err(
"meta-data requested for agent %s without specifying class",
899 crm_err(
"meta-data requested for %s, but could not determine class",
914 return action_exec_helper(op);
937 rc = action_get_metadata(op);
939 rc = action_exec_helper(op);
961 GList *standards = NULL;
962 GList *agents = NULL;
971 standards = g_list_append(standards,
973 g_list_free_full(agents, free);
980 standards = g_list_append(standards,
982 g_list_free_full(agents, free);
989 standards = g_list_append(standards,
991 g_list_free_full(agents, free);
1011 if ((standard == NULL)
1018 if (standard == NULL) {
1022 result = g_list_concat(tmp1, tmp2);
1029 result = g_list_concat(tmp1, tmp2);
1037 result = g_list_concat(tmp1, tmp2);
1067 GList *standards = NULL;
1068 GList *providers = NULL;
1070 gboolean rc = FALSE;
1071 gboolean has_providers = FALSE;
1074 for (iter = standards; iter != NULL; iter = iter->next) {
1075 if (
crm_str_eq(iter->data, standard, TRUE)) {
1088 if (has_providers == TRUE && provider != NULL) {
1090 for (iter = providers; iter != NULL; iter = iter->next) {
1091 if (
crm_str_eq(iter->data, provider, TRUE)) {
1096 }
else if (has_providers == FALSE && provider == NULL) {
1146 g_list_free(standards);
1147 g_list_free(providers);
gboolean services_action_cancel(const char *name, const char *action, guint interval_ms)
Cancel a recurring action.
#define CRM_CHECK(expr, failure_action)
void services_action_free(svc_action_t *op)
gboolean services__ocf_agent_exists(const char *provider, const char *agent)
gboolean services_action_kick(const char *name, const char *action, guint interval_ms)
gboolean upstart_job_exists(const char *name)
gboolean mainloop_child_kill(pid_t pid)
mainloop_io_t * stderr_gsource
const char * resources_find_service_class(const char *agent)
Find first service class that can provide a specified agent.
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)
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
void(* fork_callback)(svc_action_t *op)
gboolean services_action_async_fork_notify(svc_action_t *op, void(*action_callback)(svc_action_t *), void(*action_fork_callback)(svc_action_t *))
GList * services_os_get_directory_list(const char *root, gboolean files, gboolean executable)
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.
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
gboolean services_os_action_execute(svc_action_t *op)
G_GNUC_INTERNAL GList * resources_os_list_nagios_agents(void)
gboolean upstart_job_exec(svc_action_t *op)
gboolean is_op_blocked(const char *rsc)
Wrappers for and extensions to glib mainloop.
char * services__lsb_agent_path(const char *agent)
int services__get_lsb_metadata(const char *type, char **output)
void services_action_cleanup(svc_action_t *op)
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...)
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 operation_finalize(svc_action_t *op)
gboolean services_action_sync(svc_action_t *op)
G_GNUC_INTERNAL gboolean services__nagios_agent_exists(const char *agent)
gboolean systemd_unit_exists(const char *name)
#define PCMK_RESOURCE_CLASS_SERVICE
#define crm_trace(fmt, args...)
void(* callback)(svc_action_t *op)
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
GList * resources_list_providers(const char *standard)
Get a list of providers.
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
GList * systemd_unit_listall(void)
int services_action_user(svc_action_t *op, const char *user)
Set the user and group that an action will execute as.
void services_add_inflight_op(svc_action_t *op)
void services_untrack_op(svc_action_t *op)
#define PCMK_RESOURCE_CLASS_NAGIOS
#define PCMK_RESOURCE_CLASS_LSB
#define NAGIOS_PLUGIN_DIR
GList * resources_list_standards(void)
#define crm_err(fmt, args...)
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_UPSTART
gboolean resources_agent_exists(const char *standard, const char *provider, const char *agent)
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
mainloop_io_t * stdout_gsource
#define XML_ATTR_CRM_VERSION
gboolean services_alert_async(svc_action_t *action, void(*cb)(svc_action_t *op))
Execute an alert agent action.
void mainloop_del_fd(mainloop_io_t *client)
#define safe_str_eq(a, b)
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
gboolean systemd_unit_exec(svc_action_t *op)
#define crm_info(fmt, args...)
#define NAGIOS_METADATA_DIR
char * generate_op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key.
bool services__lsb_agent_exists(const char *agent)
enum crm_ais_msg_types type