static int show_nodes(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type)
{
	int err;
	int result = EXIT_FAILURE;

	err = quorum_trackstart(q_handle, CS_TRACK_CURRENT);
	if (err != CS_OK) {
		fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err));
		goto err_exit;
	}

	g_called = 0;
	while (g_called == 0) {
		err = quorum_dispatch(q_handle, CS_DISPATCH_ONE);
		if (err != CS_OK) {
			fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err));
			goto err_exit;
		}
	}

	display_nodes_data(nodeid_format, name_format, sort_type);

	result = EXIT_SUCCESS;
err_exit:
	return result;
}
Exemple #2
0
static int reload_config_do (void)
{
	cs_error_t result;
	corosync_cfg_handle_t handle;
	int rc;

	rc = 0;

	printf ("Reloading corosync.conf...\n");
	result = corosync_cfg_initialize (&handle, NULL);
	if (result != CS_OK) {
		printf ("Could not initialize corosync configuration API error %s\n", cs_strerror(result));
		exit (1);
	}

	result = corosync_cfg_reload_config (handle);
	if (result != CS_OK) {
		printf ("Could not reload configuration. Error %s\n", cs_strerror(result));
		rc = (int)result;
	}
	else {
		printf ("Done\n");
	}

	(void)corosync_cfg_finalize (handle);

	return (rc);
}
Exemple #3
0
/** \brief COMSTACK synopsis from manual, doc/comstack.xml */
static int comstack_example(const char *server_address_str)
{
    COMSTACK stack;
    char *buf = 0;
    int size = 0, length_incoming;
    void *server_address_ip;
    int status;

    char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
    int protocol_package_length = strlen(protocol_package);

    stack = cs_create(tcpip_type, 1, PROTO_HTTP);
    if (!stack) {
        perror("cs_create");  /* use perror() here since we have no stack yet */
        return -1;
    }

    server_address_ip = cs_straddr(stack, server_address_str);
    if (!server_address_ip) {
        fprintf(stderr, "cs_straddr: address could not be resolved\n");
        return -1;
    }

    status = cs_connect(stack, server_address_ip);
    if (status) {
        fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
        return -1;
    }

    status = cs_rcvconnect(stack);
    if (status) {
        fprintf(stderr, "cs_rcvconnect: %s\n", cs_strerror(stack));
        return -1;
    }

    status = cs_put(stack, protocol_package, protocol_package_length);
    if (status) {
        fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
        return -1;
    }

    /* Now get a response */
    length_incoming = cs_get(stack, &buf, &size);
    if (!length_incoming) {
        fprintf(stderr, "Connection closed\n");
        return -1;
    } else if (length_incoming < 0) {
        fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
        return -1;
    }

    /* Print result */
    fwrite(buf, length_incoming, 1, stdout);

    /* clean up */
    cs_close(stack);
    if (buf)
        xfree(buf);
    return 0;
}
static int monitor_status(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type) {
	int err;
	int loop = 0;

	if (q_type == QUORUM_FREE) {
		printf("\nQuorum is not configured - cannot monitor\n");
		return show_status(nodeid_format, name_format, sort_type);
	}

	err=quorum_trackstart(q_handle, CS_TRACK_CHANGES);
	if (err != CS_OK) {
		fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err));
		goto quorum_err;
	}

	if (using_votequorum()) {
		if ( (err=votequorum_trackstart(v_handle, 0LL, CS_TRACK_CHANGES)) != CS_OK) {
			fprintf(stderr, "Unable to start votequorum status tracking: %s\n", cs_strerror(err));
			goto quorum_err;
		}
	}


	while (1) {
		err = quorum_dispatch(q_handle, CS_DISPATCH_ONE);
		if (err != CS_OK) {
			fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err));
			goto quorum_err;
		}
		if (using_votequorum()) {
			g_vq_called = 0;
			while (!g_vq_called) {
				err = votequorum_dispatch(v_handle, CS_DISPATCH_ONE);
				if (err != CS_OK) {
					fprintf(stderr, "Unable to dispatch votequorum status: %s\n", cs_strerror(err));
					goto quorum_err;
				}
			}
		}

		err = display_quorum_data(g_quorate, nodeid_format, name_format, sort_type, loop);
		printf("\n");
		loop = 1;
		if (err != CS_OK) {
			fprintf(stderr, "Unable to display quorum data: %s\n", cs_strerror(err));
			goto quorum_err;
		}
	}

quorum_err:
	return -1;
}
Exemple #5
0
char *
corosync_cluster_name(void)
{
    cmap_handle_t handle;
    char *cluster_name = NULL;
    cs_error_t rc = CS_OK;
    int fd = -1;
    uid_t found_uid = 0;
    gid_t found_gid = 0;
    pid_t found_pid = 0;
    int rv;

    rc = cmap_initialize(&handle);
    if (rc != CS_OK) {
        crm_info("Failed to initialize the cmap API: %s (%d)",
                 cs_strerror(rc), rc);
        return NULL;
    }

    rc = cmap_fd_get(handle, &fd);
    if (rc != CS_OK) {
        crm_err("Could not obtain the CMAP API connection: %s (%d)",
                cs_strerror(rc), rc);
        goto bail;
    }

    /* CMAP provider run as root (in given user namespace, anyway)? */
    if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid,
                                            &found_uid, &found_gid))) {
        crm_err("CMAP provider is not authentic:"
                " process %lld (uid: %lld, gid: %lld)",
                (long long) PCMK__SPECIAL_PID_AS_0(found_pid),
                (long long) found_uid, (long long) found_gid);
        goto bail;
    } else if (rv < 0) {
        crm_err("Could not verify authenticity of CMAP provider: %s (%d)",
                strerror(-rv), -rv);
        goto bail;
    }

    rc = cmap_get_string(handle, "totem.cluster_name", &cluster_name);
    if (rc != CS_OK) {
        crm_info("Cannot get totem.cluster_name: %s (%d)", cs_strerror(rc), rc);

    } else {
        crm_debug("cmap totem.cluster_name = '%s'", cluster_name);
    }

