chiark / gitweb /
[PATCH] Increase the name size as requested by Richard Gooch <rgooch@ras.ucalgary.ca>
[elogind.git] / udev-remove.c
index 8794429635bd0caec5f53b294dcd713464f720b2..d9097134504a6a1cd2857b83305d683162b43c82 100644 (file)
@@ -29,6 +29,7 @@
 #include <errno.h>
 
 #include "udev.h"
+#include "udev_lib.h"
 #include "udev_version.h"
 #include "udev_dbus.h"
 #include "logging.h"
@@ -51,6 +52,8 @@ static int delete_path(char *path)
 
                /* remove if empty */
                retval = rmdir(path);
+               if (errno == ENOENT)
+                       retval = 0;
                if (retval) {
                        if (errno == ENOTEMPTY)
                                return 0;
@@ -65,18 +68,21 @@ static int delete_path(char *path)
 
 static int delete_node(struct udevice *dev)
 {
-       char filename[255];
-       char partitionname[255];
-       char *symlinks;
-       char *linkname;
+       char filename[NAME_SIZE];
+       char linkname[NAME_SIZE];
+       char partitionname[NAME_SIZE];
        int retval;
        int i;
+       char *pos;
+       int len;
 
        strfieldcpy(filename, udev_root);
        strfieldcat(filename, dev->name);
 
        info("removing device node '%s'", filename);
        retval = unlink(filename);
+       if (errno == ENOENT)
+               retval = 0;
        if (retval) {
                dbg("unlink(%s) failed with error '%s'",
                        filename, strerror(errno));
@@ -87,7 +93,8 @@ static int delete_node(struct udevice *dev)
        if (dev->partitions > 0) {
                info("removing partitions '%s[1-%i]'", filename, dev->partitions);
                for (i = 1; i <= dev->partitions; i++) {
-                       sprintf(partitionname, "%s%i", filename, i);
+                       strfieldcpy(partitionname, filename);
+                       strintcat(partitionname, i);
                        unlink(partitionname);
                }
        }
@@ -96,26 +103,22 @@ static int delete_node(struct udevice *dev)
        if (strchr(dev->name, '/'))
                delete_path(filename);
 
-       if (dev->symlink[0] != '\0') {
-               symlinks = dev->symlink;
-               while (1) {
-                       linkname = strsep(&symlinks, " ");
-                       if (linkname == NULL)
-                               break;
-
-                       strfieldcpy(filename, udev_root);
-                       strfieldcat(filename, linkname);
-
-                       dbg("unlinking symlink '%s'", filename);
-                       retval = unlink(filename);
-                       if (retval) {
-                               dbg("unlink(%s) failed with error '%s'",
-                                       filename, strerror(errno));
-                               return retval;
-                       }
-                       if (strchr(dev->symlink, '/')) {
-                               delete_path(filename);
-                       }
+       foreach_strpart(dev->symlink, " ", pos, len) {
+               strfieldcpymax(linkname, pos, len+1);
+               strfieldcpy(filename, udev_root);
+               strfieldcat(filename, linkname);
+
+               dbg("unlinking symlink '%s'", filename);
+               retval = unlink(filename);
+               if (errno == ENOENT)
+                       retval = 0;
+               if (retval) {
+                       dbg("unlink(%s) failed with error '%s'",
+                               filename, strerror(errno));
+                       return retval;
+               }
+               if (strchr(dev->symlink, '/')) {
+                       delete_path(filename);
                }
        }