summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-04-27 11:11:58 +0200
committerTom Gundersen <teg@jklm.no>2015-05-06 18:35:55 +0200
commite03c7cc26ed731245827ada3aa24f6c937ff80a1 (patch)
treec2934ea3260e5b4df1ddfde91c422e0c5068fc18 /src/udev
parentf96a5160c48574015cdd87d5991f65f8e03f0c72 (diff)
udevd: worker - only allocate the worker struct in the main process
This is not used in the worker, so avoid having to free it there.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udevd.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 1eb7b779eb..4ab3216ab7 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -168,7 +168,6 @@ static void worker_list_cleanup(struct udev *udev) {
static void worker_spawn(struct event *event) {
struct udev *udev = event->udev;
- struct worker *worker;
struct udev_monitor *worker_monitor;
pid_t pid;
@@ -180,15 +179,6 @@ static void worker_spawn(struct event *event) {
udev_monitor_allow_unicast_sender(worker_monitor, monitor);
udev_monitor_enable_receiving(worker_monitor);
- worker = new0(struct worker, 1);
- if (worker == NULL) {
- udev_monitor_unref(worker_monitor);
- return;
- }
- /* worker + event reference */
- worker->refcount = 2;
- worker->udev = udev;
-
pid = fork();
switch (pid) {
case 0: {
@@ -203,7 +193,6 @@ static void worker_spawn(struct event *event) {
dev = event->dev;
event->dev = NULL;
- free(worker);
worker_list_cleanup(udev);
event_queue_cleanup(udev, EVENT_UNDEF);
udev_monitor_unref(monitor);
@@ -392,10 +381,21 @@ out:
case -1:
udev_monitor_unref(worker_monitor);
event->state = EVENT_QUEUED;
- free(worker);
log_error_errno(errno, "fork of child failed: %m");
break;
default:
+ {
+ struct worker *worker;
+
+ worker = new0(struct worker, 1);
+ if (!worker) {
+ udev_monitor_unref(worker_monitor);
+ return;
+ }
+
+ /* worker + event reference */
+ worker->refcount = 2;
+ worker->udev = udev;
/* close monitor, but keep address around */
udev_monitor_disconnect(worker_monitor);
worker->monitor = worker_monitor;
@@ -410,6 +410,7 @@ out:
log_debug("seq %llu forked new worker ["PID_FMT"]", udev_device_get_seqnum(event->dev), pid);
break;
}
+ }
}
static void event_run(struct event *event) {