X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev_add.c;h=24a20bba9bfb9857da214b289ef16ef7d1143ca9;hb=045b1f0f7a7af2182e7109f472d873f1cc0c5e4b;hp=4fb5ef18c06149200406753edfc0eb08acbd7a40;hpb=02fa9ae58920b431bc37182716dd863f1c482651;p=elogind.git diff --git a/udev_add.c b/udev_add.c index 4fb5ef18c..24a20bba9 100644 --- a/udev_add.c +++ b/udev_add.c @@ -38,13 +38,12 @@ #include "libsysfs/sysfs/libsysfs.h" #include "udev.h" -#include "udev_lib.h" +#include "udev_utils.h" #include "udev_version.h" #include "logging.h" #include "namedev.h" #include "udev_db.h" - -#include "selinux.h" +#include "udev_selinux.h" /* * the major/minor of a device is stored in a file called "dev" @@ -68,7 +67,7 @@ error: return -1; } -static int make_node(char *file, int major, int minor, unsigned int mode, uid_t uid, gid_t gid) +static int make_node(struct udevice *udev, char *file, int major, int minor, unsigned int mode, uid_t uid, gid_t gid) { struct stat stats; int retval = 0; @@ -80,7 +79,7 @@ static int make_node(char *file, int major, int minor, unsigned int mode, uid_t if (((stats.st_mode & S_IFMT) == S_IFBLK || (stats.st_mode & S_IFMT) == S_IFCHR) && (stats.st_rdev == makedev(major, minor))) { dbg("preserve file '%s', cause it has correct dev_t", file); - selinux_setfilecon(file,stats.st_mode); + selinux_setfilecon(file, udev->kernel_name, stats.st_mode); goto perms; } @@ -90,7 +89,7 @@ static int make_node(char *file, int major, int minor, unsigned int mode, uid_t dbg("already present file '%s' unlinked", file); create: - selinux_setfscreatecon(file, mode); + selinux_setfscreatecon(file, udev->kernel_name, mode); retval = mknod(file, mode, makedev(major, minor)); if (retval != 0) { dbg("mknod(%s, %#o, %u, %u) failed with error '%s'", @@ -184,12 +183,12 @@ static int create_node(struct udevice *udev) if (!udev->test_run) { info("creating device node '%s'", filename); - if (make_node(filename, udev->major, udev->minor, udev->mode, uid, gid) != 0) + if (make_node(udev, filename, udev->major, udev->minor, udev->mode, uid, gid) != 0) goto error; } else { info("creating device node '%s', major = '%d', minor = '%d', " "mode = '%#o', uid = '%d', gid = '%d'", filename, - udev->major, udev->minor, (mode_t)udev->mode, uid, gid); + udev->major, udev->minor, udev->mode, uid, gid); } /* create all_partitions if requested */ @@ -199,7 +198,7 @@ static int create_node(struct udevice *udev) for (i = 1; i <= udev->partitions; i++) { strfieldcpy(partitionname, filename); strintcat(partitionname, i); - make_node(partitionname, udev->major, udev->minor + i, udev->mode, uid, gid); + make_node(udev, partitionname, udev->major, udev->minor + i, udev->mode, uid, gid); } } } @@ -237,7 +236,7 @@ static int create_node(struct udevice *udev) dbg("symlink(%s, %s)", linktarget, filename); if (!udev->test_run) { - selinux_setfscreatecon(filename, S_IFLNK); + selinux_setfscreatecon(filename, udev->kernel_name, S_IFLNK); unlink(filename); if (symlink(linktarget, filename) != 0) dbg("symlink(%s, %s) failed with error '%s'", @@ -292,7 +291,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) } if (namedev_name_device(udev, class_dev) != 0) - goto exit; + return 0; dbg("adding name='%s'", udev->name); @@ -318,15 +317,16 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) if (retval != 0) goto exit; - /* we've changed the name, now fake the devpath, - * cause original kernel name sleeps with the fishes - * and we don't get any event from the kernel now + /* we've changed the name, now fake the devpath, cause the + * original kernel name sleeps with the fishes and we don't + * get an event from the kernel with the new name */ pos = strrchr(udev->devpath, '/'); if (pos != NULL) { pos[1] = '\0'; strfieldcat(udev->devpath, udev->name); setenv("DEVPATH", udev->devpath, 1); + setenv("INTERFACE", udev->name, 1); } /* use netif name for the environment */