1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

SystemServer: Unlink before binding a new socket

Prevent "Address already in use" issues when restarting a service.
This commit is contained in:
Lucas CHOLLET 2022-08-07 16:48:26 +02:00 committed by Linus Groh
parent b14fedd02a
commit a13ffffbec

View file

@ -35,6 +35,10 @@ ErrorOr<void> Service::setup_socket(SocketDescriptor& socket)
{
VERIFY(socket.fd == -1);
// Note: The purpose of this syscall is to remove potential left-over of previous portal.
// The return value is discarded as sockets are not always there, and unlinking a non-existent path is considered as a failure.
(void)Core::System::unlink(socket.path);
TRY(Core::Directory::create(LexicalPath(socket.path).parent(), Core::Directory::CreateDirectories::Yes));
// Note: we use SOCK_CLOEXEC here to make sure we don't leak every socket to