summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-04-27 11:11:58 +0200
committerAnthony G. Basile <blueness@gentoo.org>2015-05-26 11:25:42 -0400
commit818b85cb3bfeca3429e2b010e3437d4e532fcb4c (patch)
treed345d0669a582a48f8d2c7051527665062f15b13
parent1a332b3cd9421daca62759248c8fd49f8c2e1654 (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. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-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 428be0d787..cc96a43b1c 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -171,7 +171,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;
@@ -183,15 +182,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: {
@@ -205,7 +195,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);
@@ -387,10 +376,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;
@@ -405,6 +405,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) {