diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-08 11:37:17 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-08 11:59:09 +0100 |
commit | cf5366387b24633284ee92285ea64a282270d591 (patch) | |
tree | a4753dc7bf319a16ed8d9d6fdee4ae09b2669279 /src/home/homed-home.c | |
parent | 23d24b76f3df765fa6dbe7fe815bd4f8e76c9bb5 (diff) | |
download | systemd-cf5366387b24633284ee92285ea64a282270d591.tar.gz |
homed: disable event sources before unreffing them
C.f. 9793530228.
We'd crash when trying to access an already-deallocated object:
Thread no. 1 (7 frames)
#2 log_assert_failed_realm at ../src/basic/log.c:844
#3 event_inotify_data_drop at ../src/libsystemd/sd-event/sd-event.c:3035
#4 source_dispatch at ../src/libsystemd/sd-event/sd-event.c:3250
#5 sd_event_dispatch at ../src/libsystemd/sd-event/sd-event.c:3631
#6 sd_event_run at ../src/libsystemd/sd-event/sd-event.c:3689
#7 sd_event_loop at ../src/libsystemd/sd-event/sd-event.c:3711
#8 run at ../src/home/homed.c:47
The source in question is an inotify source, and the messages are:
systemd-homed[1340]: /home/ moved or renamed, recreating watch and rescanning.
systemd-homed[1340]: Assertion '*_head == _item' failed at src/libsystemd/sd-event/sd-event.c:3035, function event_inotify_data_drop(). Aborting.
on_home_inotify() got called, then manager_watch_home(), which unrefs the
existing inotify_event_source. I assume that the source gets dispatched again
because it was still in the pending queue.
I can't reproduce the issue (timing?), but this should
fix #17824, https://bugzilla.redhat.com/show_bug.cgi?id=1899264.
Diffstat (limited to 'src/home/homed-home.c')
-rw-r--r-- | src/home/homed-home.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/home/homed-home.c b/src/home/homed-home.c index f1db828ed0..5a777e88ef 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -188,17 +188,17 @@ Home *home_free(Home *h) { user_record_unref(h->record); user_record_unref(h->secret); - h->worker_event_source = sd_event_source_unref(h->worker_event_source); + h->worker_event_source = sd_event_source_disable_unref(h->worker_event_source); safe_close(h->worker_stdout_fd); free(h->user_name); free(h->sysfs); - h->ref_event_source_please_suspend = sd_event_source_unref(h->ref_event_source_please_suspend); - h->ref_event_source_dont_suspend = sd_event_source_unref(h->ref_event_source_dont_suspend); + h->ref_event_source_please_suspend = sd_event_source_disable_unref(h->ref_event_source_please_suspend); + h->ref_event_source_dont_suspend = sd_event_source_disable_unref(h->ref_event_source_dont_suspend); h->pending_operations = ordered_set_free(h->pending_operations); - h->pending_event_source = sd_event_source_unref(h->pending_event_source); - h->deferred_change_event_source = sd_event_source_unref(h->deferred_change_event_source); + h->pending_event_source = sd_event_source_disable_unref(h->pending_event_source); + h->deferred_change_event_source = sd_event_source_disable_unref(h->deferred_change_event_source); h->current_operation = operation_unref(h->current_operation); @@ -888,7 +888,7 @@ static int home_on_worker_process(sd_event_source *s, const siginfo_t *si, void (void) hashmap_remove_value(h->manager->homes_by_worker_pid, PID_TO_PTR(h->worker_pid), h); h->worker_pid = 0; - h->worker_event_source = sd_event_source_unref(h->worker_event_source); + h->worker_event_source = sd_event_source_disable_unref(h->worker_event_source); if (si->si_code != CLD_EXITED) { assert(IN_SET(si->si_code, CLD_KILLED, CLD_DUMPED)); @@ -1067,7 +1067,7 @@ static int home_start_work(Home *h, const char *verb, UserRecord *hr, UserRecord r = hashmap_put(h->manager->homes_by_worker_pid, PID_TO_PTR(pid), h); if (r < 0) { - h->worker_event_source = sd_event_source_unref(h->worker_event_source); + h->worker_event_source = sd_event_source_disable_unref(h->worker_event_source); return r; } |