]> err.no Git - systemd/commitdiff
[PATCH] remove now works!
authorgreg@kroah.com <greg@kroah.com>
Thu, 10 Apr 2003 18:16:34 +0000 (11:16 -0700)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:01:38 +0000 (21:01 -0700)
test
udev.c

diff --git a/test b/test
index 9cab4a6db7ff6b8a45ac097e3661038ff6e9cf25..730f0a446a1cd0065da8780c45c4e0dfc09db6f5 100644 (file)
--- a/test
+++ b/test
@@ -1,5 +1,6 @@
 #!/bin/sh
-export ACTION=add
-export DEVPATH=/devices/pci0/00:09.0/usb1/1-1/1-1.2/ttyUSB7
+#export ACTION=add
+export ACTION=remove
+export DEVPATH=/devices/pci0/00:09.0/usb1/1-1/1-1.1/ttyUSB7
 
 ./udev tty
diff --git a/udev.c b/udev.c
index 4bb41a869638edb48881351d51476113a89d3bec..5aa9b43d43134d1092c38036e526d4079baa99c7 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -183,7 +183,21 @@ static int create_node(char *name, char type, int major, int minor, int mode)
        return retval;
 }
 
-static int add_node(char *device, char type)
+/*
+ * We also want to clean up any symlinks that were created in create_node()
+ */
+static int delete_node(char *name)
+{
+       char filename[255];
+
+       strncpy(filename, UDEV_ROOT, sizeof(filename));
+       strncat(filename, name, sizeof(filename));
+
+       dbg("unlinking %s", filename);
+       return unlink(filename);
+}
+
+static int add_device(char *device, char type)
 {
        char *name;
        int major;
@@ -217,9 +231,22 @@ exit:
        return retval;
 }
 
-static int remove_node(char *device)
+static int remove_device(char *device)
 {
-       return 0;
+       char *name;
+       int retval = 0;
+
+       name = get_name(device, 0, 0);
+       if (name == NULL) {
+               dbg ("get_name failed");
+               retval = -ENODEV;
+               goto exit;
+       }
+
+       return delete_node(name);
+
+exit:
+       return retval;
 }
 
 int main(int argc, char *argv[])
@@ -256,10 +283,10 @@ int main(int argc, char *argv[])
        dbg("looking at %s", device);
 
        if (strcmp(action, "add") == 0)
-               return add_node(device, type);
+               return add_device(device, type);
 
        if (strcmp(action, "remove") == 0)
-               return remove_node(device);
+               return remove_device(device);
 
        dbg("Unknown action: %s", action);
        return -EINVAL;