bail:
    cmap_finalize(handle);
    return cluster_name;
}
Exemple #6
0
int
corosync_cmap_has_config(const char *prefix)
{
    int rc = CS_OK;
    int retries = 0;
    static int found = -1;
    cmap_handle_t cmap_handle;
    cmap_iter_handle_t iter_handle;
    char key_name[CMAP_KEYNAME_MAXLEN + 1];

    if(found != -1) {
        return found;
    }

    do {
        rc = cmap_initialize(&cmap_handle);
        if (rc != CS_OK) {
            retries++;
            crm_debug("API connection setup failed: %s.  Retrying in %ds", cs_strerror(rc),
                      retries);
            sleep(retries);
        }

    } while (retries < 5 && rc != CS_OK);

    if (rc != CS_OK) {
        crm_warn("Could not connect to Cluster Configuration Database API: %s (rc=%d)",
                 cs_strerror(rc), rc);
        return -1;
    }

    rc = cmap_iter_init(cmap_handle, prefix, &iter_handle);
    if (rc != CS_OK) {
        crm_warn("Failed to initialize iteration for corosync cmap '%s': %s (rc=%d)",
                 prefix, cs_strerror(rc), rc);
        goto bail;
    }

    found = 0;
    while ((rc = cmap_iter_next(cmap_handle, iter_handle, key_name, NULL, NULL)) == CS_OK) {
        crm_trace("'%s' is configured in corosync cmap: %s", prefix, key_name);
        found++;
        break;
    }
    cmap_iter_finalize(cmap_handle, iter_handle);

bail:
    cmap_finalize(cmap_handle);

    return found;
}
Exemple #7
0
static bool open_capstone() {
    cs_err res = cs_open(CS_ARCH_ARM64, CS_MODE_ARM, &cshandle);
    if (res != CS_ERR_OK)
        error("Error opening Capstone engine: %s", cs_strerror(res));

    return (res == CS_ERR_OK);
}
static void track_changes(cmap_handle_t handle)
{
	struct pollfd pfd[2];
	int cmap_fd;
	cs_error_t err;
	int poll_res;
	char inbuf[3];
	int quit = CS_FALSE;

	err = cmap_fd_get(handle, &cmap_fd);
	if (err != CS_OK) {
		fprintf(stderr, "Failed to get file handle. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}

	pfd[0].fd = cmap_fd;
	pfd[1].fd = STDIN_FILENO;
	pfd[0].events = pfd[1].events = POLLIN;

	printf("Type \"q\" to finish\n");
	do {
		pfd[0].revents = pfd[1].revents = 0;
		poll_res = poll(pfd, 2, INFTIM);
		if (poll_res == -1) {
			perror("poll");
		}

		if (pfd[1].revents & POLLIN) {
			if (fgets(inbuf, sizeof(inbuf), stdin) == NULL) {
				quit = CS_TRUE;
			} else if (strncmp(inbuf, "q", 1) == 0) {
				quit = CS_TRUE;
			}
		}

		if (pfd[0].revents & POLLIN) {
			err = cmap_dispatch(handle, CS_DISPATCH_ALL);
			if (err != CS_OK) {
				fprintf(stderr, "Dispatch error %s\n", cs_strerror(err));
				quit = CS_TRUE;
			}
		}
	} while (poll_res > 0 && !quit);
}
static int set_expected(int expected_votes)
{
	int err;

	if ((err=votequorum_setexpected(v_handle, expected_votes)) != CS_OK) {
		fprintf(stderr, "Unable to set expected votes: %s\n", cs_strerror(err));
	}

	return err==CS_OK?0:err;
}
static int set_votes(uint32_t nodeid, int votes)
{
	int err;

	if ((err=votequorum_setvotes(v_handle, nodeid, votes)) != CS_OK) {
		fprintf(stderr, "Unable to set votes %d for nodeid: %u: %s\n",
			votes, nodeid, cs_strerror(err));
	}

	return err==CS_OK?0:err;
}
Exemple #11
0
void
qdevice_cmap_destroy(struct qdevice_instance *instance)
{
	cs_error_t res;

	res = cmap_finalize(instance->cmap_handle);

	if (res != CS_OK) {
		qdevice_log(LOG_WARNING, "Can't finalize cmap. Error %s", cs_strerror(res));
	}
}
Exemple #12
0
int main (void) {
	cpg_handle_t handle;
	unsigned int size;
	int i;
	unsigned int res;



	size = 1000;
	signal (SIGALRM, sigalrm_handler);
	res = cpg_initialize (&handle, &callbacks);
	if (res != CS_OK) {
		printf ("cpg_initialize failed with result %d\n", res);
		exit (1);
	}
	cpg_zcb_alloc (handle, 500000, &data);
	if (res != CS_OK) {
		printf ("cpg_zcb_alloc couldn't allocate zero copy buffer %d\n", res);
		exit (1);
	}

	res = cpg_join (handle, &group_name);
	if (res != CS_OK) {
		printf ("cpg_join failed with result %s\n", cs_strerror(res));
		exit (1);
	}

	for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */
		cpg_benchmark (handle, size);
		size += 1000;
	}

	res = cpg_finalize (handle);
	if (res != CS_OK) {
		printf ("cpg_finalize failed with result %s\n", cs_strerror(res));
		exit (1);
	}
	return (0);
}
static int unregister_qdevice(void)
{
	int err;
	struct votequorum_info info;

	err = votequorum_getinfo(v_handle, our_nodeid, &info);
	if (err != CS_OK) {
		fprintf(stderr, "Unable to get quorum device info: %s\n", cs_strerror(err));
		return -1;
	}

	if (!(info.flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED)) {
		return 0;
	}

	err = votequorum_qdevice_unregister(v_handle, info.qdevice_name);
	if (err != CS_OK) {
		fprintf(stderr, "Unable to unregister quorum device: %s\n", cs_strerror(err));
		return -1;
	}
	return 0;
}
Exemple #14
0
/*
 * Set up a listening endpoint, and give it to the event-handler.
 */
static int add_listener(char *where, int listen_id)
{
    COMSTACK l;
    void *ap;
    IOCHAN lst = NULL;
    const char *mode;

    if (control_block.dynamic)
        mode = "dynamic";
    else if (control_block.threads)
        mode = "threaded";
    else
        mode = "static";

    yaz_log(log_server, "Adding %s listener on %s id=%d", mode, where,
            listen_id);

    l = cs_create_host(where, 2, &ap);
    if (!l)
    {
        yaz_log(YLOG_FATAL, "Failed to listen on %s", where);
        return -1;
    }
    if (*control_block.cert_fname)
        cs_set_ssl_certificate_file(l, control_block.cert_fname);

    if (cs_bind(l, ap, CS_SERVER) < 0)
    {
        if (cs_errno(l) == CSYSERR)
            yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to bind to %s", where);
        else
            yaz_log(YLOG_FATAL, "Failed to bind to %s: %s", where,
                    cs_strerror(l));
        cs_close(l);
        return -1;
    }
    if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT |
                              EVENT_EXCEPT, listen_id)))
    {
        yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to create IOCHAN-type");
        cs_close(l);
        return -1;
    }
    iochan_setdata(lst, l); /* user-defined data for listener is COMSTACK */
    l->user = lst;  /* user-defined data for COMSTACK is listener chan */

    /* Add listener to chain */
    lst->next = pListener;
    pListener = lst;
    return 0; /* OK */
}
static void delete_with_prefix(cmap_handle_t handle, const char *prefix)
{
	cmap_iter_handle_t iter_handle;
	char key_name[CMAP_KEYNAME_MAXLEN + 1];
	size_t value_len;
	cmap_value_types_t type;
	cs_error_t err;
	cs_error_t err2;

	err = cmap_iter_init(handle, prefix, &iter_handle);
	if (err != CS_OK) {
		fprintf (stderr, "Failed to initialize iteration. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}

	while ((err = cmap_iter_next(handle, iter_handle, key_name, &value_len, &type)) == CS_OK) {
		err2 = cmap_delete(handle, key_name);
		if (err2 != CS_OK) {
			fprintf(stderr, "Can't delete key %s. Error %s\n", key_name, cs_strerror(err2));
		}
	}
	cmap_iter_finalize(handle, iter_handle);
}
Exemple #16
0
void
qdevice_cmap_init(struct qdevice_instance *instance)
{
	cs_error_t res;
	int no_retries;

	no_retries = 0;

	while ((res = cmap_initialize(&instance->cmap_handle)) == CS_ERR_TRY_AGAIN &&
	    no_retries++ < instance->advanced_settings->max_cs_try_again) {
		(void)poll(NULL, 0, 1000);
	}

	if (res != CS_OK) {
		errx(1, "Failed to initialize the cmap API. Error %s", cs_strerror(res));
	}

	if ((res = cmap_context_set(instance->cmap_handle, (void *)instance)) != CS_OK) {
		errx(1, "Can't set cmap context. Error %s", cs_strerror(res));
	}

	cmap_fd_get(instance->cmap_handle, &instance->cmap_poll_fd);
}
/*
 * return  1 if quorate
 *         0 if not quorate
 *        -1 on error
 */
static int show_status(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type)
{
	int is_quorate;
	int err;

	err=quorum_getquorate(q_handle, &is_quorate);
	if (err != CS_OK) {
		fprintf(stderr, "Unable to get cluster quorate status: %s\n", cs_strerror(err));
		goto quorum_err;
	}

	err=quorum_trackstart(q_handle, CS_TRACK_CURRENT);
	if (err != CS_OK) {
		fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err));
		goto quorum_err;
	}

	g_called = 0;
	while (g_called == 0 && err == CS_OK) {
		err = quorum_dispatch(q_handle, CS_DISPATCH_ONE);
		if (err != CS_OK) {
			fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err));
		}
	}

	if (quorum_trackstop(q_handle) != CS_OK) {
		fprintf(stderr, "Unable to stop quorum status tracking: %s\n", cs_strerror(err));
	}

	if (using_votequorum()) {

		if ( (err=votequorum_trackstart(v_handle, 0LL, CS_TRACK_CURRENT)) != CS_OK) {
			fprintf(stderr, "Unable to start votequorum status tracking: %s\n", cs_strerror(err));
			goto quorum_err;
		}

		g_vq_called = 0;
		while (g_vq_called == 0 && err == CS_OK) {
			err = votequorum_dispatch(v_handle, CS_DISPATCH_ONE);
			if (err != CS_OK) {
				fprintf(stderr, "Unable to dispatch votequorum status: %s\n", cs_strerror(err));
			}
		}
	}

