* Now a service is quit when it is removed from the settings file.

* When deleting the Services handler, it will now also stop all running services,
  and close the command pipe (since it's only quit when the net_server quits, that
  wasn't much of a problem, though).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21566 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-07-05 12:16:22 +00:00
parent 7a3f6f9a07
commit f6ad6dd6a6
2 changed files with 32 additions and 7 deletions

View File

@ -37,11 +37,12 @@ struct service_address {
typedef vector<service_address> AddressList; typedef vector<service_address> AddressList;
struct service { struct service {
std::string name; std::string name;
std::string launch; std::string launch;
uid_t user; uid_t user;
gid_t group; gid_t group;
AddressList addresses; AddressList addresses;
uint32 update;
~service(); ~service();
bool operator!=(const struct service& other) const; bool operator!=(const struct service& other) const;
@ -187,6 +188,15 @@ Services::Services(const BMessage& services)
Services::~Services() Services::~Services()
{ {
wait_for_thread(fListener, NULL); wait_for_thread(fListener, NULL);
close(fReadPipe);
close(fWritePipe);
// stop all services
while (!fNameMap.empty()) {
_StopService(*fNameMap.begin()->second);
}
} }
@ -260,6 +270,7 @@ Services::_StartService(struct service& service)
// add service to maps and activate it // add service to maps and activate it
fNameMap[service.name] = &service; fNameMap[service.name] = &service;
service.update = fUpdate;
iterator = service.addresses.begin(); iterator = service.addresses.begin();
for (; iterator != service.addresses.end(); iterator++) { for (; iterator != service.addresses.end(); iterator++) {
@ -456,7 +467,21 @@ Services::_Update(const BMessage& services)
if (*service != *iterator->second) { if (*service != *iterator->second) {
_StopService(*iterator->second); _StopService(*iterator->second);
_StartService(*service); _StartService(*service);
} } else
service->update = fUpdate;
}
}
// stop all services that are not part of the update message
ServiceNameMap::iterator iterator = fNameMap.begin();
while (iterator != fNameMap.end()) {
struct service* service = iterator->second;
iterator++;
if (service->update != fUpdate) {
// this service has to be removed
_StopService(*service);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2006, Haiku, Inc. All Rights Reserved. * Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -48,7 +48,7 @@ class Services : public BHandler {
BLocker fLock; BLocker fLock;
ServiceNameMap fNameMap; ServiceNameMap fNameMap;
ServiceSocketMap fSocketMap; ServiceSocketMap fSocketMap;
int32 fUpdate; uint32 fUpdate;
int fReadPipe; int fReadPipe;
int fWritePipe; int fWritePipe;
int fMinSocket; int fMinSocket;