summaryrefslogtreecommitdiff
path: root/udev-remove.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2003-11-12 03:48:01 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:06:23 -0700
commit218eae87273e6b1d401ac67f94d648c9f39a30fa (patch)
tree122975e80fd3008c3e82ed12b55588cb425ba2e6 /udev-remove.c
parentc19a6b304cd7a727da9758853134b557f5f40705 (diff)
[PATCH] add support for subdirs
support subdirectory creation/removal for NAME="/devfs/is/crazy/video0" create parent subdirs for device node if needed remove subdirs when last node is removed
Diffstat (limited to 'udev-remove.c')
-rw-r--r--udev-remove.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/udev-remove.c b/udev-remove.c
index 666928f318..1cf5d5134d 100644
--- a/udev-remove.c
+++ b/udev-remove.c
@@ -69,12 +69,45 @@ exit:
static int delete_node(char *name)
{
char filename[255];
+ int retval;
strncpy(filename, udev_root, sizeof(filename));
strncat(filename, name, sizeof(filename));
dbg("unlinking %s", filename);
- return unlink(filename);
+ retval = unlink(filename);
+ if (retval) {
+ dbg("unlink(%s) failed with error '%s'",
+ filename, strerror(errno));
+ return retval;
+ }
+
+ /* remove subdirectories */
+ if (strchr(name, '/')) {
+ char *pos;
+
+ pos = strrchr(filename, '/');
+ while (1) {
+ *pos = 0x00;
+ pos = strrchr(filename, '/');
+
+ /* don't remove the last one */
+ if ((pos == filename) || (pos == NULL))
+ break;
+
+ /* remove if empty */
+ retval = rmdir(filename);
+ if (retval) {
+ if (errno == ENOTEMPTY)
+ return 0;
+ dbg("rmdir(%s) failed with error '%s'",
+ filename, strerror(errno));
+ break;
+ }
+ dbg("removed %s", filename);
+ }
+ }
+ return retval;
}
int udev_remove_device(char *device, char *subsystem)