예제 #1
0
DBusMessage *
dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
{
  DBusPendingCall *pending;
  SpiReentrantCallClosure *closure;
  const char *unique_name = dbus_bus_get_unique_name (bus);
  const char *destination = dbus_message_get_destination (message);
  struct timeval tv;
  DBusMessage *ret;

  if (unique_name && destination &&
      strcmp (destination, unique_name) != 0)
    return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);

  closure = g_new0 (SpiReentrantCallClosure, 1);
  closure->reply = NULL;
  atspi_dbus_connection_setup_with_g_main(bus, NULL);
  if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
      return NULL;
  if (!pending)
    return NULL;
  dbus_pending_call_set_notify (pending, set_reply, (void *) closure, g_free);

  closure->reply = NULL;
  gettimeofday (&tv, NULL);
  dbus_pending_call_ref (pending);
  while (!closure->reply)
    {
      if (!dbus_connection_read_write_dispatch (bus, dbind_timeout) ||
          time_elapsed (&tv) > dbind_timeout)
        {
          dbus_pending_call_unref (pending);
          return NULL;
        }
    }
  
  ret = closure->reply;
  dbus_pending_call_unref (pending);
  return ret;
}
예제 #2
0
파일: systemd.c 프로젝트: tradej/pacemaker
gboolean
systemd_unit_exec_with_unit(svc_action_t * op, const char *unit)
{
    const char *method = op->action;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;

    if (unit == NULL) {
        crm_debug("Could not obtain unit named '%s'", op->agent);
        op->rc = PCMK_OCF_NOT_INSTALLED;
        op->status = PCMK_LRM_OP_NOT_INSTALLED;
        goto cleanup;
    }

    if (safe_str_eq(op->action, "monitor") || safe_str_eq(method, "status")) {
        DBusPendingCall *pending = NULL;
        char *state;

        state = pcmk_dbus_get_property(systemd_proxy, BUS_NAME, unit,
                                       BUS_NAME ".Unit", "ActiveState",
                                       op->synchronous?NULL:systemd_unit_check,
                                       op, op->synchronous?NULL:&pending, op->timeout);
        if (op->synchronous) {
            systemd_unit_check("ActiveState", state, op);
            free(state);
            return op->rc == PCMK_OCF_OK;
        } else if (pending) {
            dbus_pending_call_ref(pending);
            services_set_op_pending(op, pending);
            return TRUE;
        }

        return FALSE;

    } else if (g_strcmp0(method, "start") == 0) {
        FILE *file_strm = NULL;
        char *override_dir = crm_strdup_printf("%s/%s.service.d", SYSTEMD_OVERRIDE_ROOT, op->agent);
        char *override_file = crm_strdup_printf("%s/%s.service.d/50-pacemaker.conf", SYSTEMD_OVERRIDE_ROOT, op->agent);

        method = "StartUnit";
        crm_build_path(override_dir, 0755);

        file_strm = fopen(override_file, "w");
        if (file_strm != NULL) {
            /* TODO: Insert the start timeout in too */
            char *override = crm_strdup_printf(
                "[Unit]\n"
                "Description=Cluster Controlled %s\n"
                "Before=pacemaker.service\n"
                "\n"
                "[Service]\n"
                "Restart=no\n",
                op->agent);

            int rc = fprintf(file_strm, "%s\n", override);

            free(override);
            if (rc < 0) {
                crm_perror(LOG_ERR, "Cannot write to systemd override file %s", override_file);
            }

        } else {