From: Lennart Poettering Date: Mon, 27 Feb 2023 18:05:19 +0000 (+0100) Subject: sd-event: handle kernels that set CONFIG_PSI_DEFAULT_DISABLED more gracefully X-Git-Tag: v254-rc1~1147 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9897f5ddeae5ad4eafae15c8dd63056622458be5;p=thirdparty%2Fsystemd.git sd-event: handle kernels that set CONFIG_PSI_DEFAULT_DISABLED more gracefully 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. --- diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 73b5267ae81..2c0895dc741 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -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; }