Esempio n. 1
0
gboolean
upstart_job_running(const gchar * name)
{
    bool running = FALSE;
    char *job = NULL;

    if(upstart_job_by_name(name, &job)) {
        char *path = get_first_instance(job);

        if (path) {
            char *state = pcmk_dbus_get_property(
                upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state");

            crm_info("State of %s: %s", name, state);
            if (state) {
                running = !g_strcmp0(state, "running");
            }
            free(state);
        }
        free(path);
    }

    free(job);
    crm_info("%s is%s running", name, running ? "" : " not");
    return running;
}
Esempio n. 2
0
/* For a synchronous 'op', returns FALSE if 'op' fails */
gboolean
upstart_job_exec(svc_action_t * op, gboolean synchronous)
{
    char *job = NULL;
    int arg_wait = TRUE;
    const char *arg_env = "pacemaker=1";
    const char *action = op->action;

    DBusError error;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;
    DBusMessageIter iter, array_iter;

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

    if (safe_str_eq(op->action, "meta-data")) {
        op->stdout_data = upstart_job_metadata(op->agent);
        op->rc = PCMK_OCF_OK;
        goto cleanup;
    }

    if(!upstart_job_by_name(op->agent, &job, op->timeout)) {
        crm_debug("Could not obtain job named '%s' to %s", op->agent, action);
        if (!g_strcmp0(action, "stop")) {
            op->rc = PCMK_OCF_OK;

        } else {
            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(action, "status")) {

        char *path = get_first_instance(job, op->timeout);

        op->rc = PCMK_OCF_NOT_RUNNING;
        if(path) {
            DBusPendingCall *pending = NULL;
            char *state = pcmk_dbus_get_property(
                upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state",
                op->synchronous?NULL:upstart_job_check, op,
                op->synchronous?NULL:&pending, op->timeout);

            free(job);
            free(path);

            if(op->synchronous) {
                upstart_job_check("state", state, op);
                free(state);
                return op->rc == PCMK_OCF_OK;
            } else if (pending) {
                services_set_op_pending(op, pending);
                services_add_inflight_op(op);
                return TRUE;
            }
            return FALSE;
        }
        goto cleanup;

    } else if (!g_strcmp0(action, "start")) {
        action = "Start";
    } else if (!g_strcmp0(action, "stop")) {
        action = "Stop";
    } else if (!g_strcmp0(action, "restart")) {
        action = "Restart";
    } else {
        op->rc = PCMK_OCF_UNIMPLEMENT_FEATURE;
        goto cleanup;
    }

    crm_debug("Calling %s for %s on %s", action, op->rsc, job);

    msg = dbus_message_new_method_call(BUS_NAME, // target for the method call
                                       job, // object to call on
                                       UPSTART_JOB_IFACE, // interface to call on
                                       action); // method name
    CRM_ASSERT(msg != NULL);

    dbus_message_iter_init_append (msg, &iter);

    CRM_LOG_ASSERT(dbus_message_iter_open_container (&iter,
                                                     DBUS_TYPE_ARRAY,
                                                     DBUS_TYPE_STRING_AS_STRING,
                                                     &array_iter));

    CRM_LOG_ASSERT(dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &arg_env));
    CRM_LOG_ASSERT(dbus_message_iter_close_container (&iter, &array_iter));

    CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg_wait, DBUS_TYPE_INVALID));

    if (op->synchronous == FALSE) {
        DBusPendingCall* pending = pcmk_dbus_send(msg, upstart_proxy, upstart_async_dispatch, op, op->timeout);
        free(job);

        if(pending) {
            services_set_op_pending(op, pending);
            services_add_inflight_op(op);
            return TRUE;
        }
        return FALSE;
    }

    dbus_error_init(&error);
    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, op->timeout);

    if(error.name) {
        if(!upstart_mask_error(op, error.name)) {
            crm_err("Could not issue %s for %s: %s (%s)", action, op->rsc, error.name, job);
        }

    } else if (!g_strcmp0(op->action, "stop")) {
        /* No return vaue */
        op->rc = PCMK_OCF_OK;

    } else if(!pcmk_dbus_type_check(reply, NULL, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) {
        crm_warn("Call to %s passed but return type was unexpected", op->action);
        op->rc = PCMK_OCF_OK;

    } else {
        const char *path = NULL;

        dbus_message_get_args (reply, NULL,
                               DBUS_TYPE_OBJECT_PATH, &path,
                               DBUS_TYPE_INVALID);
        crm_info("Call to %s passed: %s", op->action, path);
        op->rc = PCMK_OCF_OK;
    }


  cleanup:
    free(job);
    if(msg) {
        dbus_message_unref(msg);
    }

    if(reply) {
        dbus_message_unref(reply);
    }

    if (op->synchronous == FALSE) {
        return operation_finalize(op);
    }
    return op->rc == PCMK_OCF_OK;
}
Esempio n. 3
0
BOOL
pdhservice_translate(LPSTR object, LPSTR counter, LPSTR instance, 
                     BOOL is_english, LPSTR *new_object, LPSTR *new_counter, 
                     LPSTR *new_instance)
{
#if 0
#define DEBUG_SHOW_NAME
#endif
   BOOL instance_found = FALSE;
   BOOL counter_found = FALSE;
   BOOL object_found = FALSE;
   PPERF_DATA_BLOCK perf_data = NULL;
   DWORD buffer_size = TOTALBYTES;
   pdhservice_container *container1;
   pdhservice_container *container2;

   DENTER("pdhservice_translate");
   if (is_english) {
      container1 = &container_english;
      container2 = &container_system_lang;
   } else {
      container1 = &container_system_lang;
      container2 = &container_english;
   }

   // Allocate the buffer for the performance data.
   perf_data = (PPERF_DATA_BLOCK) malloc(buffer_size);
   if (perf_data != NULL) {
      PPERF_OBJECT_TYPE perf_object;
      DWORD i;

      while (RegQueryValueEx(HKEY_PERFORMANCE_DATA, "Global",
                             NULL, NULL, (LPBYTE) perf_data, 
                             &buffer_size) == ERROR_MORE_DATA) {
         /*
          * Increase buffer until it is big enough
          */
         buffer_size += BYTEINCREMENT;
         perf_data = (PPERF_DATA_BLOCK) realloc(perf_data, buffer_size);
      }

      /*
       * Process all objects
       */
      perf_object = get_first_object(perf_data);
      for(i = 0; !object_found && i < perf_data->NumObjectTypes; i++) {
         PPERF_COUNTER_DEFINITION perf_counter;

#ifdef DEBUG_SHOW_NAME
         printf("\nO %ld: %s\n", perf_object->ObjectNameTitleIndex,
                container1->names_array[perf_object->ObjectNameTitleIndex]);
         fflush(stdout);
#endif
         if (lstrcmp(container1->names_array[perf_object->ObjectNameTitleIndex], object) == 0) {
            *new_object = container2->names_array[perf_object->ObjectNameTitleIndex];
            object_found = TRUE;
         }

         perf_counter = get_first_counter(perf_object);
         if (perf_object->NumInstances > 0) {
            int k;

            /*
             * Process all instances
             */
            PPERF_INSTANCE_DEFINITION perf_instance = get_first_instance(perf_object);
            for (k = 0; !instance_found && k < perf_object->NumInstances; k++) {
               PPERF_COUNTER_DEFINITION perf_curinst;
               DWORD j;
               WCHAR wide_string[1024];


#ifdef DEBUG_SHOW_NAME
               printf( "\n\tI %S: \n", 
                      (char *)((PBYTE)perf_instance + perf_instance->NameOffset));
               fflush(stdout);
#endif
               /* The instance seems to be stored as multibyte string !? */
               mbstowcs(wide_string, instance, sizeof(wide_string)/sizeof(WCHAR));
               if (object_found && wcscmp((wchar_t *)((PBYTE)perf_instance + perf_instance->NameOffset), wide_string) == 0) {
                  *new_instance = instance;
                  instance_found = TRUE;
               } else if (object_found && lstrcmp("*", instance) == 0) {
                  *new_instance = "*";
                  instance_found = TRUE;
               }
               perf_curinst = perf_counter;
               // Retrieve all counters.

               for (j = 0; !counter_found && j < perf_object->NumCounters; j++) {
#ifdef DEBUG_SHOW_NAME
                    printf("\t\tC %ld: %s\n", 
                        perf_curinst->CounterNameTitleIndex,
                        container1->names_array[perf_curinst->CounterNameTitleIndex]);
                    fflush(stdout);
#endif

                  if (instance_found && lstrcmp(container1->names_array[perf_curinst->CounterNameTitleIndex], counter) == 0) {
                     *new_counter = container2->names_array[perf_curinst->CounterNameTitleIndex];
                     counter_found = TRUE;
                  }

                  perf_curinst = get_next_counter(perf_curinst);             
               }

               perf_instance = get_next_instance(perf_instance);
            }
         } else {
            WORD j;
            PPERF_COUNTER_BLOCK counter_block = (PPERF_COUNTER_BLOCK) ((PBYTE)perf_object +
                                                perf_object->DefinitionLength );

            for (j = 0; !counter_found && j < perf_object->NumCounters; j++) {
               // Display the counter by index and name.

#ifdef DEBUG_SHOW_NAME
               printf("\tC %ld: %s\n", perf_counter->CounterNameTitleIndex,
                      container1->names_array[perf_counter->CounterNameTitleIndex] != NULL ? 
                      container1->names_array[perf_counter->CounterNameTitleIndex] : "NULL");
               fflush(stdout);
#endif

               if (object_found && lstrcmp(container1->names_array[perf_counter->CounterNameTitleIndex], counter) == 0) {
                  *new_counter = container2->names_array[perf_counter->CounterNameTitleIndex];
                  counter_found = TRUE;
               }
                
               // Get the next counter.
               perf_counter = get_next_counter(perf_counter);
            }
         }
         
         // Get the next object type.

         perf_object = get_next_object(perf_object);
      }
      free(perf_data);
      perf_data = NULL;
   }
   DEXIT;
   return counter_found && object_found;
}