コード例 #1
0
void br_shutdown(void)
{
    sysfs_close_class(br_class_net);
    br_class_net = NULL;
    close(br_socket_fd);
    br_socket_fd = -1;
}
コード例 #2
0
int br_refresh(void)
{
    if (br_class_net) {
        sysfs_close_class(br_class_net);
        br_class_net = sysfs_open_class("net");
    }

    return 0;
}
コード例 #3
0
ファイル: sysfs_class.c プロジェクト: tapwag/drakx
/**
 * sysfs_open_class: opens specific class and all its devices on system
 * returns sysfs_class structure with success or NULL with error.
 */
struct sysfs_class *sysfs_open_class(const char *name)
{
    struct sysfs_class *cls = NULL;
    char *c, classpath[SYSFS_PATH_MAX];

    if (!name) {
        errno = EINVAL;
        return NULL;
    }

    memset(classpath, 0, SYSFS_PATH_MAX);
    if ((sysfs_get_mnt_path(classpath, SYSFS_PATH_MAX)) != 0) {
        dprintf("Sysfs not supported on this system\n");
        return NULL;
    }

    safestrcat(classpath, "/");
    if (strcmp(name, SYSFS_BLOCK_NAME) == 0) {
        safestrcat(classpath, SYSFS_BLOCK_NAME);
        if (!sysfs_path_is_dir(classpath))
            goto done;
        c = strrchr(classpath, '/');
        *(c+1) = '\0';
    }
    safestrcat(classpath, SYSFS_CLASS_NAME);
    safestrcat(classpath, "/");
    safestrcat(classpath, name);
done:
    if (sysfs_path_is_dir(classpath)) {
        dprintf("Class %s not found on the system\n", name);
        return NULL;
    }

    cls = alloc_class();
    if (cls == NULL) {
        dprintf("calloc failed\n");
        return NULL;
    }
    safestrcpy(cls->name, name);
    safestrcpy(cls->path, classpath);
    if ((sysfs_remove_trailing_slash(cls->path)) != 0) {
        dprintf("Invalid path to class device %s\n", cls->path);
        sysfs_close_class(cls);
        return NULL;
    }

    return cls;
}