chiark / gitweb /
remove 'udevadm trigger --type=failed' and SYSFS, ID, BUS keys
[elogind.git] / libudev / libudev-queue-private.c
index a799be062a961aa8829d97133456b5910dacc4ad..e0a7b53b8136b592a1c647fc6bdfc0265017de61 100644 (file)
@@ -56,7 +56,6 @@ static int rebuild_queue_file(struct udev_queue_export *udev_queue_export);
 
 struct udev_queue_export {
        struct udev *udev;
-       int failed_count;       /* number of failed events exported */
        int queued_count;       /* number of unfinished events exported in queue file */
        FILE *queue_file;
        unsigned long long int seqnum_max;      /* earliest sequence number in queue file */
@@ -104,9 +103,10 @@ void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export)
 {
        char filename[UTIL_PATH_SIZE];
 
+       if (udev_queue_export == NULL)
+               return;
        util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.tmp", NULL);
        unlink(filename);
-
        util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev_queue_export->udev), "/queue.bin", NULL);
        unlink(filename);
 }
@@ -164,7 +164,7 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e
        devpaths->devpaths_size = range + 1;
 
        /* read all records and populate the table */
-       while(1) {
+       for (;;) {
                if (udev_queue_read_seqnum(udev_queue_export->queue_file, &seqnum) < 0)
                        break;
                n = seqnum - udev_queue_export->seqnum_max;
@@ -303,8 +303,10 @@ static int write_queue_record(struct udev_queue_export *udev_queue_export,
        len = (devpath_len < USHRT_MAX) ? devpath_len : USHRT_MAX;
        if (fwrite(&len, sizeof(unsigned short), 1, udev_queue_export->queue_file) != 1)
                goto write_error;
-       if (fwrite(devpath, 1, len, udev_queue_export->queue_file) != len)
-               goto write_error;
+       if (len > 0) {
+               if (fwrite(devpath, 1, len, udev_queue_export->queue_file) != len)
+                       goto write_error;
+       }
 
        /* *must* flush output; caller may fork */
        if (fflush(udev_queue_export->queue_file) != 0)
@@ -325,7 +327,6 @@ write_error:
 enum device_state {
        DEVICE_QUEUED,
        DEVICE_FINISHED,
-       DEVICE_FAILED,
 };
 
 static inline size_t queue_record_size(size_t devpath_len)
@@ -342,6 +343,7 @@ static int update_queue(struct udev_queue_export *udev_queue_export,
        int bytes;
        int err;
 
+       /* FINISHED records have a zero length devpath */
        if (state == DEVICE_QUEUED) {
                devpath = udev_device_get_devpath(udev_device);
                devpath_len = strlen(devpath);
@@ -353,12 +355,9 @@ static int update_queue(struct udev_queue_export *udev_queue_export,
                        return -1;
        }
 
-       /* when the queue file grows too large, garbage-collect and rebuild it */
-       bytes = ftell(udev_queue_export->queue_file) + queue_record_size(devpath_len);
-
        /* if we're removing the last event from the queue, that's the best time to rebuild it */
-       if (state != DEVICE_QUEUED && udev_queue_export->queued_count == 1 && bytes > 2048) {
-               /* because we don't need to read the old queue file */
+       if (state != DEVICE_QUEUED && udev_queue_export->queued_count == 1) {
+               /* we don't need to read the old queue file */
                fclose(udev_queue_export->queue_file);
                udev_queue_export->queue_file = NULL;
                rebuild_queue_file(udev_queue_export);
@@ -366,6 +365,7 @@ static int update_queue(struct udev_queue_export *udev_queue_export,
        }
 
        /* try to rebuild the queue files before they grow larger than one page. */
+       bytes = ftell(udev_queue_export->queue_file) + queue_record_size(devpath_len);
        if ((udev_queue_export->waste_bytes > bytes / 2) && bytes > 4096)
                rebuild_queue_file(udev_queue_export);
 
@@ -392,47 +392,9 @@ static int update_queue(struct udev_queue_export *udev_queue_export,
        return err;
 }
 
-static void update_failed(struct udev_queue_export *udev_queue_export,
-                         struct udev_device *udev_device, enum device_state state)
-{
-       struct udev *udev = udev_device_get_udev(udev_device);
-       char filename[UTIL_PATH_SIZE];
-
-       if (state != DEVICE_FAILED && udev_queue_export->failed_count == 0)
-               return;
-
-       /* location of failed file */
-       util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/failed/",
-                     udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL);
-
-       switch (state) {
-       case DEVICE_FAILED:
-               /* record event in the failed directory */
-               udev_queue_export->failed_count++;
-               util_create_path(udev, filename);
-               symlink(udev_device_get_devpath(udev_device), filename);
-               break;
-
-       case DEVICE_QUEUED:
-               /* delete failed file */
-               if (unlink(filename) == 0) {
-                       util_delete_path(udev, filename);
-                       udev_queue_export->failed_count--;
-               }
-               break;
-
-       case DEVICE_FINISHED:
-               break;
-       }
-
-       return;
-}
-
 static int update(struct udev_queue_export *udev_queue_export,
                  struct udev_device *udev_device, enum device_state state)
 {
-       update_failed(udev_queue_export, udev_device, state);
-
        if (update_queue(udev_queue_export, udev_device, state) != 0)
                return -1;
 
@@ -448,8 +410,3 @@ int udev_queue_export_device_finished(struct udev_queue_export *udev_queue_expor
 {
        return update(udev_queue_export, udev_device, DEVICE_FINISHED);
 }
-
-int udev_queue_export_device_failed(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device)
-{
-       return update(udev_queue_export, udev_device, DEVICE_FAILED);
-}