X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev_add.c;h=689c2dceecf8e3132f0151d55ca3d5d735ac0d42;hb=069410dbb4769595f57d6208c4a524b2eaa2659c;hp=d07120de62a14103b443c36a11076a669f6fab07;hpb=7a947ce51586fd4212447643df90580542777ab9;p=elogind.git diff --git a/udev_add.c b/udev_add.c index d07120de6..689c2dcee 100644 --- a/udev_add.c +++ b/udev_add.c @@ -34,10 +34,7 @@ #include #include #include -#ifndef __KLIBC__ #include -#include -#endif #include "libsysfs/sysfs/libsysfs.h" #include "udev.h" @@ -46,9 +43,6 @@ #include "logging.h" #include "namedev.h" #include "udevdb.h" -#include "klibc_fixups.h" - -#define LOCAL_USER "$local" #include "selinux.h" @@ -155,37 +149,6 @@ exit: return retval; } -/* get the local logged in user */ -static void set_to_local_user(char *user) -{ - struct utmp *u; - time_t recent = 0; - - strfieldcpymax(user, default_owner_str, OWNER_SIZE); - setutent(); - while (1) { - u = getutent(); - if (u == NULL) - break; - - /* is this a user login ? */ - if (u->ut_type != USER_PROCESS) - continue; - - /* is this a local login ? */ - if (strcmp(u->ut_host, "")) - continue; - - if (u->ut_time > recent) { - recent = u->ut_time; - strfieldcpymax(user, u->ut_user, OWNER_SIZE); - dbg("local user is '%s'", user); - break; - } - } - endutent(); -} - static int create_node(struct udevice *udev) { char filename[NAME_SIZE]; @@ -229,8 +192,6 @@ static int create_node(struct udevice *udev) uid = (uid_t) id; else { struct passwd *pw; - if (strncmp(udev->owner, LOCAL_USER, sizeof(LOCAL_USER)) == 0) - set_to_local_user(udev->owner); pw = getpwnam(udev->owner); if (pw == NULL) @@ -355,7 +316,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) retval = get_major_minor(class_dev, udev); if (retval != 0) { dbg("no dev-file found, do nothing"); - goto close; + return 0; } } @@ -365,45 +326,44 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) dbg("adding name='%s'", udev->name); selinux_init(); - switch (udev->type) { - case 'b': - case 'c': + + if (udev->type == 'b' || udev->type == 'c') { retval = create_node(udev); if (retval != 0) goto exit; - if ((!udev->test_run) && (udevdb_add_dev(udev) != 0)) - dbg("udevdb_add_dev failed, but we are going to try " - "to create the node anyway. But remove might not " - "work properly for this device."); - dev_d_send(udev); - break; + if (udevdb_add_dev(udev) != 0) + dbg("udevdb_add_dev failed, but we create the node anyway, " + "remove might not work for custom names"); + + /* use full path to the environment */ + snprintf(udev->devname, NAME_SIZE-1, "%s%s", udev_root, udev->name); - case 'n': + } else if (udev->type == 'n') { + /* look if we want to change the name of the netif */ if (strcmp(udev->name, udev->kernel_name) != 0) { retval = rename_net_if(udev); if (retval != 0) goto exit; - /* netif's are keyed with the configured name, cause - * the original kernel name sleeps with the fishes + + /* 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 */ pos = strrchr(udev->devpath, '/'); if (pos != NULL) { pos[1] = '\0'; strfieldcat(udev->devpath, udev->name); + setenv("DEVPATH", udev->devpath, 1); } - } - if ((!udev->test_run) && (udevdb_add_dev(udev) != 0)) - dbg("udevdb_add_dev failed"); - dev_d_send(udev); - break; + /* use netif name for the environment */ + strfieldcpy(udev->devname, udev->name); + } } exit: selinux_restore(); -close: - sysfs_close_class_device(class_dev); return retval; }