]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-event: handle kernels that set CONFIG_PSI_DEFAULT_DISABLED more gracefully
authorLennart Poettering <lennart@poettering.net>
Mon, 27 Feb 2023 18:05:19 +0000 (19:05 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 28 Feb 2023 12:15:13 +0000 (12:15 +0000)
If CONFIG_PSI_DEFAULT_DISABLED is set in the kernel, then the PSI files
will be there, and you can open them, but read()/write() will fail.
Which is terrible, since that happens so late. But anyway, handle this
gracefully.

src/libsystemd/sd-event/sd-event.c

index 73b5267ae8179f0594302bc352c99ae73ad02f36..2c0895dc741dc129b4fe417029baae39a4f2ba30 100644 (file)
@@ -4000,8 +4000,17 @@ static int source_memory_pressure_write(sd_event_source *s) {
         if (s->memory_pressure.write_buffer_size > 0) {
                 n = write(s->memory_pressure.fd, s->memory_pressure.write_buffer, s->memory_pressure.write_buffer_size);
                 if (n < 0) {
-                        if (!ERRNO_IS_TRANSIENT(errno))
-                                return -errno;
+                        if (!ERRNO_IS_TRANSIENT(errno)) {
+                                /* If kernel is built with CONFIG_PSI_DEFAULT_DISABLED it will expose PSI
+                                 * files, but then generates EOPNOSUPP on read() and write() (instead of on
+                                 * open()!). This sucks hard, since we can only detect this kind of failure
+                                 * so late. Let's make the best of it, and turn off the event source like we
+                                 * do for failed event source handlers. */
+
+                                log_debug_errno(errno, "Writing memory pressure settings to kernel failed, disabling memory pressure event source: %m");
+                                assert_se(sd_event_source_set_enabled(s, SD_EVENT_OFF) >= 0);
+                                return 0;
+                        }
 
                         n = 0;
                 }