示例#1
0
gboolean
decodeNVpair(const char *srcstring, char separator, char **name, char **value)
{
	int lpc = 0;
	int len = 0;
	const char *temp = NULL;

	CRM_ASSERT(name != NULL && value != NULL);
	*name = NULL;
	*value = NULL;

	crm_debug_4("Attempting to decode: [%s]", srcstring);
	if (srcstring != NULL) {
		len = strlen(srcstring);
		while(lpc <= len) {
			if (srcstring[lpc] == separator) {
				crm_malloc0(*name, lpc+1);
				if(*name == NULL) {
					break; /* and return FALSE */
				}
				strncpy(*name, srcstring, lpc);
				(*name)[lpc] = '\0';

/* this sucks but as the strtok manpage says..
 * it *is* a bug
 */
				len = len-lpc; len--;
				if(len <= 0) {
					*value = NULL;
				} else {

					crm_malloc0(*value, len+1);
					if(*value == NULL) {
						crm_free(*name);
						break; /* and return FALSE */
					}
					temp = srcstring+lpc+1;
					strncpy(*value, temp, len);
					(*value)[len] = '\0';
				}
				return TRUE;
			}
			lpc++;
		}
	}

	if(*name != NULL) {
		crm_free(*name);
	}
	*name = NULL;
	*value = NULL;
    
	return FALSE;
}
示例#2
0
crm_graph_t *
unpack_graph(xmlNode * xml_graph, const char *reference)
{
/*
  <transition_graph>
  <synapse>
  <action_set>
  <rsc_op id="2"
  ... 
  <inputs>
  <rsc_op id="2"
  ... 
*/
    crm_graph_t *new_graph = NULL;
    const char *t_id = NULL;
    const char *time = NULL;
    xmlNode *synapse = NULL;

    crm_malloc0(new_graph, sizeof(crm_graph_t));

    new_graph->id = -1;
    new_graph->abort_priority = 0;
    new_graph->network_delay = -1;
    new_graph->transition_timeout = -1;
    new_graph->stonith_timeout = -1;
    new_graph->completion_action = tg_done;

    new_graph->migrating = g_hash_table_new_full(crm_str_hash, g_str_equal,
                                                 g_hash_destroy_str, g_hash_destroy_str);

    if (reference) {
        new_graph->source = crm_strdup(reference);
    } else {
        new_graph->source = crm_strdup("unknown");
    }

    if (xml_graph != NULL) {
        t_id = crm_element_value(xml_graph, "transition_id");
        CRM_CHECK(t_id != NULL, crm_free(new_graph);
                  return NULL);
        new_graph->id = crm_parse_int(t_id, "-1");

        time = crm_element_value(xml_graph, "cluster-delay");
        CRM_CHECK(time != NULL, crm_free(new_graph);
                  return NULL);
        new_graph->network_delay = crm_get_msec(time);

        time = crm_element_value(xml_graph, "stonith-timeout");
        if (time == NULL) {
            new_graph->stonith_timeout = new_graph->network_delay;
        } else {
            new_graph->stonith_timeout = crm_get_msec(time);
        }

        t_id = crm_element_value(xml_graph, "batch-limit");
        new_graph->batch_limit = crm_parse_int(t_id, "0");

        t_id = crm_element_value(xml_graph, "migration-limit");
        new_graph->migration_limit = crm_parse_int(t_id, "-1");
    }
示例#3
0
static crm_node_t *crm_new_peer(unsigned int id, const char *uname)
{
    crm_node_t *node = NULL;
    CRM_CHECK(uname != NULL || id > 0, return NULL);

    crm_debug("Creating entry for node %s/%u", uname, id);
    
    crm_malloc0(node, sizeof(crm_node_t));
    node->state = crm_strdup("unknown");

    if(id > 0) {
	node->id = id;
	crm_info("Node %s now has id: %u", crm_str(uname), id);
	g_hash_table_replace(crm_peer_id_cache, GUINT_TO_POINTER(node->id), node);
    }
    
    if(uname) {
	node->uname = crm_strdup(uname);
	CRM_ASSERT(node->uname != NULL);
	crm_info("Node %u is now known as %s", id, node->uname);
	g_hash_table_replace(crm_peer_cache, node->uname, node);

	if(is_openais_cluster()) {
	    node->uuid = crm_strdup(node->uname);
	}

	if(crm_status_callback) {
	    crm_status_callback(crm_status_uname, node, NULL);
	}	
    }
    
    return node;
}
示例#4
0
static void
save_cib_contents(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data)
{
    char *id = user_data;

    register_fsa_error_adv(C_FSA_INTERNAL, I_ERROR, NULL, NULL, __FUNCTION__);
    CRM_CHECK(id != NULL, return);

    if (rc == cib_ok) {
        int len = 15;
        char *filename = NULL;

        len += strlen(id);
        len += strlen(PE_STATE_DIR);

        crm_malloc0(filename, len);
        CRM_CHECK(filename != NULL, return);

        sprintf(filename, PE_STATE_DIR "/pe-core-%s.bz2", id);
        if (write_xml_file(output, filename, TRUE) < 0) {
            crm_err("Could not save CIB contents after PE crash to %s", filename);
        } else {
            crm_notice("Saved CIB contents after PE crash to %s", filename);
        }

        crm_free(filename);
    }
示例#5
0
static async_command_t *create_async_command(xmlNode *msg) 
{
    async_command_t *cmd = NULL;
    xmlNode *op = get_xpath_object("//@"F_STONITH_ACTION, msg, LOG_ERR);
    const char *action = crm_element_value(op, F_STONITH_ACTION);

    CRM_CHECK(action != NULL, crm_log_xml_warn(msg, "NoAction"); return NULL);

    crm_log_xml_trace(msg, "Command");
    crm_malloc0(cmd, sizeof(async_command_t));
    crm_element_value_int(msg, F_STONITH_CALLID,   &(cmd->id));
    crm_element_value_int(msg, F_STONITH_CALLOPTS, &(cmd->options));
    crm_element_value_int(msg, F_STONITH_TIMEOUT,  &(cmd->timeout));

    cmd->timeout *= 1000;
    cmd->origin = crm_element_value_copy(msg, F_ORIG);
    cmd->remote = crm_element_value_copy(msg, F_STONITH_REMOTE);
    cmd->client = crm_element_value_copy(msg, F_STONITH_CLIENTID);
    cmd->op     = crm_element_value_copy(msg, F_STONITH_OPERATION);
    cmd->action = crm_strdup(action);
    cmd->victim = crm_element_value_copy(op, F_STONITH_TARGET);
    cmd->done   = st_child_done;

    CRM_CHECK(cmd->op != NULL, crm_log_xml_warn(msg, "NoOp"); free_async_command(cmd); return NULL);
    CRM_CHECK(cmd->client != NULL, crm_log_xml_warn(msg, "NoClient"));
    return cmd;
}
示例#6
0
gboolean
decode_transition_magic(
	const char *magic, char **uuid, int *transition_id, int *action_id,
	int *op_status, int *op_rc, int *target_rc)
{
    int res = 0;
    char *key = NULL;
    gboolean result = TRUE;

    CRM_CHECK(magic != NULL, return FALSE);
    CRM_CHECK(op_rc != NULL, return FALSE);
    CRM_CHECK(op_status != NULL, return FALSE);
    
    crm_malloc0(key, strlen(magic));
    res = sscanf(magic, "%d:%d;%s", op_status, op_rc, key);
    if(res != 3) {
	crm_crit("Only found %d items in: %s", res, magic);
	result = FALSE;
	goto bail;
    }
    
    CRM_CHECK(decode_transition_key(key, uuid, transition_id, action_id, target_rc),
	      result = FALSE;
	      goto bail;
	);
示例#7
0
static gboolean
attrd_connect(IPC_Channel * channel, gpointer user_data)
{
    attrd_client_t *new_client = NULL;

    crm_trace("Connecting channel");

    if (channel == NULL) {
        crm_err("Channel was NULL");
        return FALSE;

    } else if (channel->ch_status != IPC_CONNECT) {
        crm_err("Channel was disconnected");
        return FALSE;
    } else if (need_shutdown) {
        crm_info("Ignoring connection request during shutdown");
        return FALSE;
    }

    crm_malloc0(new_client, sizeof(attrd_client_t));
    new_client->channel = channel;

    crm_trace("Created channel %p for channel %s", new_client, new_client->id);

/* 		channel->ops->set_recv_qlen(channel, 100); */
/* 		channel->ops->set_send_qlen(channel, 400); */

    new_client->source =
        G_main_add_IPC_Channel(G_PRIORITY_DEFAULT, channel, FALSE, attrd_ipc_callback, new_client,
                               attrd_connection_destroy);

    crm_trace("Client %s connected", new_client->id);

    return TRUE;
}
示例#8
0
gboolean
do_init(void)
{
    GCHSource *src = NULL;

    crm_malloc0(admin_uuid, 11);
    if (admin_uuid != NULL) {
        snprintf(admin_uuid, 10, "%d", getpid());
        admin_uuid[10] = '\0';
    }

    src = init_client_ipc_comms(CRM_SYSTEM_CRMD, admin_msg_callback, NULL, &crmd_channel);

    if (DO_RESOURCE || DO_RESOURCE_LIST || DO_NODE_LIST) {
        return TRUE;

    } else if (crmd_channel != NULL) {
        send_hello_message(crmd_channel, admin_uuid, crm_system_name, "0", "1");

        set_IPC_Channel_dnotify(src, crmadmin_ipc_connection_destroy);

        return TRUE;
    }
    return FALSE;
}
示例#9
0
char *
generateReference(const char *custom1, const char *custom2)
{

	const char *local_cust1 = custom1;
	const char *local_cust2 = custom2;
	int reference_len = 4;
	char *since_epoch = NULL;

	reference_len += 20; /* too big */
	reference_len += 40; /* too big */
	
	if(local_cust1 == NULL) { local_cust1 = "_empty_"; }
	reference_len += strlen(local_cust1);
	
	if(local_cust2 == NULL) { local_cust2 = "_empty_"; }
	reference_len += strlen(local_cust2);
	
	crm_malloc0(since_epoch, reference_len);

	if(since_epoch != NULL) {
		sprintf(since_epoch, "%s-%s-%ld-%u",
			local_cust1, local_cust2,
			(unsigned long)time(NULL), ref_counter++);
	}

	return since_epoch;
}
示例#10
0
文件: io.c 项目: huiser/pacemaker
static gboolean
validate_on_disk_cib(const char *filename, xmlNode ** on_disk_cib)
{
    int s_res = -1;
    struct stat buf;
    gboolean passed = TRUE;
    xmlNode *root = NULL;

    CRM_ASSERT(filename != NULL);

    s_res = stat(filename, &buf);
    if (s_res == 0) {
        char *sigfile = NULL;
        size_t fnsize;

        crm_debug_2("Reading cluster configuration from: %s", filename);
        root = filename2xml(filename);

        fnsize = strlen(filename) + 5;
        crm_malloc0(sigfile, fnsize);
        snprintf(sigfile, fnsize, "%s.sig", filename);
        if (validate_cib_digest(root, sigfile) == FALSE) {
            passed = FALSE;
        }
        crm_free(sigfile);
    }

    if (on_disk_cib != NULL) {
        *on_disk_cib = root;
    } else {
        free_xml(root);
    }

    return passed;
}
示例#11
0
static char *get_heartbeat_uuid(uint32_t unused, const char *uname) 
{
    char *uuid_calc = NULL;
#if SUPPORT_HEARTBEAT
    cl_uuid_t uuid_raw;
    const char *unknown = "00000000-0000-0000-0000-000000000000";

    if (heartbeat_cluster == NULL) {
        crm_warn("No connection to heartbeat, using uuid=uname");
        return NULL;
    }

    if (heartbeat_cluster->llc_ops->get_uuid_by_name(heartbeat_cluster, uname, &uuid_raw) ==
        HA_FAIL) {
        crm_err("get_uuid_by_name() call failed for host %s", uname);
        crm_free(uuid_calc);
        return NULL;
    }

    crm_malloc0(uuid_calc, 50);
    cl_uuid_unparse(&uuid_raw, uuid_calc);

    if (safe_str_eq(uuid_calc, unknown)) {
        crm_warn("Could not calculate UUID for %s", uname);
        crm_free(uuid_calc);
        return NULL;
    }
#endif
    return uuid_calc;
}
示例#12
0
cib_t*
cib_native_new (void)
{
	cib_native_opaque_t *native = NULL;
	cib_t *cib = cib_new_variant();
	
	crm_malloc0(native, sizeof(cib_native_opaque_t));
	
	cib->variant = cib_native;
	cib->variant_opaque = native;

	native->command_channel   = NULL;
	native->callback_channel  = NULL;
	
	/* assign variant specific ops*/
	cib->cmds->variant_op = cib_native_perform_op;
	cib->cmds->signon     = cib_native_signon;
	cib->cmds->signon_raw = cib_native_signon_raw;
	cib->cmds->signoff    = cib_native_signoff;
	cib->cmds->free       = cib_native_free;
	cib->cmds->inputfd    = cib_native_inputfd;

	cib->cmds->register_notification = cib_native_register_notification;
	cib->cmds->set_connection_dnotify = cib_native_set_connection_dnotify;

	return cib;
}
示例#13
0
static gboolean
count_migrating(crm_graph_t * graph, synapse_t * synapse)
{
    GListPtr lpc = NULL;

    CRM_CHECK(synapse != NULL, return FALSE);

    for (lpc = synapse->actions; lpc != NULL; lpc = lpc->next) {
        crm_action_t *action = (crm_action_t *) lpc->data;

        const char *task = NULL;

        if (action->type != action_type_rsc) {
            continue;
        }

        task = crm_element_value(action->xml, XML_LRM_ATTR_TASK);

        if (crm_str_eq(task, CRMD_ACTION_MIGRATE, TRUE)
            || crm_str_eq(task, CRMD_ACTION_MIGRATED, TRUE)) {
            const char *node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID);

            int *counter = g_hash_table_lookup(graph->migrating, node);

            if (counter == NULL) {
                crm_malloc0(counter, sizeof(int));
                g_hash_table_insert(graph->migrating, crm_strdup(node), counter);
            }

            (*counter)++;
        }
    }
    return TRUE;
}
示例#14
0
enum cib_errors
cib_update_counter(xmlNode * xml_obj, const char *field, gboolean reset)
{
    char *new_value = NULL;
    char *old_value = NULL;
    int int_value = -1;

    if (reset == FALSE && crm_element_value(xml_obj, field) != NULL) {
        old_value = crm_element_value_copy(xml_obj, field);
    }
    if (old_value != NULL) {
        crm_malloc0(new_value, 128);
        int_value = atoi(old_value);
        sprintf(new_value, "%d", ++int_value);
    } else {
        new_value = crm_strdup("1");
    }

    crm_debug_4("%s %d(%s)->%s", field, int_value, crm_str(old_value), crm_str(new_value));
    crm_xml_add(xml_obj, field, new_value);

    crm_free(new_value);
    crm_free(old_value);

    return cib_ok;
}
示例#15
0
char *
crm_strdup_fn(const char *src, const char *file, const char *fn, int line)
{
	char *dup = NULL;
	CRM_CHECK(src != NULL, return NULL);
	crm_malloc0(dup, strlen(src) + 1);
	return strcpy(dup, src);
}
示例#16
0
ha_msg_input_t *
new_ha_msg_input(xmlNode *orig) 
{
	ha_msg_input_t *input_copy = NULL;
	crm_malloc0(input_copy, sizeof(ha_msg_input_t));
	input_copy->msg = orig;
	input_copy->xml = get_message_xml(input_copy->msg, F_CRM_DATA);
	return input_copy;
}
示例#17
0
static gboolean
te_fence_node(crm_graph_t *graph, crm_action_t *action)
{
	const char *id = NULL;
	const char *uuid = NULL;
	const char *target = NULL;
	const char *type = NULL;
	stonith_ops_t * st_op = NULL;
	
	id = ID(action->xml);
	target = crm_element_value(action->xml, XML_LRM_ATTR_TARGET);
	uuid = crm_element_value(action->xml, XML_LRM_ATTR_TARGET_UUID);
	type = g_hash_table_lookup(action->params, crm_meta_name("stonith_action"));
	
	CRM_CHECK(id != NULL,
		  crm_log_xml_warn(action->xml, "BadAction");
		  return FALSE);
	CRM_CHECK(uuid != NULL,
		  crm_log_xml_warn(action->xml, "BadAction");
		  return FALSE);
	CRM_CHECK(type != NULL,
		  crm_log_xml_warn(action->xml, "BadAction");
		  return FALSE);
	CRM_CHECK(target != NULL,
		  crm_log_xml_warn(action->xml, "BadAction");
		  return FALSE);

	te_log_action(LOG_INFO,
		      "Executing %s fencing operation (%s) on %s (timeout=%d)",
		      type, id, target,
		      transition_graph->transition_timeout / 2);

	/* Passing NULL means block until we can connect... */
	te_connect_stonith(NULL);
	
	crm_malloc0(st_op, sizeof(stonith_ops_t));
	if(safe_str_eq(type, "poweroff")) {
		st_op->optype = POWEROFF;
	} else {
		st_op->optype = RESET;
	}
	
	st_op->timeout = transition_graph->transition_timeout / 2;
	st_op->node_name = crm_strdup(target);
	st_op->node_uuid = crm_strdup(uuid);
	
	st_op->private_data = generate_transition_key(
		transition_graph->id, action->id, te_uuid);
	
	CRM_ASSERT(stonithd_input_IPC_channel() != NULL);
		
	if (ST_OK != stonithd_node_fence( st_op )) {
		crm_err("Cannot fence %s: stonithd_node_fence() call failed ",
			target);
	}
	return TRUE;
}
示例#18
0
void
print_xml_diff(FILE * where, xmlNode * diff)
{
    char *buffer = NULL;
    xmlNode *child = NULL;
    int max = 1024, len = 0;
    gboolean is_first = TRUE;
    xmlNode *added = find_xml_node(diff, "diff-added", FALSE);
    xmlNode *removed = find_xml_node(diff, "diff-removed", FALSE);

    is_first = TRUE;
    for (child = __xml_first_child(removed); child != NULL; child = __xml_next(child)) {
        len = 0;
        max = 1024;
        crm_free(buffer);
        crm_malloc0(buffer, max);

        if (is_first) {
            is_first = FALSE;
        } else {
            fprintf(where, " --- \n");
        }

        CRM_CHECK(dump_data_element(0, &buffer, &max, &len, "-", child, TRUE) >= 0, continue);
        fprintf(where, "%s", buffer);
    }

    is_first = TRUE;
    for (child = __xml_first_child(added); child != NULL; child = __xml_next(child)) {
        len = 0;
        max = 1024;
        crm_free(buffer);
        crm_malloc0(buffer, max);

        if (is_first) {
            is_first = FALSE;
        } else {
            fprintf(where, " +++ \n");
        }

        CRM_CHECK(dump_data_element(0, &buffer, &max, &len, "+", child, TRUE) >= 0, continue);
        fprintf(where, "%s", buffer);
    }
}
示例#19
0
static crm_action_t *
unpack_action(synapse_t * parent, xmlNode * xml_action)
{
    crm_action_t *action = NULL;
    xmlNode *action_copy = NULL;
    const char *value = crm_element_value(xml_action, XML_ATTR_ID);

    if (value == NULL) {
        crm_err("Actions must have an id!");
        crm_log_xml_trace(xml_action, "Action with missing id");
        return NULL;
    }

    action_copy = copy_xml(xml_action);
    crm_malloc0(action, sizeof(crm_action_t));
    if (action == NULL) {
        return NULL;
    }

    action->id = crm_parse_int(value, NULL);
    action->type = action_type_rsc;
    action->xml = action_copy;
    action->synapse = parent;

    if (safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_RSC_OP)) {
        action->type = action_type_rsc;

    } else if (safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_PSEUDO_EVENT)) {
        action->type = action_type_pseudo;

    } else if (safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_CRM_EVENT)) {
        action->type = action_type_crm;
    }

    action->params = xml2list(action_copy);

    value = g_hash_table_lookup(action->params, "CRM_meta_timeout");
    if (value != NULL) {
        action->timeout = crm_parse_int(value, NULL);
    }

    value = g_hash_table_lookup(action->params, "CRM_meta_interval");
    if (value != NULL) {
        action->interval = crm_parse_int(value, NULL);
    }

    value = g_hash_table_lookup(action->params, "CRM_meta_can_fail");
    if (value != NULL) {
        crm_str_to_boolean(value, &(action->can_fail));
    }

    crm_trace("Action %d has timer set to %dms", action->id, action->timeout);

    return action;
}
示例#20
0
ha_time_t *
parse_time_offset(char **offset_str)
{
    ha_time_t *new_time = NULL;

    crm_malloc0(new_time, sizeof(ha_time_t));
    crm_malloc0(new_time->has, sizeof(ha_has_time_t));

    if ((*offset_str)[0] == 'Z') {

    } else if ((*offset_str)[0] == '+' || (*offset_str)[0] == '-' || isdigit((int)(*offset_str)[0])) {
        gboolean negate = FALSE;

        if ((*offset_str)[0] == '-') {
            negate = TRUE;
            (*offset_str)++;
        }
        parse_time(offset_str, new_time, FALSE);
        if (negate) {
            new_time->hours = 0 - new_time->hours;
            new_time->minutes = 0 - new_time->minutes;
            new_time->seconds = 0 - new_time->seconds;
        }

    } else {
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
        time_t now = time(NULL);
        struct tm *now_tm = localtime(&now);
#endif
        int h_offset = GMTOFF(now_tm) / (3600);
        int m_offset = (GMTOFF(now_tm) - (3600 * h_offset)) / (60);

        if (h_offset < 0 && m_offset < 0) {
            m_offset = 0 - m_offset;
        }
        new_time->hours = h_offset;
        new_time->minutes = m_offset;
        new_time->has->hours = TRUE;
        new_time->has->minutes = TRUE;
    }
    return new_time;
}
示例#21
0
static void
te_start_action_timer(crm_graph_t * graph, crm_action_t * action)
{
    crm_malloc0(action->timer, sizeof(crm_action_timer_t));
    action->timer->timeout = action->timeout;
    action->timer->reason = timeout_action;
    action->timer->action = action;
    action->timer->source_id = g_timeout_add(action->timer->timeout + graph->network_delay,
                                             action_timer_callback, (void *)action->timer);

    CRM_ASSERT(action->timer->source_id != 0);
}
示例#22
0
static void
te_start_action_timer(crm_action_t *action) 
{
	crm_malloc0(action->timer, sizeof(crm_action_timer_t));
	action->timer->timeout   = action->timeout;
	action->timer->reason    = timeout_action_warn;
	action->timer->action    = action;
	action->timer->source_id = Gmain_timeout_add(
		action->timer->timeout,
		action_timer_callback, (void*)action->timer);

	CRM_ASSERT(action->timer->source_id != 0);
}
示例#23
0
char *
crm_itoa(int an_int)
{
	int len = 32;
	char *buffer = NULL;
	
	crm_malloc0(buffer, (len+1));
	if(buffer != NULL) {
		snprintf(buffer, len, "%d", an_int);
	}
	
	return buffer;
}
示例#24
0
char *
crm_concat(const char *prefix, const char *suffix, char join) 
{
	int len = 0;
	char *new_str = NULL;
	CRM_ASSERT(prefix != NULL);
	CRM_ASSERT(suffix != NULL);
	len = strlen(prefix) + strlen(suffix) + 2;

	crm_malloc0(new_str, (len));
	sprintf(new_str, "%s%c%s", prefix, join, suffix);
	new_str[len-1] = 0;
	return new_str;
}
示例#25
0
void
unpack_instance_attributes(xmlNode * top, xmlNode * xml_obj, const char *set_name,
                           GHashTable * node_hash, GHashTable * hash, const char *always_first,
                           gboolean overwrite, ha_time_t * now)
{
    GListPtr sorted = NULL;
    GListPtr unsorted = NULL;
    const char *score = NULL;
    sorted_set_t *pair = NULL;
    struct unpack_data_s data;
    xmlNode *attr_set = NULL;

    if (xml_obj == NULL) {
        crm_trace("No instance attributes");
        return;
    }

    crm_trace("Checking for attributes");
    for (attr_set = __xml_first_child(xml_obj); attr_set != NULL; attr_set = __xml_next(attr_set)) {
        /* Uncertain if set_name == NULL check is strictly necessary here */
        if (set_name == NULL || crm_str_eq((const char *)attr_set->name, set_name, TRUE)) {
            pair = NULL;
            attr_set = expand_idref(attr_set, top);
            if (attr_set == NULL) {
                continue;
            }

            crm_malloc0(pair, sizeof(sorted_set_t));
            pair->name = ID(attr_set);
            pair->special_name = always_first;
            pair->attr_set = attr_set;

            score = crm_element_value(attr_set, XML_RULE_ATTR_SCORE);
            pair->score = char2score(score);

            unsorted = g_list_prepend(unsorted, pair);
        }
    }

    if (pair != NULL) {
        data.hash = hash;
        data.node_hash = node_hash;
        data.now = now;
        data.overwrite = overwrite;
    }

    sorted = g_list_sort(unsorted, sort_pairs);
    g_list_foreach(sorted, unpack_attr_set, &data);
    slist_basic_destroy(sorted);
}
示例#26
0
static char *
get_shadow_prompt(const char *name)
{
    int len = 16;
    char *prompt = NULL;

    CRM_ASSERT(name != NULL);

    len += strlen(name);
    crm_malloc0(prompt, len);

    snprintf(prompt, len, "shadow[%s] # ", name);
    return prompt;
}
示例#27
0
char *
generate_op_key(const char *rsc_id, const char *op_type, int interval)
{
	int len = 35;
	char *op_id = NULL;

	CRM_CHECK(rsc_id  != NULL, return NULL);
	CRM_CHECK(op_type != NULL, return NULL);
	
	len += strlen(op_type);
	len += strlen(rsc_id);
	crm_malloc0(op_id, len);
	CRM_CHECK(op_id != NULL, return NULL);
	sprintf(op_id, "%s_%s_%d", rsc_id, op_type, interval);
	return op_id;
}
示例#28
0
char *
generate_transition_magic_v202(const char *transition_key, int op_status)
{
	int len = 80;
	char *fail_state = NULL;

	CRM_CHECK(transition_key != NULL, return NULL);
	
	len += strlen(transition_key);
	
	crm_malloc0(fail_state, len);
	if(fail_state != NULL) {
		snprintf(fail_state, len, "%d:%s", op_status,transition_key);
	}
	return fail_state;
}
示例#29
0
IPC_Channel *
init_client_ipc_comms_nodispatch(const char *channel_name)
{
	IPC_Channel *ch;
	GHashTable  *attrs;
	static char  path[] = IPC_PATH_ATTR;

	char *commpath = NULL;
	int local_socket_len = 2; /* 2 = '/' + '\0' */

	local_socket_len += strlen(channel_name);
	local_socket_len += strlen(CRM_STATE_DIR);

	crm_malloc0(commpath, local_socket_len);

	sprintf(commpath, CRM_STATE_DIR "/%s", channel_name);
	commpath[local_socket_len - 1] = '\0';
	crm_debug("Attempting to talk on: %s", commpath);
	
	attrs = g_hash_table_new(g_str_hash,g_str_equal);
	g_hash_table_insert(attrs, path, commpath);

	ch = ipc_channel_constructor(IPC_ANYTYPE, attrs);
	g_hash_table_destroy(attrs);

	if (ch == NULL) {
		crm_err("Could not access channel on: %s", commpath);
		crm_free(commpath);
		return NULL;
		
	} else if (ch->ops->initiate_connection(ch) != IPC_OK) {
		crm_debug("Could not init comms on: %s", commpath);
		ch->ops->destroy(ch);
		crm_free(commpath);
		return NULL;
	}

	ch->ops->set_recv_qlen(ch, 512);
	ch->ops->set_send_qlen(ch, 512);
 	ch->should_send_block = TRUE;

	crm_debug_3("Processing of %s complete", commpath);

	crm_free(commpath);
	return ch;
}
示例#30
0
char *
generate_transition_key(int transition_id, int action_id, int target_rc, const char *node)
{
	int len = 40;
	char *fail_state = NULL;

	CRM_CHECK(node != NULL, return NULL);
	
	len += strlen(node);
	
	crm_malloc0(fail_state, len);
	if(fail_state != NULL) {
		snprintf(fail_state, len, "%d:%d:%d:%s",
			 action_id, transition_id, target_rc, node);
	}
	return fail_state;
}