예제 #1
0
static void
test_write_hostname ()
{
	gchar *hostname = read_hostname ("hostname");
	gchar *tmp;

	write_hostname ("gentoo-nm", "hostname");
	tmp = read_hostname ("hostname");
	ASSERT (strcmp (tmp, "gentoo-nm") == 0,
		"write hostname", "write hostname error");
	write_hostname (hostname, "hostname");
	g_free (tmp);
	g_free (hostname);
}
예제 #2
0
static void
test_read_hostname ()
{
	gchar *hostname = read_hostname ("hostname");

	ASSERT (hostname != NULL, "get hostname", "hostname is NULL");
	ASSERT (strcmp ("gentoo", hostname) == 0,
		"get hostname",
		"hostname is not correctly read, read:%s, expected: gentoo",
		hostname);
	g_free (hostname);
}
static void
update_system_hostname (gpointer config)
{
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Updating hostname");

	if (priv->hostname)
		g_free (priv->hostname);
	priv->hostname = read_hostname (IFNET_SYSTEM_HOSTNAME_FILE);

	g_object_notify (G_OBJECT (config),
			 NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Hostname updated to: %s",
		      priv->hostname);
}
예제 #4
0
파일: functions.c 프로젝트: tijuca/openmct
/* function: getting some systems informations
 * return: nothing, yust fill the struct statistics
 */
int get_sysinfos(void)
{
    // getting the hostname
    statistics.hostname=Strdup(read_hostname());
    // the revision of the image
    statistics.rev=Strdup(read_hardware(1));
    // the vendor + model
    statistics.vendor=Strdup(read_hardware(2));
    // the uptime
    statistics.uptime=Strdup(get_uptime());
    // the kernel version
    statistics.kernel=Strdup(kernelversion());
    // the CPU version
    statistics.cpu=Strdup(get_cpuinfo());
    return 0;
}
예제 #5
0
int hostname_setup(void) {
        int r;
        char *b = NULL;
        const char *hn = NULL;
        bool enoent = false;

        r = read_hostname(&b);
        if (r < 0) {
                hn = NULL;

                if (r == -ENOENT)
                        enoent = true;
                else
                        log_warning("Failed to read configured hostname: %s", strerror(-r));
        } else
                hn = b;

        if (isempty(hn)) {
                /* Don't override the hostname if it is already set
                 * and not explicitly configured */
                if (hostname_is_set())
                        goto finish;

                if (enoent)
                        log_info("No hostname configured.");

                hn = "localhost";
        }

        if (sethostname(hn, strlen(hn)) < 0) {
                log_warning("Failed to set hostname to <%s>: %m", hn);
                r = -errno;
        } else
                log_info("Set hostname to <%s>.", hn);

finish:
        free(b);

        return r;
}