コード例 #1
0
/* Return a shvarFile for this interface, taking into account one level of
 * inheritance (eeewww). */
static shvarFile *
shvarfilesGet(const char *interfaceName) {
    shvarFile *ifcfg = NULL;
    char ifcfgName[PATH_MAX];
    char *ifcfgParentDiff = NULL;

    /* Start with the basic configuration. */
    snprintf(ifcfgName, sizeof(ifcfgName), "%s%s", IFCFGPREFIX, interfaceName);
    ifcfg = svNewFile(ifcfgName);
    if (ifcfg == NULL)
	    return NULL;

    /* Do we have a parent interface (i.e., for ppp0-blah, ppp0) to inherit? */
    ifcfgParentDiff = strchr(ifcfgName + sizeof(IFCFGPREFIX), '-');
    if (ifcfgParentDiff) {
        *ifcfgParentDiff = '\0';
	ifcfg->parent = svNewFile(ifcfgName);
    }

    /* This is very unclean, but we have to close the shvar descriptors in
     * case they've been numbered STDOUT_FILENO or STDERR_FILENO, which would
     * be disastrous if inherited by a child process. */
    close (ifcfg->fd);
    ifcfg->fd = 0;

    if (ifcfg->parent) {
	close (ifcfg->parent->fd);
	ifcfg->parent->fd = 0;
    }

    return ifcfg;
}
コード例 #2
0
ファイル: utils.c プロジェクト: domsom/NetworkManager-ds
shvarFile *
utils_get_extra_ifcfg (const char *parent, const char *tag, gboolean should_create)
{
	shvarFile *ifcfg = NULL;
	char *path;

	path = utils_get_extra_path (parent, tag);
	if (!path)
		return NULL;

	if (should_create && !g_file_test (path, G_FILE_TEST_EXISTS))
		ifcfg = svCreateFile (path);

	if (!ifcfg)
		ifcfg = svNewFile (path);

	g_free (path);
	return ifcfg;
}