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
This commit is contained in:
Jan Palus 2023-10-26 23:15:36 +02:00 committed by Daniel Eklöf
parent ee02e7b07d
commit 8e1b51be10
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -3195,6 +3195,7 @@ config_load(struct config *conf, const char *conf_path,
ret = !errors_are_fatal;
fclose(f);
conf_file.fd = -1;
}
}