static void GTMConvertCFDictEntryToLaunchDataDictEntry(const void *key,
                                                       const void *value,
                                                       void *context) {
  GTMCFToLDictContext *local_context = (GTMCFToLDictContext *)context;
  if (*(local_context->error)) return;

  launch_data_t launch_value
    = GTMLaunchDataCreateFromCFType(value, local_context->error);
  if (launch_value) {
    launch_data_t launch_key
      = GTMLaunchDataCreateFromCFType(key, local_context->error);
    if (launch_key) {
      bool goodInsert
        = launch_data_dict_insert(local_context->dict,
                                  launch_value,
                                  launch_data_get_string(launch_key));
      if (!goodInsert) {
        *(local_context->error)
          = GTMCFLaunchCreateUnlocalizedError(EINVAL,
                                              CFSTR("launch_data_dict_insert "
                                                    "failed key: %@ value: %@"),
                                              key,
                                              value);
        launch_data_free(launch_value);
      }
      launch_data_free(launch_key);
    }
  }
}
static launch_data_t GTMPerformOnLabel(const char *verb,
                                       CFStringRef jobLabel,
                                       CFErrorRef *error) {
  launch_data_t resp = NULL;
  launch_data_t label = GTMLaunchDataCreateFromCFType(jobLabel, error);
  if (*error == NULL) {
    launch_data_t msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
    launch_data_dict_insert(msg, label, verb);
    resp = launch_msg(msg);
    launch_data_free(msg);
    if (!resp) {
      *error = GTMCFLaunchCreateUnlocalizedError(errno, CFSTR(""));
    }
  }
  return resp;
}
Ejemplo n.º 3
0
bool
launchd_job_status(const char * job, LaunchJobStatus& info)
{
	launch_data_t resp;
	launch_data_t msg;

	msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
	if (msg == NULL) {
	    throw std::runtime_error("out of memory");
	}

	launch_data_dict_insert(msg, launch_data_new_string(job),
				LAUNCH_KEY_GETJOB);

	resp = launch_msg(msg);
	launch_data_free(msg);

	if (resp == NULL) {
	    LAUNCHD_MSG_ERR(job, LAUNCH_KEY_GETJOB);
	    return false;
	}

	switch (launch_data_get_type(resp)) {
	case LAUNCH_DATA_DICTIONARY:
	    fill_job_info(resp, NULL, &info);
	    launch_data_free(resp);
	    return true;

	case LAUNCH_DATA_ERRNO:
	    errno = launch_data_get_errno(resp);
	    launch_data_free(resp);
	    if (errno != 0) {
		LAUNCHD_MSG_ERR(job, LAUNCH_KEY_GETJOB);
		return false;
	    }

	    return true;

	default:
	    LAUNCHD_MSG_ERRMSG(job, LAUNCH_KEY_GETJOB,
		    "unexpected respose type %d",
		    launch_data_get_type(resp));
	    launch_data_free(resp);
	    return false;
	}

}