From 798ad3db303ec486d507f32915193f3456bfca86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 23 Apr 2015 17:10:45 +0200 Subject: [PATCH] BLooper: don't delete a launch_daemon port. * Unless the service is really to be quit, the port should stay around; but that decision is to be made by the launch_daemon, not the service itself. --- headers/os/app/Looper.h | 1 + src/kits/app/Application.cpp | 2 ++ src/kits/app/Looper.cpp | 17 ++++++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/headers/os/app/Looper.h b/headers/os/app/Looper.h index 215f7a8c96..d7f66ce19b 100644 --- a/headers/os/app/Looper.h +++ b/headers/os/app/Looper.h @@ -172,6 +172,7 @@ private: BList* fCommonFilters; bool fTerminating; bool fRunCalled; + bool fOwnsPort; uint32 _reserved[11]; }; diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index 6d80bbd410..d6edd8a99b 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -267,6 +267,8 @@ BApplication::BApplication(const char* signature, const char* looperName, looperName != NULL ? looperName : kDefaultLooperName) { _InitData(signature, initGUI, _error); + if (port < 0) + fOwnsPort = false; } diff --git a/src/kits/app/Looper.cpp b/src/kits/app/Looper.cpp index 5b87b08902..6c0b72e49e 100644 --- a/src/kits/app/Looper.cpp +++ b/src/kits/app/Looper.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2013 Haiku, Inc. All rights reserved + * Copyright 2001-2015 Haiku, Inc. All rights reserved * Distributed under the terms of the MIT License. * * Authors: @@ -130,7 +130,7 @@ BLooper::~BLooper() } // Close the message port and read and reply to the remaining messages. - if (fMsgPort >= 0) + if (fMsgPort >= 0 && fOwnsPort) close_port(fMsgPort); // Clear the queue so our call to IsMessageWaiting() below doesn't give @@ -143,13 +143,15 @@ BLooper::~BLooper() // msg will automagically post generic reply } - do { - delete ReadMessageFromPort(0); - // msg will automagically post generic reply - } while (IsMessageWaiting()); + if (!fOwnsPort) { + do { + delete ReadMessageFromPort(0); + // msg will automagically post generic reply + } while (IsMessageWaiting()); + delete_port(fMsgPort); + } fDirectTarget->Release(); - delete_port(fMsgPort); // Clean up our filters SetCommonFilterList(NULL); @@ -945,6 +947,7 @@ BLooper::_InitData(const char* name, int32 priority, port_id port, fPreferred = NULL; fThread = B_ERROR; fTerminating = false; + fOwnsPort = true; fMsgPort = -1; fAtomicCount = 0;