summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorHaavard <havardpe@yahoo-inc.com>2017-03-20 13:04:33 +0000
committerHaavard <havardpe@yahoo-inc.com>2017-03-27 09:53:26 +0000
commit23abed1a0bc4f4c5ea47b43fc7ea0645e63a26e6 (patch)
tree6d943bbe31738f7e9b84979e4fd63dfd76eef580 /configd
parent8844ccb7297e8a5120dd903c85e923f2f93aa693 (diff)
remove most usage of LinkedPtr from vespa
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/config-handler.cpp59
-rw-r--r--configd/src/apps/sentinel/config-handler.h7
-rw-r--r--configd/src/apps/sentinel/service.h3
3 files changed, 26 insertions, 43 deletions
diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp
index dedcfc5595a..9ce4926357f 100644
--- a/configd/src/apps/sentinel/config-handler.cpp
+++ b/configd/src/apps/sentinel/config-handler.cpp
@@ -96,7 +96,7 @@ void
ConfigHandler::terminateServices(bool catchable, bool printDebug)
{
for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) {
- Service::LP service = it->second;
+ Service *service = it->second.get();
if (printDebug && service->isRunning()) {
LOG(info, "%s: killing", service->name().c_str());
}
@@ -177,32 +177,17 @@ ConfigHandler::doConfigure()
const vespalib::string name(serviceConfig.name);
ServiceMap::iterator found(_services.find(name));
if (found == _services.end()) {
- services[name] = Service::LP(new Service(serviceConfig, config.application, _outputConnections, _startMetrics));
+ services[name] = Service::UP(new Service(serviceConfig, config.application, _outputConnections, _startMetrics));
} else {
- services[name] = found->second;
found->second->reconfigure(serviceConfig);
+ services[name] = std::move(found->second);
}
}
- stopOldServicesNotInMap(services);
_services.swap(services);
vespalib::ComponentConfigProducer::Config current("sentinel", _subscriber.getGeneration(), "ok");
_stateApi.myComponents.addConfig(current);
}
-void
-ConfigHandler::stopOldServicesNotInMap(const ServiceMap & newServices)
-{
- for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) {
- const vespalib::string & key(it->first);
- if (newServices.find(key) == newServices.end()) {
- Service::LP service = it->second;
- if (service->isRunning()) {
- service->terminate(true);
- }
- }
- }
-}
-
int
ConfigHandler::doWork()
@@ -237,8 +222,8 @@ ConfigHandler::handleChildDeaths()
pid_t pid;
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
// A child process has exited. find it.
- Service::LP service = serviceByPid(pid);
- if (service.get() != NULL) {
+ Service *service = serviceByPid(pid);
+ if (service != NULL) {
LOG(debug, "pid %d finished, Service:%s", (int)pid,
service->name().c_str());
service->youExited(status);
@@ -348,26 +333,26 @@ ConfigHandler::handleCommands()
_connections.erase(dst, _connections.end());
}
-Service::LP
+Service *
ConfigHandler::serviceByPid(pid_t pid)
{
for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) {
- Service::LP service = it->second;
+ Service *service = it->second.get();
if (service->pid() == pid) {
return service;
}
}
- return Service::LP(NULL);
+ return NULL;
}
-Service::LP
+Service *
ConfigHandler::serviceByName(const vespalib::string & name)
{
ServiceMap::iterator found(_services.find(name));
if (found != _services.end()) {
- return found->second;
+ return found->second.get();
}
- return Service::LP(NULL);
+ return NULL;
}
@@ -475,7 +460,7 @@ void
ConfigHandler::doLs(CommandConnection *c, char *args)
{
for (ServiceMap::iterator it(_services.begin()), mt(_services.end()); it != mt; it++) {
- Service::LP service = it->second;
+ Service *service = it->second.get();
if (*args && strcmp(args, service->name().c_str()) != 0) {
continue;
}
@@ -502,8 +487,8 @@ ConfigHandler::doQuit(CommandConnection *c, char *)
void
ConfigHandler::doStart(CommandConnection *c, char *args)
{
- Service::LP service = serviceByName(args);
- if (service.get() == NULL) {
+ Service *service = serviceByName(args);
+ if (service == NULL) {
c->printf("Cannot find any service named '%s'\n", args);
return;
}
@@ -528,8 +513,8 @@ ConfigHandler::doRestart(CommandConnection *c, char *args)
void
ConfigHandler::doRestart(CommandConnection *c, char *args, bool force)
{
- Service::LP service = serviceByName(args);
- if (service.get() == NULL) {
+ Service *service = serviceByName(args);
+ if (service == NULL) {
c->printf("Cannot find any service named '%s'\n", args);
return;
}
@@ -565,8 +550,8 @@ ConfigHandler::doStop(CommandConnection *c, char *args)
void
ConfigHandler::doStop(CommandConnection *c, char *args, bool force)
{
- Service::LP service = serviceByName(args);
- if (service.get() == NULL) {
+ Service *service = serviceByName(args);
+ if (service == NULL) {
c->printf("Cannot find any service named '%s'\n", args);
return;
}
@@ -589,8 +574,8 @@ ConfigHandler::doStop(CommandConnection *c, char *args, bool force)
void
ConfigHandler::doAuto(CommandConnection *c, char *args)
{
- Service::LP service = serviceByName(args);
- if (service.get() == NULL) {
+ Service *service = serviceByName(args);
+ if (service == NULL) {
c->printf("Cannot find any service named '%s'\n", args);
return;
}
@@ -615,8 +600,8 @@ ConfigHandler::doAuto(CommandConnection *c, char *args)
void
ConfigHandler::doManual(CommandConnection *c, char *args)
{
- Service::LP service = serviceByName(args);
- if (service.get() == NULL) {
+ Service *service = serviceByName(args);
+ if (service == NULL) {
c->printf("Cannot find any service named '%s'\n", args);
return;
}
diff --git a/configd/src/apps/sentinel/config-handler.h b/configd/src/apps/sentinel/config-handler.h
index ffd5af7ef4c..2656a8df571 100644
--- a/configd/src/apps/sentinel/config-handler.h
+++ b/configd/src/apps/sentinel/config-handler.h
@@ -26,7 +26,7 @@ class OutputConnection;
class ConfigHandler {
private:
- typedef std::map<vespalib::string, Service::LP> ServiceMap;
+ typedef std::map<vespalib::string, Service::UP> ServiceMap;
ConfigSubscriber _subscriber;
ConfigHandle<SentinelConfig>::UP _sentinelHandle;
@@ -41,8 +41,8 @@ private:
ConfigHandler(const ConfigHandler&);
ConfigHandler& operator =(const ConfigHandler&);
- Service::LP serviceByPid(pid_t pid);
- Service::LP serviceByName(const vespalib::string & name);
+ Service *serviceByPid(pid_t pid);
+ Service *serviceByName(const vespalib::string & name);
void handleCommands();
void handleCommand(CommandConnection *c);
void handleOutputs();
@@ -65,7 +65,6 @@ private:
void doQuit(CommandConnection *c, char *args);
void terminateServices(bool catchable, bool printDebug = false);
- void stopOldServicesNotInMap(const ServiceMap & newServices);
void doConfigure();
diff --git a/configd/src/apps/sentinel/service.h b/configd/src/apps/sentinel/service.h
index 0021221b17e..ad391d3680f 100644
--- a/configd/src/apps/sentinel/service.h
+++ b/configd/src/apps/sentinel/service.h
@@ -1,7 +1,6 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <vespa/vespalib/util/linkedptr.h>
#include <vespa/vespalib/stllike/string.h>
#include <vespa/config-sentinel.h>
#include <list>
@@ -46,7 +45,7 @@ private:
StartMetrics &_metrics;
public:
- typedef vespalib::LinkedPtr<Service> LP;
+ using UP = std::unique_ptr<Service>;
~Service();
Service(const SentinelConfig::Service& config,
const SentinelConfig::Application& application,