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=d237834c68b658a103b8c10992948b039899b2b0;hb=75ff8da8ab2e7362ec489fe5280fe5c84fe42741;hpb=c332cfc72da865f3c9f5e34867fc3ac1b0bf0154 diff --git a/udev-add.c b/udev-add.c index d237834c6..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; }