1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-05 23:51:28 +03:00

use major:minor as entries in symlink stack instead of devpath

This commit is contained in:
Kay Sievers 2010-03-10 17:29:27 +01:00
parent a00ff5db02
commit af24bb178e

View File

@ -245,28 +245,26 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons
for (;;) { for (;;) {
struct udev_device *dev_db; struct udev_device *dev_db;
struct dirent *dent; struct dirent *dent;
char devpath[UTIL_PATH_SIZE]; int maj, min;
char syspath[UTIL_PATH_SIZE]; char type, type2;
ssize_t len; dev_t devnum;
dent = readdir(dir); dent = readdir(dir);
if (dent == NULL || dent->d_name[0] == '\0') if (dent == NULL || dent->d_name[0] == '\0')
break; break;
if (dent->d_name[0] == '.') if (dent->d_name[0] == '.')
continue; continue;
dbg(udev, "found '%s/%s'\n", stackdir, dent->d_name); if (sscanf(dent->d_name, "%c%i:%i", &type, &maj, &min) != 3)
len = readlinkat(dirfd(dir), dent->d_name, devpath, sizeof(devpath));
if (len <= 0 || len == (ssize_t)sizeof(devpath))
continue; continue;
devpath[len] = '\0'; info(udev, "found '%c%i:%i' claiming '%s'\n", type, maj, min, stackdir);
util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL); devnum = makedev(maj, min);
info(udev, "found '%s' claiming '%s'\n", syspath, stackdir);
/* did we find ourself? */ /* did we find ourself? */
if (strcmp(udev_device_get_syspath(dev), syspath) == 0) type2 = strcmp(udev_device_get_subsystem(dev), "block") == 0 ? 'b' : 'c';
if (udev_device_get_devnum(dev) == devnum && type == type2)
continue; continue;
dev_db = udev_device_new_from_syspath(udev, syspath); dev_db = udev_device_new_from_devnum(udev, type, devnum);
if (dev_db != NULL) { if (dev_db != NULL) {
const char *devnode; const char *devnode;
@ -276,7 +274,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons
udev_device_get_devnode(dev_db), udev_device_get_devlink_priority(dev_db)); udev_device_get_devnode(dev_db), udev_device_get_devlink_priority(dev_db));
if (target == NULL || udev_device_get_devlink_priority(dev_db) > priority) { if (target == NULL || udev_device_get_devlink_priority(dev_db) > priority) {
info(udev, "'%s' claims priority %i for '%s'\n", info(udev, "'%s' claims priority %i for '%s'\n",
syspath, udev_device_get_devlink_priority(dev_db), stackdir); udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir);
priority = udev_device_get_devlink_priority(dev_db); priority = udev_device_get_devlink_priority(dev_db);
util_strscpy(buf, bufsize, devnode); util_strscpy(buf, bufsize, devnode);
target = buf; target = buf;
@ -328,11 +326,15 @@ static void link_update(struct udev_device *dev, const char *slink, bool add)
dbg(udev, "creating index: '%s'\n", filename); dbg(udev, "creating index: '%s'\n", filename);
do { do {
int fd;
err = util_create_path(udev, filename); err = util_create_path(udev, filename);
if (err != 0 && err != -ENOENT) if (err != 0 && err != -ENOENT)
break; break;
err = symlink(udev_device_get_devpath(dev), filename); fd = open(filename, O_WRONLY|O_CREAT, 0444);
if (err != 0) if (fd >= 0)
close(fd);
else
err = -errno; err = -errno;
} while (err == -ENOENT); } while (err == -ENOENT);
} }