chiark / gitweb /
cleanup /dev/.udev/queue on startup and exit
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 6 Nov 2008 16:43:12 +0000 (17:43 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 6 Nov 2008 16:43:12 +0000 (17:43 +0100)
udev/udev-rules.c
udev/udevd.c

index 4094768..c718ff0 100644 (file)
@@ -1528,7 +1528,6 @@ static int parse_file(struct udev_rules *rules, const char *filename, unsigned s
 
 static int add_matching_files(struct udev *udev, struct udev_list_node *file_list, const char *dirname, const char *suffix)
 {
 
 static int add_matching_files(struct udev *udev, struct udev_list_node *file_list, const char *dirname, const char *suffix)
 {
-       struct dirent *ent;
        DIR *dir;
        char filename[UTIL_PATH_SIZE];
 
        DIR *dir;
        char filename[UTIL_PATH_SIZE];
 
@@ -1540,26 +1539,28 @@ static int add_matching_files(struct udev *udev, struct udev_list_node *file_lis
        }
 
        while (1) {
        }
 
        while (1) {
-               ent = readdir(dir);
-               if (ent == NULL || ent->d_name[0] == '\0')
+               struct dirent *dent;
+
+               dent = readdir(dir);
+               if (dent == NULL || dent->d_name[0] == '\0')
                        break;
 
                        break;
 
-               if ((ent->d_name[0] == '.') || (ent->d_name[0] == '#'))
+               if (dent->d_name[0] == '.')
                        continue;
 
                /* look for file matching with specified suffix */
                if (suffix != NULL) {
                        const char *ext;
 
                        continue;
 
                /* look for file matching with specified suffix */
                if (suffix != NULL) {
                        const char *ext;
 
-                       ext = strrchr(ent->d_name, '.');
+                       ext = strrchr(dent->d_name, '.');
                        if (ext == NULL)
                                continue;
                        if (strcmp(ext, suffix) != 0)
                                continue;
                }
                        if (ext == NULL)
                                continue;
                        if (strcmp(ext, suffix) != 0)
                                continue;
                }
-               dbg(udev, "put file '%s/%s' into list\n", dirname, ent->d_name);
+               dbg(udev, "put file '%s/%s' into list\n", dirname, dent->d_name);
 
 
-               snprintf(filename, sizeof(filename), "%s/%s", dirname, ent->d_name);
+               snprintf(filename, sizeof(filename), "%s/%s", dirname, dent->d_name);
                filename[sizeof(filename)-1] = '\0';
                udev_list_entry_add(udev, file_list, filename, NULL, 1, 1);
        }
                filename[sizeof(filename)-1] = '\0';
                udev_list_entry_add(udev, file_list, filename, NULL, 1, 1);
        }
index 405a1ed..15a197e 100644 (file)
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <time.h>
 #include <getopt.h>
 #include <fcntl.h>
 #include <time.h>
 #include <getopt.h>
+#include <dirent.h>
 #include <sys/select.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/select.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -569,6 +570,38 @@ static void reap_sigchilds(void)
        }
 }
 
        }
 }
 
+static void cleanup_queue_dir(struct udev *udev)
+{
+       char dirname[UTIL_PATH_SIZE];
+       char filename[UTIL_PATH_SIZE];
+       DIR *dir;
+
+       util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
+       util_strlcat(filename, "/.udev/uevent_seqnum", sizeof(filename));
+       unlink(filename);
+
+       util_strlcpy(dirname, udev_get_dev_path(udev), sizeof(dirname));
+       util_strlcat(dirname, "/.udev/queue", sizeof(dirname));
+       dir = opendir(dirname);
+       if (dir != NULL) {
+               while (1) {
+                       struct dirent *dent;
+
+                       dent = readdir(dir);
+                       if (dent == NULL || dent->d_name[0] == '\0')
+                               break;
+                       if (dent->d_name[0] == '.')
+                               continue;
+                       util_strlcpy(filename, dirname, sizeof(filename));
+                       util_strlcat(filename, "/", sizeof(filename));
+                       util_strlcat(filename, dent->d_name, sizeof(filename));
+                       unlink(filename);
+               }
+               closedir(dir);
+               rmdir(dirname);
+       }
+}
+
 static void export_initial_seqnum(struct udev *udev)
 {
        char filename[UTIL_PATH_SIZE];
 static void export_initial_seqnum(struct udev *udev)
 {
        char filename[UTIL_PATH_SIZE];
@@ -732,6 +765,7 @@ int main(int argc, char *argv[])
                goto exit;
        }
        udev_list_init(&event_list);
                goto exit;
        }
        udev_list_init(&event_list);
+       cleanup_queue_dir(udev);
        export_initial_seqnum(udev);
 
        if (daemonize) {
        export_initial_seqnum(udev);
 
        if (daemonize) {
@@ -954,7 +988,7 @@ exit:
        if (inotify_fd >= 0)
                close(inotify_fd);
        udev_monitor_unref(kernel_monitor);
        if (inotify_fd >= 0)
                close(inotify_fd);
        udev_monitor_unref(kernel_monitor);
-
+       cleanup_queue_dir(udev);
        udev_selinux_exit(udev);
        udev_unref(udev);
        logging_close();
        udev_selinux_exit(udev);
        udev_unref(udev);
        logging_close();