From 8e1b51be102dbbfc2f4965e60431eeb60712f069 Mon Sep 17 00:00:00 2001 From: Jan Palus Date: Thu, 26 Oct 2023 23:15:36 +0200 Subject: [PATCH] config: reset conf file descriptor after closing file stream conf file descriptor is closed once again during cleanup at the end of config_load() if descriptor >= 0. avoid double closing by assigning negative value to fd after first close. by the time second close happens some other descriptor might be opened reusing previous number ie it might happen during foot server startup when syslog message is logged between one close and the other. in this particular situation, as of this writing, it considers fd=3 for which following events apply: 1. conf file is opened and fclosed() 2. warning is logged with syslog which leads to opening socket to /dev/log which is kept open by glibc (gets fd=3) 3. second close during config_load() closes /dev/log socket descriptor 4. epoll_create() in fdm.c reuses fd=3 again 5. another message is being logged with syslog. glibc notices sendto() failure on saved /dev/log descriptor hence it closes it and opens new one Due to epoll descriptor closure foot starts a chain of errors that lead to startup failure. Fixes #1531 --- config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/config.c b/config.c index 98d2918b..e5cd6723 100644 --- a/config.c +++ b/config.c @@ -3195,6 +3195,7 @@ config_load(struct config *conf, const char *conf_path, ret = !errors_are_fatal; fclose(f); + conf_file.fd = -1; } }