Skip to content

Commit

Permalink
Merge pull request #823 from gao-yan/services-op-return
Browse files Browse the repository at this point in the history
Fixes for the execution functions of services
  • Loading branch information
kgaillot committed Oct 29, 2015
2 parents 908071c + 9ccf764 commit 6df00e2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/services/dbus.c
Expand Up @@ -176,7 +176,7 @@ DBusPendingCall* pcmk_dbus_send(DBusMessage *msg, DBusConnection *connection,
return NULL;

} else if (pending == NULL) {
crm_err("No pending call found for %s", method);
crm_err("No pending call found for %s: Connection to System DBus may be closed", method);
return NULL;
}

Expand Down
15 changes: 8 additions & 7 deletions lib/services/services.c
Expand Up @@ -584,21 +584,22 @@ handle_duplicate_recurring(svc_action_t * op, void (*action_callback) (svc_actio
static gboolean
action_async_helper(svc_action_t * op) {
gboolean res = FALSE;
gboolean inflight = FALSE;

if (op->standard && strcasecmp(op->standard, "upstart") == 0) {
#if SUPPORT_UPSTART
res = upstart_job_exec(op, FALSE);
res = upstart_job_exec(op, FALSE, &inflight);
#endif
} else if (op->standard && strcasecmp(op->standard, "systemd") == 0) {
#if SUPPORT_SYSTEMD
res = systemd_unit_exec(op);
res = systemd_unit_exec(op, &inflight);
#endif
} else {
res = services_os_action_execute(op, FALSE);
res = services_os_action_execute(op, FALSE, &inflight);
}

/* keep track of ops that are in-flight to avoid collisions in the same namespace */
if (op->rsc && res) {
if (op->rsc && inflight) {
inflight_ops = g_list_append(inflight_ops, op);
}

Expand Down Expand Up @@ -703,14 +704,14 @@ services_action_sync(svc_action_t * op)
op->synchronous = true;
if (op->standard && strcasecmp(op->standard, "upstart") == 0) {
#if SUPPORT_UPSTART
rc = upstart_job_exec(op, TRUE);
rc = upstart_job_exec(op, TRUE, NULL);
#endif
} else if (op->standard && strcasecmp(op->standard, "systemd") == 0) {
#if SUPPORT_SYSTEMD
rc = systemd_unit_exec(op);
rc = systemd_unit_exec(op, NULL);
#endif
} else {
rc = services_os_action_execute(op, TRUE);
rc = services_os_action_execute(op, TRUE, NULL);
}
crm_trace(" > %s_%s_%d: %s = %d", op->rsc, op->action, op->interval, op->opaque->exec, op->rc);
if (op->stdout_data) {
Expand Down
13 changes: 11 additions & 2 deletions lib/services/services_linux.c
Expand Up @@ -589,16 +589,21 @@ action_synced_wait(svc_action_t * op, sigset_t mask)

}

/* Returns FALSE if 'op' should be free'd by the caller */
/* For an asynchronous 'op', returns FALSE if 'op' should be free'd by the caller */
/* For a synchronous 'op', returns FALSE if 'op' fails */
gboolean
services_os_action_execute(svc_action_t * op, gboolean synchronous)
services_os_action_execute(svc_action_t * op, gboolean synchronous, gboolean * inflight)
{
int stdout_fd[2];
int stderr_fd[2];
sigset_t mask;
sigset_t old_mask;
struct stat st;

if (inflight) {
*inflight = FALSE;
}

if (pipe(stdout_fd) < 0) {
crm_err("pipe() failed");
}
Expand Down Expand Up @@ -702,6 +707,10 @@ services_os_action_execute(svc_action_t * op, gboolean synchronous)
op->opaque->stderr_gsource = mainloop_add_fd(op->id,
G_PRIORITY_LOW,
op->opaque->stderr_fd, op, &stderr_callbacks);

if (inflight) {
*inflight = TRUE;
}
}

return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion lib/services/services_private.h
Expand Up @@ -44,7 +44,7 @@ struct svc_action_private_s {

GList *services_os_get_directory_list(const char *root, gboolean files, gboolean executable);

gboolean services_os_action_execute(svc_action_t * op, gboolean synchronous);
gboolean services_os_action_execute(svc_action_t * op, gboolean synchronous, gboolean * inflight);

GList *resources_os_list_lsb_agents(void);

Expand Down
31 changes: 24 additions & 7 deletions lib/services/systemd.c
Expand Up @@ -537,9 +537,10 @@ systemd_unit_exec_with_unit(svc_action_t * op, const char *unit)
} else if (pending) {
services_set_op_pending(op, pending);
return TRUE;
}

return FALSE;
} else {
return operation_finalize(op);
}

} else if (g_strcmp0(method, "start") == 0) {
FILE *file_strm = NULL;
Expand Down Expand Up @@ -619,8 +620,10 @@ systemd_unit_exec_with_unit(svc_action_t * op, const char *unit)
if(pending) {
services_set_op_pending(op, pending);
return TRUE;

} else {
return operation_finalize(op);
}
return FALSE;

} else {
DBusError error;
Expand Down Expand Up @@ -656,11 +659,17 @@ systemd_timeout_callback(gpointer p)
return FALSE;
}

/* For an asynchronous 'op', returns FALSE if 'op' should be free'd by the caller */
/* For a synchronous 'op', returns FALSE if 'op' fails */
gboolean
systemd_unit_exec(svc_action_t * op)
systemd_unit_exec(svc_action_t * op, gboolean * inflight)
{
char *unit = NULL;

if (inflight) {
*inflight = FALSE;
}

CRM_ASSERT(op);
CRM_ASSERT(systemd_init());
op->rc = PCMK_OCF_UNKNOWN_ERROR;
Expand All @@ -673,7 +682,7 @@ systemd_unit_exec(svc_action_t * op)
op->rc = PCMK_OCF_OK;

if (op->synchronous == FALSE) {
operation_finalize(op);
return operation_finalize(op);
}
return TRUE;
}
Expand All @@ -682,8 +691,16 @@ systemd_unit_exec(svc_action_t * op)
free(unit);

if (op->synchronous == FALSE) {
op->opaque->timerid = g_timeout_add(op->timeout + 5000, systemd_timeout_callback, op);
return TRUE;
if (op->opaque->pending) {
op->opaque->timerid = g_timeout_add(op->timeout + 5000, systemd_timeout_callback, op);
if (inflight) {
*inflight = TRUE;
}
return TRUE;

} else {
return operation_finalize(op);
}
}

return op->rc == PCMK_OCF_OK;
Expand Down
2 changes: 1 addition & 1 deletion lib/services/systemd.h
Expand Up @@ -17,7 +17,7 @@
*/

G_GNUC_INTERNAL GList *systemd_unit_listall(void);
G_GNUC_INTERNAL int systemd_unit_exec(svc_action_t * op);
G_GNUC_INTERNAL int systemd_unit_exec(svc_action_t * op, gboolean * inflight);
G_GNUC_INTERNAL gboolean systemd_unit_exists(const gchar * name);
G_GNUC_INTERNAL gboolean systemd_unit_running(const gchar * name);
G_GNUC_INTERNAL void systemd_cleanup(void);
17 changes: 14 additions & 3 deletions lib/services/upstart.c
Expand Up @@ -426,8 +426,10 @@ upstart_async_dispatch(DBusPendingCall *pending, void *user_data)
}
}

