+ /* create parent directories if needed */
+ if (strrchr(dev->name, '/'))
+ create_path(filename);
+
+ if (dev->owner[0] != '\0') {
+ char *endptr;
+ unsigned long id = strtoul(dev->owner, &endptr, 10);
+ if (endptr[0] == '\0')
+ uid = (uid_t) id;
+ else {
+ if (strncmp(dev->owner, LOCAL_USER, sizeof(LOCAL_USER)) == 0)
+ set_to_local_user(dev->owner);
+
+ struct passwd *pw = getpwnam(dev->owner);
+ if (pw == NULL)
+ dbg("specified user unknown '%s'", dev->owner);
+ else
+ uid = pw->pw_uid;
+ }
+ }
+
+ if (dev->group[0] != '\0') {
+ char *endptr;
+ unsigned long id = strtoul(dev->group, &endptr, 10);
+ if (endptr[0] == '\0')
+ gid = (gid_t) id;
+ else {
+ struct group *gr = getgrnam(dev->group);
+ if (gr == NULL)
+ dbg("specified group unknown '%s'", dev->group);
+ else
+ gid = gr->gr_gid;
+ }
+ }
+
+ if (!fake) {
+ unlink_entry(filename);
+ info("creating device node '%s'", filename);
+ make_node(filename, dev->major, dev->minor, dev->mode, uid, gid);
+ } else {
+ info("creating device node '%s', major = '%d', minor = '%d', "
+ "mode = '%#o', uid = '%d', gid = '%d'", filename,
+ dev->major, dev->minor, (mode_t)dev->mode, uid, gid);
+ }
+
+ /* create partitions if requested */
+ if (dev->partitions > 0) {
+ info("creating device partition nodes '%s[1-%i]'", filename, dev->partitions);
+ if (!fake) {
+ for (i = 1; i <= dev->partitions; i++) {
+ strfieldcpy(partitionname, filename);
+ strintcat(partitionname, i);
+ unlink_entry(partitionname);
+ make_node(partitionname, dev->major,
+ dev->minor + i, dev->mode, uid, gid);
+ }
+ }
+ }
+
+ if (!fake)
+ selinux_add_node(filename);
+
+ /* create symlink if requested */
+ if (dev->symlink[0] != '\0') {
+ symlinks = dev->symlink;
+ while (1) {
+ linkname = strsep(&symlinks, " ");
+ if (linkname == NULL || linkname[0] == '\0')
+ break;
+
+ strfieldcpy(filename, udev_root);
+ strfieldcat(filename, linkname);
+ dbg("symlink '%s' to node '%s' requested", filename, dev->name);
+ if (!fake)
+ if (strrchr(linkname, '/'))
+ create_path(filename);
+
+ /* optimize relative link */
+ linktarget[0] = '\0';
+ i = 0;
+ tail = 0;
+ while ((dev->name[i] == linkname[i]) && dev->name[i]) {
+ if (dev->name[i] == '/')
+ tail = i+1;
+ i++;
+ }
+ while (linkname[i] != '\0') {
+ if (linkname[i] == '/')
+ strfieldcat(linktarget, "../");
+ i++;
+ }
+
+ strfieldcat(linktarget, &dev->name[tail]);
+
+ if (!fake)
+ unlink_entry(filename);
+
+ dbg("symlink(%s, %s)", linktarget, filename);
+ if (!fake) {
+ retval = symlink(linktarget, filename);
+ if (retval != 0)
+ dbg("symlink(%s, %s) failed with error '%s'",
+ linktarget, filename, strerror(errno));
+ }
+ }
+ }