mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
libudev: queue - always rebuild queue file when nothing is queued anymore
This commit is contained in:
parent
85e172c9bd
commit
4b718be86d
@ -36,7 +36,7 @@ dist_libexec_SCRIPTS =
|
|||||||
# libudev
|
# libudev
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
LIBUDEV_CURRENT=11
|
LIBUDEV_CURRENT=11
|
||||||
LIBUDEV_REVISION=3
|
LIBUDEV_REVISION=4
|
||||||
LIBUDEV_AGE=11
|
LIBUDEV_AGE=11
|
||||||
|
|
||||||
SUBDIRS += libudev/docs
|
SUBDIRS += libudev/docs
|
||||||
|
@ -164,7 +164,7 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e
|
|||||||
devpaths->devpaths_size = range + 1;
|
devpaths->devpaths_size = range + 1;
|
||||||
|
|
||||||
/* read all records and populate the table */
|
/* read all records and populate the table */
|
||||||
while(1) {
|
for (;;) {
|
||||||
if (udev_queue_read_seqnum(udev_queue_export->queue_file, &seqnum) < 0)
|
if (udev_queue_read_seqnum(udev_queue_export->queue_file, &seqnum) < 0)
|
||||||
break;
|
break;
|
||||||
n = seqnum - udev_queue_export->seqnum_max;
|
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;
|
len = (devpath_len < USHRT_MAX) ? devpath_len : USHRT_MAX;
|
||||||
if (fwrite(&len, sizeof(unsigned short), 1, udev_queue_export->queue_file) != 1)
|
if (fwrite(&len, sizeof(unsigned short), 1, udev_queue_export->queue_file) != 1)
|
||||||
goto write_error;
|
goto write_error;
|
||||||
if (fwrite(devpath, 1, len, udev_queue_export->queue_file) != len)
|
if (len > 0) {
|
||||||
goto write_error;
|
if (fwrite(devpath, 1, len, udev_queue_export->queue_file) != len)
|
||||||
|
goto write_error;
|
||||||
|
}
|
||||||
|
|
||||||
/* *must* flush output; caller may fork */
|
/* *must* flush output; caller may fork */
|
||||||
if (fflush(udev_queue_export->queue_file) != 0)
|
if (fflush(udev_queue_export->queue_file) != 0)
|
||||||
@ -342,6 +344,7 @@ static int update_queue(struct udev_queue_export *udev_queue_export,
|
|||||||
int bytes;
|
int bytes;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
/* FINISHED records have a zero length devpath */
|
||||||
if (state == DEVICE_QUEUED) {
|
if (state == DEVICE_QUEUED) {
|
||||||
devpath = udev_device_get_devpath(udev_device);
|
devpath = udev_device_get_devpath(udev_device);
|
||||||
devpath_len = strlen(devpath);
|
devpath_len = strlen(devpath);
|
||||||
@ -353,12 +356,9 @@ static int update_queue(struct udev_queue_export *udev_queue_export,
|
|||||||
return -1;
|
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 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) {
|
if (state != DEVICE_QUEUED && udev_queue_export->queued_count == 1) {
|
||||||
/* because we don't need to read the old queue file */
|
/* we don't need to read the old queue file */
|
||||||
fclose(udev_queue_export->queue_file);
|
fclose(udev_queue_export->queue_file);
|
||||||
udev_queue_export->queue_file = NULL;
|
udev_queue_export->queue_file = NULL;
|
||||||
rebuild_queue_file(udev_queue_export);
|
rebuild_queue_file(udev_queue_export);
|
||||||
@ -366,6 +366,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. */
|
/* 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)
|
if ((udev_queue_export->waste_bytes > bytes / 2) && bytes > 4096)
|
||||||
rebuild_queue_file(udev_queue_export);
|
rebuild_queue_file(udev_queue_export);
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
|
|||||||
if (pfd[0].fd < 0) {
|
if (pfd[0].fd < 0) {
|
||||||
err(udev, "inotify_init failed: %m\n");
|
err(udev, "inotify_init failed: %m\n");
|
||||||
} else {
|
} else {
|
||||||
if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_CLOSE_WRITE) < 0) {
|
if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) {
|
||||||
err(udev, "watching '%s' failed\n", udev_get_run_path(udev));
|
err(udev, "watching '%s' failed\n", udev_get_run_path(udev));
|
||||||
close(pfd[0].fd);
|
close(pfd[0].fd);
|
||||||
pfd[0].fd = -1;
|
pfd[0].fd = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user