X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev-add.c;h=d20e96ee72e7faeb3ebf9c2799b5035646e679e3;hp=7a89076add32891c287d878a738d2c62803ab1e3;hb=75ff8da8ab2e7362ec489fe5280fe5c84fe42741;hpb=1e959a4b05f93bf31d0603a027b50cb148ef7e90 diff --git a/udev-add.c b/udev-add.c index 7a89076ad..d20e96ee7 100644 --- a/udev-add.c +++ b/udev-add.c @@ -67,12 +67,15 @@ exit: } /* - * We also want to add some permissions here, and possibly some symlinks + * we possibly want to add some symlinks here + * only numeric owner/group id's are supported */ static int create_node(struct udevice *dev) { char filename[255]; int retval = 0; + uid_t uid = 0; + gid_t gid = 0; dev_t res; strncpy(filename, udev_root, sizeof(filename)); @@ -100,13 +103,64 @@ static int create_node(struct udevice *dev) return -EINVAL; } + /* create subdirectories if requested */ + if (strchr(dev->name, '/')) { + char path[255]; + char *pos; + struct stat stats; + + strncpy(path, filename, sizeof(path)); + pos = strchr(path+1, '/'); + while (1) { + pos = strchr(pos+1, '/'); + if (pos == NULL) + break; + *pos = 0x00; + if (stat(path, &stats)) { + retval = mkdir(path, 0755); + if (retval) { + dbg("mkdir(%s) failed with error '%s'", + path, strerror(errno)); + return retval; + } + dbg("created %s", path); + } + *pos = '/'; + } + } + dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor); retval = mknod(filename, dev->mode, res); if (retval) dbg("mknod(%s, %#o, %u, %u) failed with error '%s'", filename, dev->mode, dev->major, dev->minor, strerror(errno)); - // FIXME set the ownership of the node + if (*dev->owner) { + char *endptr; + unsigned long id = strtoul(dev->owner, &endptr, 10); + if (*endptr == 0x00) + uid = (uid_t) id; + else + dbg("only numeric owner id supported: %s", dev->owner); + } + + if (*dev->group) { + char *endptr; + unsigned long id = strtoul(dev->group, &endptr, 10); + if (*endptr == 0x00) + gid = (gid_t) id; + else + dbg("only numeric group id supported: %s", dev->group); + } + + if (uid || gid) { + dbg("chown(%s, %u, %u)", filename, uid, gid); + retval = chown(filename, uid, gid); + if (retval) + dbg("chown(%s, %u, %u) failed with error '%s'", filename, + uid, gid, strerror(errno)); + } + return retval; } @@ -139,26 +193,24 @@ exit: static int sleep_for_dev(char *path) { char filename[SYSFS_PATH_MAX + 6]; - struct stat buf; - int loop = 0; - int retval = -ENODEV; + int loop = SECONDS_TO_WAIT_FOR_DEV; + int retval; strcpy(filename, sysfs_path); strcat(filename, path); strcat(filename, "/dev"); - while (loop < SECONDS_TO_WAIT_FOR_DEV) { + while (loop--) { + struct stat buf; + dbg("looking for %s", filename); retval = stat(filename, &buf); - if (retval == 0) { - retval = 0; + if (!retval) goto exit; - } /* sleep for a second or two to give the kernel a chance to * create the dev file */ sleep(1); - ++loop; } retval = -ENODEV; exit: