Exemplo n.º 1
0
static struct json_object * get_hostname(void) {
	struct json_object *ret = NULL;

	struct uci_context *ctx = uci_alloc_context();
	ctx->flags &= ~UCI_FLAG_STRICT;

	char section[] = "system.@system[0]";
	struct uci_ptr ptr;
	if (uci_lookup_ptr(ctx, &ptr, section, true))
		goto error;

	struct uci_section *s = ptr.s;

	const char *hostname = uci_lookup_option_string(ctx, s, "pretty_hostname");

	if (!hostname)
		hostname = uci_lookup_option_string(ctx, s, "hostname");

	ret = gluonutil_wrap_string(hostname);

error:
	uci_free_context(ctx);

	return ret;
}
Exemplo n.º 2
0
static struct json_object * get_hostname(void) {
	struct utsname utsname;

	if (uname(&utsname))
		return NULL;

	return gluonutil_wrap_string(utsname.nodename);
}