From a13ffffbec78f1111af9c9df94897ac5fa480637 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sun, 7 Aug 2022 16:48:26 +0200 Subject: SystemServer: Unlink before binding a new socket Prevent "Address already in use" issues when restarting a service. --- Userland/Services/SystemServer/Service.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Userland/Services') diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp index f2d1c2dde2..90d677af18 100644 --- a/Userland/Services/SystemServer/Service.cpp +++ b/Userland/Services/SystemServer/Service.cpp @@ -35,6 +35,10 @@ ErrorOr 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 -- cgit v1.2.3