]>
Commit | Line | Data |
---|---|---|
9fdcbae5 LP |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | ||
3 | #include "machined.h" | |
4 | #include "nscd-flush.h" | |
5 | #include "strv.h" | |
6 | ||
7 | static int on_nscd_cache_flush_event(sd_event_source *s, void *userdata) { | |
8 | /* Let's ask glibc's nscd daemon to flush its caches. We request this for the three database machines may show | |
9 | * up in: the hosts database (for resolvable machine names) and the user and group databases (for the user ns | |
10 | * ranges). */ | |
11 | ||
12 | (void) nscd_flush_cache(STRV_MAKE("passwd", "group", "hosts")); | |
13 | return 0; | |
14 | } | |
15 | ||
16 | int manager_enqueue_nscd_cache_flush(Manager *m) { | |
17 | int r; | |
18 | ||
19 | assert(m); | |
20 | ||
21 | if (!m->nscd_cache_flush_event) { | |
22 | r = sd_event_add_defer(m->event, &m->nscd_cache_flush_event, on_nscd_cache_flush_event, m); | |
23 | if (r < 0) | |
24 | return log_error_errno(r, "Failed to allocate NSCD cache flush event: %m"); | |
25 | ||
26 | sd_event_source_set_description(m->nscd_cache_flush_event, "nscd-cache-flush"); | |
27 | } | |
28 | ||
29 | r = sd_event_source_set_enabled(m->nscd_cache_flush_event, SD_EVENT_ONESHOT); | |
30 | if (r < 0) { | |
31 | m->nscd_cache_flush_event = sd_event_source_unref(m->nscd_cache_flush_event); | |
32 | return log_error_errno(r, "Failed to enable NSCD cache flush event: %m"); | |
33 | } | |
34 | ||
35 | return 0; | |
36 | } |