chiark / gitweb /
[PATCH] add replace test
[elogind.git] / udev-add.c
index eb1c0fb6761b138f88149d5de5dc01a849473c85..d20e96ee72e7faeb3ebf9c2799b5035646e679e3 100644 (file)
@@ -74,6 +74,8 @@ 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));
@@ -101,15 +103,38 @@ 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));
 
-       uid_t uid = 0;
-       gid_t gid = 0;
-
        if (*dev->owner) {
                char *endptr;
                unsigned long id = strtoul(dev->owner, &endptr, 10);