/* For an asynchronous 'op', returns FALSE if 'op' should be free'd by the caller */
/* For a synchronous 'op', returns FALSE if 'op' fails */
gboolean
upstart_job_exec(svc_action_t * op, gboolean synchronous)
upstart_job_exec(svc_action_t * op, gboolean synchronous, gboolean * inflight)
{
char *job = NULL;
int arg_wait = TRUE;
Expand All @@ -439,6 +441,10 @@ upstart_job_exec(svc_action_t * op, gboolean synchronous)
DBusMessage *reply = NULL;
DBusMessageIter iter, array_iter;

if (inflight) {
*inflight = FALSE;
}

op->rc = PCMK_OCF_UNKNOWN_ERROR;
CRM_ASSERT(upstart_init());

Expand Down Expand Up @@ -481,6 +487,9 @@ upstart_job_exec(svc_action_t * op, gboolean synchronous)
return op->rc == PCMK_OCF_OK;
} else if (pending) {
services_set_op_pending(op, pending);
if (inflight) {
*inflight = TRUE;
}
return TRUE;
}
return FALSE;
Expand Down Expand Up @@ -524,6 +533,9 @@ upstart_job_exec(svc_action_t * op, gboolean synchronous)

if(pending) {
services_set_op_pending(op, pending);
if (inflight) {
*inflight = TRUE;
}
return TRUE;
}
return FALSE;
Expand Down Expand Up @@ -567,8 +579,7 @@ upstart_job_exec(svc_action_t * op, gboolean synchronous)
}

if (op->synchronous == FALSE) {
operation_finalize(op);
return TRUE;
return operation_finalize(op);
}
return op->rc == PCMK_OCF_OK;
}
2 changes: 1 addition & 1 deletion lib/services/upstart.h
Expand Up @@ -24,7 +24,7 @@
# include "crm/services.h"

G_GNUC_INTERNAL GList *upstart_job_listall(void);
G_GNUC_INTERNAL int upstart_job_exec(svc_action_t * op, gboolean synchronous);
G_GNUC_INTERNAL int upstart_job_exec(svc_action_t * op, gboolean synchronous, gboolean * inflight);
G_GNUC_INTERNAL gboolean upstart_job_exists(const gchar * name);
G_GNUC_INTERNAL gboolean upstart_job_running(const gchar * name);
G_GNUC_INTERNAL void upstart_cleanup(void);
Expand Down

0 comments on commit 6df00e2

Please sign in to comment.