quorum_err:
	if (err != CS_OK) {
		return -1;
	}

	err = display_quorum_data(is_quorate, nodeid_format, name_format, sort_type, 0);
	if (err != CS_OK) {
		return -1;
	}

	return is_quorate;
}
Exemple #18
0
static void track_link_updown_events(void)
{
	cmap_iter_handle_t iter_handle;
	cmap_track_handle_t track_handle;

	char key_name[CMAP_KEYNAME_MAXLEN + 1];
	size_t value_len;
	cmap_value_types_t type;
	cs_error_t err;
	struct track_item *track_item;

	err = cmap_iter_init(stats_handle, "stats.knet.", &iter_handle);
	if (err != CS_OK) {
		fprintf (stderr, "Failed to initialize knet stats iterator. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}

	while ((err = cmap_iter_next(stats_handle, iter_handle, key_name, &value_len, &type)) == CS_OK) {
		if (strstr(key_name, ".connected")) {

			track_item = malloc(sizeof(struct track_item));
			if (!track_item) {
				return;
			}

			if ((err = cmap_track_add(stats_handle, key_name, CMAP_TRACK_MODIFY, _cs_cmap_link_faulty_key_changed, NULL, &track_handle)) != CS_OK) {
				fprintf (stderr, "Failed to add tracker for %s. Error %s\n", key_name, cs_strerror(err));
				exit (EXIT_FAILURE);
			}
			strcpy(track_item->key_name, key_name);
			track_item->track_handle = track_handle;
			qb_map_put(tracker_map, track_item->key_name, track_item);

		}
	}
	cmap_iter_finalize(stats_handle, iter_handle);
}
static int q_dispatch_wrapper_fn (
	int fd,
	int revents,
	void *data)
{
	cs_error_t error = quorum_dispatch (q_handle, CS_DISPATCH_ALL);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "got %s error, disconnecting.",
			cs_strerror(error));
		quorum_finalize(q_handle);
		q_handle = 0;
		return -1;
	}
	return 0;
}
static void add_track(cmap_handle_t handle, const char *key_name, int prefix)
{
	cmap_track_handle_t track_handle;
	int32_t track_type;
	cs_error_t err;

	track_type = CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_MODIFY;
	if (prefix) {
		track_type |= CMAP_TRACK_PREFIX;
	}

	err = cmap_track_add(handle, key_name, track_type, cmap_notify_fn, NULL, &track_handle);
	if (err != CS_OK) {
		fprintf(stderr, "Failed to add tracking function. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}
}
static void print_iter(cmap_handle_t handle, const char *prefix)
{
	cmap_iter_handle_t iter_handle;
	char key_name[CMAP_KEYNAME_MAXLEN + 1];
	size_t value_len;
	cmap_value_types_t type;
	cs_error_t err;

	err = cmap_iter_init(handle, prefix, &iter_handle);
	if (err != CS_OK) {
		fprintf (stderr, "Failed to initialize iteration. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}

	while ((err = cmap_iter_next(handle, iter_handle, key_name, &value_len, &type)) == CS_OK) {
		print_key(handle, key_name, value_len, NULL, type);
	}
	cmap_iter_finalize(handle, iter_handle);
}
Exemple #22
0
static const char * disarm64(insn_t insn, address_t pc) {
    cs_insn *csi;
    size_t count;
    if (!cshandle && !open_capstone())
        return "<capstone open failed>";

    count = cs_disasm(cshandle, (const uint8_t *) &insn, sizeof(insn), pc, 1, &csi);
    if (count == 1) {
        snprintf(disarm64_buf, DISARM64_BUFSIZE-2, "%s\t%s", csi->mnemonic, csi->op_str);
        cs_free(csi, 1);
    } else {
        cs_err err = cs_errno(cshandle);
        if (err != CS_ERR_OK) {
            error("Capstone disassembler failed: %s", cs_strerror(err));
            return "<capstone error>";
        }
        return "<unrecognised>";
    }

    return disarm64_buf;
}
static void print_key(cmap_handle_t handle,
		const char *key_name,
		size_t value_len,
		const void *value,
		cmap_value_types_t type)
{
	char *str;
	char *bin_value = NULL;
	cs_error_t err;
	int8_t i8;
	uint8_t u8;
	int16_t i16;
	uint16_t u16;
	int32_t i32;
	uint32_t u32;
	int64_t i64;
	uint64_t u64;
	float flt;
	double dbl;
	int end_loop;
	int no_retries;
	size_t bin_value_len;

	end_loop = 0;
	no_retries = 0;

	err = CS_OK;

	while (!end_loop) {
		switch (type) {
		case CMAP_VALUETYPE_INT8:
			if (value == NULL) {
				err = cmap_get_int8(handle, key_name, &i8);
			} else {
				i8 = *((int8_t *)value);
			}
			break;
		case CMAP_VALUETYPE_INT16:
			if (value == NULL) {
				err = cmap_get_int16(handle, key_name, &i16);
			} else {
				i16 = *((int16_t *)value);
			}
			break;
		case CMAP_VALUETYPE_INT32:
			if (value == NULL) {
				err = cmap_get_int32(handle, key_name, &i32);
			} else {
				i32 = *((int32_t *)value);
			}
			break;
		case CMAP_VALUETYPE_INT64:
			if (value == NULL) {
				err = cmap_get_int64(handle, key_name, &i64);
			} else {
				i64 = *((int64_t *)value);
			}
			break;
		case CMAP_VALUETYPE_UINT8:
			if (value == NULL) {
				err = cmap_get_uint8(handle, key_name, &u8);
			} else {
				u8 = *((uint8_t *)value);
			}
			break;
		case CMAP_VALUETYPE_UINT16:
			if (value == NULL) {
				err = cmap_get_uint16(handle, key_name, &u16);
			} else {
				u16 = *((uint16_t *)value);
			}
			break;
		case CMAP_VALUETYPE_UINT32:
			if (value == NULL) {
				err = cmap_get_uint32(handle, key_name, &u32);
			} else {
				u32 = *((uint32_t *)value);
			}
			break;
		case CMAP_VALUETYPE_UINT64:
			if (value == NULL) {
				err = cmap_get_uint64(handle, key_name, &u64);
			} else {
				u64 = *((uint64_t *)value);
			}
			break;
		case CMAP_VALUETYPE_FLOAT:
			if (value == NULL) {
				err = cmap_get_float(handle, key_name, &flt);
			} else {
				flt = *((float *)value);
			}
			break;
		case CMAP_VALUETYPE_DOUBLE:
			if (value == NULL) {
				err = cmap_get_double(handle, key_name, &dbl);
			} else {
				dbl = *((double *)value);
			}
			break;
		case CMAP_VALUETYPE_STRING:
			if (value == NULL) {
				err = cmap_get_string(handle, key_name, &str);
			} else {
				str = (char *)value;
			}
			break;
		case CMAP_VALUETYPE_BINARY:
			if (show_binary) {
				if (value == NULL) {
					bin_value = malloc(value_len);
					if (bin_value == NULL) {
						fprintf(stderr, "Can't alloc memory\n");
						exit(EXIT_FAILURE);
					}
					bin_value_len = value_len;
					err = cmap_get(handle, key_name, bin_value, &bin_value_len, NULL);
				} else {
					bin_value = (char *)value;
				}
			}
			break;
		}

		if (err == CS_OK)
			end_loop = 1;

		if (err == CS_ERR_TRY_AGAIN) {
			sleep(1);
			no_retries++;
		}

		if (no_retries > MAX_TRY_AGAIN) {
			end_loop = 1;
		}
	};

	if (err != CS_OK) {
		fprintf(stderr, "Can't get value of %s. Error %s\n", key_name, cs_strerror(err));

		return ;
	}

	printf("%s (", key_name);

	switch (type) {
	case CMAP_VALUETYPE_INT8:
		printf("%s) = %"PRId8, "i8", i8);
		break;
	case CMAP_VALUETYPE_UINT8:
		printf("%s) = %"PRIu8, "u8", u8);
		break;
	case CMAP_VALUETYPE_INT16:
		printf("%s) = %"PRId16, "i16", i16);
		break;
	case CMAP_VALUETYPE_UINT16:
		printf("%s) = %"PRIu16, "u16", u16);
		break;
	case CMAP_VALUETYPE_INT32:
		printf("%s) = %"PRId32, "i32", i32);
		break;
	case CMAP_VALUETYPE_UINT32:
		printf("%s) = %"PRIu32, "u32", u32);
		break;
	case CMAP_VALUETYPE_INT64:
		printf("%s) = %"PRId64, "i64", i64);
		break;
	case CMAP_VALUETYPE_UINT64:
		printf("%s) = %"PRIu64, "u64", u64);
		break;
	case CMAP_VALUETYPE_FLOAT:
		printf("%s) = %f", "flt", flt);
		break;
	case CMAP_VALUETYPE_DOUBLE:
		printf("%s) = %lf", "dbl", dbl);
		break;
	case CMAP_VALUETYPE_STRING:
		printf("%s) = %s", "str", str);
		if (value == NULL) {
			free(str);
		}
		break;
	case CMAP_VALUETYPE_BINARY:
		printf("%s)", "bin");
		if (show_binary) {
			printf(" = ");
			if (bin_value) {
				print_binary_key(bin_value, value_len);
				if (value == NULL) {
					free(bin_value);
				}
			} else {
				printf("*empty*");
			}
		}
		break;
	}

	printf("\n");
}
static int display_quorum_data(int is_quorate,
			       nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type,
			       int loop)
{
	struct votequorum_info info;
	int err;
	char quorumtype[256];
	time_t t;

	memset(quorumtype, 0, sizeof(quorumtype));

	printf("Quorum information\n");
	printf("------------------\n");
	time(&t);
	printf("Date:             %s", ctime((const time_t *)&t));

	if (get_quorum_type(quorumtype, sizeof(quorumtype))) {
		strncpy(quorumtype, "Not configured", sizeof(quorumtype) - 1);
	}
	printf("Quorum provider:  %s\n", quorumtype);
	printf("Nodes:            %d\n", g_view_list_entries);
	if (nodeid_format == NODEID_FORMAT_DECIMAL) {
		printf("Node ID:          %u\n", our_nodeid);
	} else {
		printf("Node ID:          0x%08x\n", our_nodeid);
	}

	if (v_handle) {
		printf("Ring ID:          %d/%" PRIu64 "\n", g_ring_id_rep_node, g_ring_id);
	}
	else {
		printf("Ring ID:          %" PRIu64 "\n", g_ring_id);
	}
	printf("Quorate:          %s\n", is_quorate?"Yes":"No");

	if (!v_handle) {
		return CS_OK;
	}

	err=votequorum_getinfo(v_handle, our_nodeid, &info);
	if ((err == CS_OK) || (err == CS_ERR_NOT_EXIST)) {
		printf("\nVotequorum information\n");
		printf("----------------------\n");
		printf("Expected votes:   %d\n", info.node_expected_votes);
		printf("Highest expected: %d\n", info.highest_expected);
		printf("Total votes:      %d\n", info.total_votes);
		printf("Quorum:           %d %s\n", info.quorum, info.flags & VOTEQUORUM_INFO_QUORATE?" ":"Activity blocked");
		printf("Flags:            ");
		if (info.flags & VOTEQUORUM_INFO_TWONODE) printf("2Node ");
		if (info.flags & VOTEQUORUM_INFO_QUORATE) printf("Quorate ");
		if (info.flags & VOTEQUORUM_INFO_WAIT_FOR_ALL) printf("WaitForAll ");
		if (info.flags & VOTEQUORUM_INFO_LAST_MAN_STANDING) printf("LastManStanding ");
		if (info.flags & VOTEQUORUM_INFO_AUTO_TIE_BREAKER) printf("AutoTieBreaker ");
		if (info.flags & VOTEQUORUM_INFO_ALLOW_DOWNSCALE) printf("AllowDownscale ");
		if (info.flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) printf("Qdevice ");
		printf("\n");
	} else {
		fprintf(stderr, "Unable to get node info: %s\n", cs_strerror(err));
	}

	display_nodes_data(nodeid_format, name_format, sort_type);

	return err;
}
/*
 * This resolves the first address assigned to a node
 * and returns the name or IP address. Use cfgtool if you need more information.
 */
static const char *node_name(uint32_t nodeid, name_format_t name_format)
{
	int err;
	int numaddrs;
	corosync_cfg_node_address_t addrs[INTERFACE_MAX];
	static char buf[(INET6_ADDRSTRLEN + 1) * KNET_MAX_LINK];
	const char *nodelist_name = NULL;
	socklen_t addrlen;
	struct sockaddr_storage *ss;
	int start_addr = 0;
	int i;
	int bufptr = 0;

	buf[0] = '\0';

	/* If a name is required, always look for the nodelist node0_addr name first */
	if (name_format == ADDRESS_FORMAT_NAME) {
		nodelist_name = node_name_by_nodelist(nodeid);
	}
	if ((nodelist_name) &&
	    (strlen(nodelist_name) > 0)) {
		start_addr = 1;
		strcpy(buf, nodelist_name);
		bufptr = strlen(buf);
	}

	err = corosync_cfg_get_node_addrs(c_handle, nodeid, INTERFACE_MAX, &numaddrs, addrs);
	if (err != CS_OK) {
		fprintf(stderr, "Unable to get node address for nodeid %u: %s\n", nodeid, cs_strerror(err));
		return "";
	}

	/* Don't show all addressess */
	if (!g_show_all_addrs) {
		numaddrs = 1;
	}

	for (i=start_addr; i<numaddrs; i++) {

		ss = (struct sockaddr_storage *)addrs[i].address;

		if (!ss->ss_family) {
			continue;
		}

		if (ss->ss_family == AF_INET6) {
			addrlen = sizeof(struct sockaddr_in6);
		} else {
			addrlen = sizeof(struct sockaddr_in);
		}

		if (i) {
			buf[bufptr++] = ',';
			buf[bufptr++] = ' ';
		}

		if (!getnameinfo(
			    (struct sockaddr *)addrs[i].address, addrlen,
			    buf+bufptr, sizeof(buf)-bufptr,
			    NULL, 0,
			    (name_format == ADDRESS_FORMAT_IP)?NI_NUMERICHOST:0)) {
			bufptr += strlen(buf+bufptr);
		}
	}

	return buf;
}
Exemple #26
0
gboolean
corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode * xml_parent)
{
    int lpc = 0;
    int rc = CS_OK;
    int retries = 0;
    gboolean any = FALSE;
    cmap_handle_t cmap_handle;

    do {
        rc = cmap_initialize(&cmap_handle);
        if (rc != CS_OK) {
            retries++;
            crm_debug("API connection setup failed: %s.  Retrying in %ds", cs_strerror(rc),
                      retries);
            sleep(retries);
        }

    } while (retries < 5 && rc != CS_OK);

    if (rc != CS_OK) {
        crm_warn("Could not connect to Cluster Configuration Database API, error %d", rc);
        return FALSE;
    }

    crm_peer_init();
    crm_trace("Initializing corosync nodelist");
    for (lpc = 0;; lpc++) {
        uint32_t nodeid = 0;
        char *name = NULL;
        char *key = NULL;

        key = g_strdup_printf("nodelist.node.%d.nodeid", lpc);
        rc = cmap_get_uint32(cmap_handle, key, &nodeid);
        g_free(key);

        if (rc != CS_OK) {
            break;
        }

        name = corosync_node_name(cmap_handle, nodeid);
        if (name != NULL) {
            GHashTableIter iter;
            crm_node_t *node = NULL;

            g_hash_table_iter_init(&iter, crm_peer_cache);
            while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
                if(node && node->uname && strcasecmp(node->uname, name) == 0) {
                    if (node->id && node->id != nodeid) {
                        crm_crit("Nodes %u and %u share the same name '%s': shutting down", node->id,
                                 nodeid, name);
                        crm_exit(DAEMON_RESPAWN_STOP);
                    }
                }
            }
        }

        if (nodeid > 0 || name != NULL) {
            crm_trace("Initializing node[%d] %u = %s", lpc, nodeid, name);
            crm_get_peer(nodeid, name);
        }

        if (nodeid > 0 && name != NULL) {
            any = TRUE;

            if (xml_parent) {
                xmlNode *node = create_xml_node(xml_parent, XML_CIB_TAG_NODE);

                crm_xml_add_int(node, XML_ATTR_ID, nodeid);
                crm_xml_add(node, XML_ATTR_UNAME, name);
                if (force_member) {
                    crm_xml_add(node, XML_ATTR_TYPE, CRM_NODE_MEMBER);
                }
            }
        }

        free(name);
    }
    cmap_finalize(cmap_handle);
    return any;
}
int main(int argc, char *argv[])
{
	enum user_action action;
	int c;
	cs_error_t err;
	cmap_handle_t handle;
	int i;
	size_t value_len;
	cmap_value_types_t type;
	int track_prefix;
	int no_retries;
	char * settings_file = NULL;

	action = ACTION_PRINT_PREFIX;
	track_prefix = 1;

	while ((c = getopt(argc, argv, "hgsdDtTbp:")) != -1) {
		switch (c) {
		case 'h':
			return print_help();
			break;
		case 'b':
			show_binary++;
			break;
		case 'g':
			action = ACTION_GET;
			break;
		case 's':
			action = ACTION_SET;
			break;
		case 'd':
			action = ACTION_DELETE;
			break;
		case 'D':
			action = ACTION_DELETE_PREFIX;
			break;
		case 'p':
			settings_file = optarg;
			action = ACTION_LOAD;
			break;
		case 't':
			action = ACTION_TRACK;
			track_prefix = 0;
			break;
		case 'T':
			action = ACTION_TRACK;
			break;
		case '?':
			return (EXIT_FAILURE);
			break;
		default:
			action = ACTION_PRINT_PREFIX;
			break;
		}
	}

	if (argc == 1 || (argc == 2 && show_binary)) {
		action = ACTION_PRINT_ALL;
	}

	argc -= optind;
	argv += optind;

	if (argc == 0 &&
	    action != ACTION_LOAD &&
	    action != ACTION_PRINT_ALL) {
		fprintf(stderr, "Expected key after options\n");
		return (EXIT_FAILURE);
	}

	no_retries = 0;
	while ((err = cmap_initialize(&handle)) == CS_ERR_TRY_AGAIN && no_retries++ < MAX_TRY_AGAIN) {
		sleep(1);
	}

	if (err != CS_OK) {
		fprintf (stderr, "Failed to initialize the cmap API. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}

	switch (action) {
	case ACTION_PRINT_ALL:
		print_iter(handle, NULL);
		break;
	case ACTION_PRINT_PREFIX:
		for (i = 0; i < argc; i++) {
			print_iter(handle, argv[i]);
		}
		break;
	case ACTION_GET:
		for (i = 0; i < argc; i++) {
			err = cmap_get(handle, argv[i], NULL, &value_len, &type);
			if (err == CS_OK) {
				print_key(handle, argv[i], value_len, NULL, type);
			} else {
				fprintf(stderr, "Can't get key %s. Error %s\n", argv[i], cs_strerror(err));
			}
		}
		break;
	case ACTION_DELETE:
		for (i = 0; i < argc; i++) {
			err = cmap_delete(handle, argv[i]);
			if (err != CS_OK) {
				fprintf(stderr, "Can't delete key %s. Error %s\n", argv[i], cs_strerror(err));
			}
		}
		break;
	case ACTION_DELETE_PREFIX:
		for (i = 0; i < argc; i++) {
			delete_with_prefix(handle, argv[i]);
		}
		break;
	case ACTION_LOAD:
		read_in_config_file(handle, settings_file);
		break;
	case ACTION_TRACK:
		for (i = 0; i < argc; i++) {
			add_track(handle, argv[i], track_prefix);
		}
		track_changes(handle);
		break;
	case ACTION_SET:
		if (argc < 3) {
			fprintf(stderr, "At least 3 parameters are expected for set\n");
			return (EXIT_FAILURE);
		}

		set_key(handle, argv[0], argv[1], argv[2]);
		break;

	}

	err = cmap_finalize(handle);
	if (err != CS_OK) {
		fprintf (stderr, "Failed to finalize the cmap API. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}

	return (0);
}
static void set_key(cmap_handle_t handle, const char *key_name, const char *key_type_s, const char *key_value_s)
{
	int64_t i64;
	uint64_t u64;
	double dbl;
	float flt;
	cs_error_t err = CS_OK;
	int scanf_res = 0;

	cmap_value_types_t type;

	if (convert_name_to_type(key_type_s) == -1) {
		fprintf(stderr, "Unknown type %s\n", key_type_s);
		exit (EXIT_FAILURE);
	}

	type = convert_name_to_type(key_type_s);

	switch (type) {
	case CMAP_VALUETYPE_INT8:
	case CMAP_VALUETYPE_INT16:
	case CMAP_VALUETYPE_INT32:
	case CMAP_VALUETYPE_INT64:
		scanf_res = sscanf(key_value_s, "%"PRId64, &i64);
		break;
	case CMAP_VALUETYPE_UINT8:
	case CMAP_VALUETYPE_UINT16:
	case CMAP_VALUETYPE_UINT32:
	case CMAP_VALUETYPE_UINT64:
		scanf_res = sscanf(key_value_s, "%"PRIu64, &u64);
		break;
	case CMAP_VALUETYPE_FLOAT:
		scanf_res = sscanf(key_value_s, "%f", &flt);
		break;
	case CMAP_VALUETYPE_DOUBLE:
		scanf_res = sscanf(key_value_s, "%lf", &dbl);
		break;
	case CMAP_VALUETYPE_STRING:
	case CMAP_VALUETYPE_BINARY:
		/*
		 * Do nothing
		 */
		scanf_res = 1;
		break;
	}

	if (scanf_res != 1) {
		fprintf(stderr, "%s is not valid %s type value\n", key_value_s, key_type_s);
		exit(EXIT_FAILURE);
	}
	/*
	 * We have parsed value, so insert value
	 */

	switch (type) {
	case CMAP_VALUETYPE_INT8:
		if (i64 > INT8_MAX || i64 < INT8_MIN) {
			fprintf(stderr, "%s is not valid i8 integer\n", key_value_s);
			exit(EXIT_FAILURE);
		}
		err = cmap_set_int8(handle, key_name, i64);
		break;
	case CMAP_VALUETYPE_INT16:
		if (i64 > INT16_MAX || i64 < INT16_MIN) {
			fprintf(stderr, "%s is not valid i16 integer\n", key_value_s);
			exit(EXIT_FAILURE);
		}
		err = cmap_set_int16(handle, key_name, i64);
		break;
	case CMAP_VALUETYPE_INT32:
		if (i64 > INT32_MAX || i64 < INT32_MIN) {
			fprintf(stderr, "%s is not valid i32 integer\n", key_value_s);
			exit(EXIT_FAILURE);
		}
		err = cmap_set_int32(handle, key_name, i64);
		break;
	case CMAP_VALUETYPE_INT64:
		err = cmap_set_int64(handle, key_name, i64);
		break;

	case CMAP_VALUETYPE_UINT8:
		if (u64 > UINT8_MAX) {
			fprintf(stderr, "%s is not valid u8 integer\n", key_value_s);
			exit(EXIT_FAILURE);
		}
		err = cmap_set_uint8(handle, key_name, u64);
		break;
	case CMAP_VALUETYPE_UINT16:
		if (u64 > UINT16_MAX) {
			fprintf(stderr, "%s is not valid u16 integer\n", key_value_s);
			exit(EXIT_FAILURE);
		}
		err = cmap_set_uint16(handle, key_name, u64);
		break;
	case CMAP_VALUETYPE_UINT32:
		if (u64 > UINT32_MAX) {
			fprintf(stderr, "%s is not valid u32 integer\n", key_value_s);
			exit(EXIT_FAILURE);
		}
		err = cmap_set_uint32(handle, key_name, u64);
		break;
	case CMAP_VALUETYPE_UINT64:
		err = cmap_set_uint64(handle, key_name, u64);
		break;
	case CMAP_VALUETYPE_FLOAT:
		err = cmap_set_float(handle, key_name, flt);
		break;
	case CMAP_VALUETYPE_DOUBLE:
		err = cmap_set_double(handle, key_name, dbl);
		break;
	case CMAP_VALUETYPE_STRING:
		err = cmap_set_string(handle, key_name, key_value_s);
		break;
	case CMAP_VALUETYPE_BINARY:
		err = set_key_bin(handle, key_name, key_value_s);
		break;
	}

	if (err != CS_OK) {
		fprintf (stderr, "Failed to set key %s. Error %s\n", key_name, cs_strerror(err));
		exit (EXIT_FAILURE);
	}
}
Exemple #29
0
/*
 * CFG functionality stolen from node_name() in corosync-quorumtool.c
 * This resolves the first address assigned to a node and returns the name or IP address.
 */
char *
corosync_node_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid)
{
    int lpc = 0;
    int rc = CS_OK;
    int retries = 0;
    char *name = NULL;
    cmap_handle_t local_handle = 0;

    /* nodeid == 0 == CMAN_NODEID_US */
    if (nodeid == 0) {
        nodeid = get_local_nodeid(0);
    }

    if (cmap_handle == 0 && local_handle == 0) {
        retries = 0;
        crm_trace("Initializing CMAP connection");
        do {
            rc = cmap_initialize(&local_handle);
            if (rc != CS_OK) {
                retries++;
                crm_debug("API connection setup failed: %s.  Retrying in %ds", cs_strerror(rc),
                          retries);
                sleep(retries);
            }

        } while (retries < 5 && rc != CS_OK);

        if (rc != CS_OK) {
            crm_warn("Could not connect to Cluster Configuration Database API, error %s",
                     cs_strerror(rc));
            local_handle = 0;
        }
    }

    if (cmap_handle == 0) {
        cmap_handle = local_handle;
    }

    while (name == NULL && cmap_handle != 0) {
        uint32_t id = 0;
        char *key = NULL;

        key = g_strdup_printf("nodelist.node.%d.nodeid", lpc);
        rc = cmap_get_uint32(cmap_handle, key, &id);
        crm_trace("Checking %u vs %u from %s", nodeid, id, key);
        g_free(key);

        if (rc != CS_OK) {
            break;
        }

        if (nodeid == id) {
            crm_trace("Searching for node name for %u in nodelist.node.%d %s", nodeid, lpc, name);
            if (name == NULL) {
                key = g_strdup_printf("nodelist.node.%d.ring0_addr", lpc);
                rc = cmap_get_string(cmap_handle, key, &name);
                crm_trace("%s = %s", key, name);

                if (node_name_is_valid(key, name) == FALSE) {
                    free(name);
                    name = NULL;
                }
                g_free(key);
            }

            if (name == NULL) {
                key = g_strdup_printf("nodelist.node.%d.name", lpc);
                rc = cmap_get_string(cmap_handle, key, &name);
                crm_trace("%s = %s %d", key, name, rc);
                g_free(key);
            }
            break;
        }

        lpc++;
    }

    if(local_handle) {
        cmap_finalize(local_handle);
    }

    if (name == NULL) {
        crm_notice("Unable to get node name for nodeid %u", nodeid);
    }
    return name;
}
Exemple #30
0
gboolean
read_config(void)
{
    int rc = CS_OK;
    int retries = 0;
    gboolean have_log = FALSE;

    char *logging_debug = NULL;
    char *logging_logfile = NULL;
    char *logging_to_logfile = NULL;
    char *logging_to_syslog = NULL;
    char *logging_syslog_facility = NULL;    

    enum cluster_type_e stack = pcmk_cluster_unknown;

#if HAVE_CONFDB
    char *value = NULL;
    confdb_handle_t config;
    confdb_handle_t top_handle = 0;
    hdb_handle_t local_handle;
    static confdb_callbacks_t callbacks = { };

    do {
        rc = confdb_initialize(&config, &callbacks);
	if(rc != CS_OK) {
	    retries++;
	    printf("Connection setup failed: %d.  Retrying in %ds\n", rc, retries);
	    sleep(retries);

	} else {
            break;
        }

    } while(retries < 5);
#elif HAVE_CMAP
    cmap_handle_t local_handle;

    /* There can be only one (possibility if confdb isn't around) */
    do {
        rc = cmap_initialize(&local_handle);
	if(rc != CS_OK) {
	    retries++;
	    printf("API connection setup failed: %s.  Retrying in %ds\n",
                   cs_strerror(rc), retries);
	    crm_info("API connection setup failed: %s.  Retrying in %ds",
                     cs_strerror(rc), retries);
	    sleep(retries);

	} else {
            break;
        }

    } while(retries < 5);
#endif

    if (rc != CS_OK) {
        printf("Could not connect to Cluster Configuration Database API, error %d\n", rc);
        crm_warn("Could not connect to Cluster Configuration Database API, error %d", rc);
        return FALSE;
    }

    stack = get_cluster_type();
    crm_info("Reading configure for stack: %s", name_for_cluster_type(stack));
    
    /* =::=::= Should we be here =::=::= */
    if (stack == pcmk_cluster_corosync) {
        setenv("HA_cluster_type", "corosync", 1);
        setenv("HA_quorum_type",  "corosync", 1);

#if HAVE_CONFDB
    } else if (stack == pcmk_cluster_cman) {
        setenv("HA_cluster_type", "cman", 1);
        setenv("HA_quorum_type",  "cman", 1);
        enable_crmd_as_root(TRUE);
        use_cman = TRUE;

    } else if (stack == pcmk_cluster_classic_ais) {
        setenv("HA_cluster_type", "openais", 1);
        setenv("HA_quorum_type",  "pcmk", 1);

        /* Look for a service block to indicate our plugin is loaded */
        top_handle = config_find_init(config);
        local_handle = config_find_next(config, "service", top_handle);

        while (local_handle) {
            get_config_opt(config, local_handle, "name", &value, NULL);
            if (safe_str_eq("pacemaker", value)) {
                get_config_opt(config, local_handle, "ver", &value, "0");
                if (safe_str_eq(value, "1")) {
                    get_config_opt(config, local_handle, "use_logd", &value, "no");
                    setenv("HA_use_logd", value, 1);
                    setenv("HA_LOGD", value, 1);

                    get_config_opt(config, local_handle, "use_mgmtd", &value, "no");
                    enable_mgmtd(crm_is_true(value));

                } else {
                    crm_err("We can only start Pacemaker from init if using version 1"
                            " of the Pacemaker plugin for Corosync.  Terminating.");
                    exit(100);
                }
                break;
            }
            local_handle = config_find_next(config, "service", top_handle);
        }
        free(value);

#endif
    } else {
        crm_err("Unsupported stack type: %s", name_for_cluster_type(stack));
        return FALSE;
    }

#if HAVE_CONFDB
    top_handle = config_find_init(config);
    local_handle = config_find_next(config, "logging", top_handle);
    
    get_config_opt(config, local_handle, "debug", &logging_debug, "off");
    get_config_opt(config, local_handle, "logfile", &logging_logfile, "/var/log/pacemaker");
    get_config_opt(config, local_handle, "to_logfile", &logging_to_logfile, "off");
    get_config_opt(config, local_handle, "to_syslog", &logging_to_syslog, "on");
    get_config_opt(config, local_handle, "syslog_facility", &logging_syslog_facility, "daemon");

    confdb_finalize(config);    
#elif HAVE_CMAP
    /* =::=::= Logging =::=::= */
    get_config_opt(local_handle, "logging.debug", &logging_debug, "off");
    get_config_opt(local_handle, "logging.logfile", &logging_logfile, "/var/log/pacemaker");
    get_config_opt(local_handle, "logging.to_logfile", &logging_to_logfile, "off");
    get_config_opt(local_handle, "logging.to_syslog", &logging_to_syslog, "on");
    get_config_opt(local_handle, "logging.syslog_facility", &logging_syslog_facility, "daemon");

    cmap_finalize(local_handle); 
#endif
    
    if (crm_is_true(logging_debug)) {
        setenv("HA_debug", "1", 1);
        if(get_crm_log_level() < LOG_DEBUG) {
            set_crm_log_level(LOG_DEBUG);
        }

    } else {
        setenv("HA_debug", "0", 1);
    }

    if (crm_is_true(logging_to_logfile)) {
        if(crm_add_logfile(logging_logfile)) {
            setenv("HA_debugfile", logging_logfile, 1);
            setenv("HA_DEBUGLOG", logging_logfile, 1);
            setenv("HA_LOGFILE", logging_logfile, 1);
            have_log = TRUE;

        } else {
            crm_err("Couldn't create logfile: %s", logging_logfile);
        }
    }

    if (have_log && crm_is_true(logging_to_syslog) == FALSE) {
        crm_info("User configured file based logging and explicitly disabled syslog.");
        free(logging_syslog_facility);
        logging_syslog_facility = NULL;

    } else {
        if (crm_is_true(logging_to_syslog) == FALSE) {
            crm_err
                ("Please enable some sort of logging, either 'to_logfile: on' or  'to_syslog: on'.");
            crm_err("If you use file logging, be sure to also define a value for 'logfile'");
        }
    }

    if(logging_syslog_facility) {
        setenv("HA_logfacility", logging_syslog_facility, 1);
        setenv("HA_LOGFACILITY", logging_syslog_facility, 1);
    } else {
        unsetenv("HA_logfacility");
        unsetenv("HA_LOGFACILITY");
    }
    
    free(logging_debug);
    free(logging_logfile);
    free(logging_to_logfile);
    free(logging_to_syslog);
    free(logging_syslog_facility);
    return TRUE;
}