예제 #1
0
static void
read_connections (SCPluginIfcfg *plugin)
{
    GDir *dir;
    GError *err = NULL;

    dir = g_dir_open (IFCFG_DIR, 0, &err);
    if (dir) {
        const char *item;

        while ((item = g_dir_read_name (dir))) {
            char *full_path;

            if (utils_should_ignore_file (item, TRUE))
                continue;

            full_path = g_build_filename (IFCFG_DIR, item, NULL);
            if (utils_get_ifcfg_name (full_path, TRUE))
                _internal_new_connection (plugin, full_path, NULL, NULL);
            g_free (full_path);
        }

        g_dir_close (dir);
    } else {
        PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Can not read directory '%s': %s", IFCFG_DIR, err->message);
        g_error_free (err);
    }
}
예제 #2
0
static void
read_connections (NMSystemConfigInterface *config)
{
	SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
	GDir *dir;
	GError *error = NULL;
	const char *item;

	dir = g_dir_open (KEYFILE_DIR, 0, &error);
	if (!dir) {
		PLUGIN_WARN (KEYFILE_PLUGIN_NAME, "Cannot read directory '%s': (%d) %s",
		             KEYFILE_DIR,
		             error ? error->code : -1,
		             error && error->message ? error->message : "(unknown)");
		g_clear_error (&error);
		return;
	}

	while ((item = g_dir_read_name (dir))) {
		NMSettingsConnection *connection;
		char *full_path;

		if (nm_keyfile_plugin_utils_should_ignore_file (item))
			continue;

		full_path = g_build_filename (KEYFILE_DIR, item, NULL);
		PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "parsing %s ... ", item);

		connection = _internal_new_connection (self, full_path, NULL, &error);
		if (connection) {
			PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "    read connection '%s'",
			              nm_connection_get_id (NM_CONNECTION (connection)));
		} else {
			PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "    error: %s",
				          (error && error->message) ? error->message : "(unknown)");
		}
		g_clear_error (&error);
		g_free (full_path);
	}
	g_dir_close (dir);
}
예제 #3
0
/* Read each file in our config directory and try to create a new
 * NMExamplePlugin for it.
 */
static void
read_connections (NMSystemConfigInterface *config)
{
	SCPluginExample *self = SC_PLUGIN_EXAMPLE (config);
	GDir *dir;
	GError *error = NULL;
	const char *item;

	dir = g_dir_open (EXAMPLE_DIR, 0, &error);
	if (!dir) {
		nm_log_warn (LOGD_SETTINGS, "Cannot read directory '%s': (%d) %s",
		             EXAMPLE_DIR,
		             error ? error->code : -1,
		             error && error->message ? error->message : "(unknown)");
		g_clear_error (&error);
		return;
	}

	while ((item = g_dir_read_name (dir))) {
		NMSettingsConnection *connection;
		char *full_path;

		/* XXX: Check file extension and ignore "~", ".tmp", ".bak", etc */

		full_path = g_build_filename (EXAMPLE_DIR, item, NULL);
		nm_log_info (LOGD_SETTINGS, "parsing %s ... ", item);

		connection = _internal_new_connection (self, full_path, NULL, &error);
		if (connection) {
			nm_log_info (LOGD_SETTINGS, "    read connection '%s'",
			             nm_connection_get_id (NM_CONNECTION (connection)));
		} else {
			nm_log_info (LOGD_SETTINGS, "    error: %s",
			             (error && error->message) ? error->message : "(unknown)");
		}
		g_clear_error (&error);
		g_free (full_path);
	}
	g_dir_close (dir);
}