Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: service_manager.cc

Issue 6508016: vpn-manager: Add l2tp/ipsec vpn manager (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vpn-manager.git@master
Patch Set: respond to petkov Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service_manager.h ('k') | service_manager_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service_manager.cc
diff --git a/service_manager.cc b/service_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..31f210efc102fb428daa86a1f7b737db8b37e132
--- /dev/null
+++ b/service_manager.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "vpn-manager/service_manager.h"
+
+#include "base/eintr_wrapper.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/scoped_temp_dir.h"
+#include "base/string_util.h"
+
+const FilePath* ServiceManager::temp_path_ = NULL;
+const char* ServiceManager::temp_base_path_ = "/home/chronos/user/tmp";
+
+ServiceManager::ServiceManager(const std::string& service_name)
+ : is_running_(false),
+ was_stopped_(false),
+ inner_service_(NULL),
+ outer_service_(NULL),
+ service_name_(service_name) {
+}
+
+ServiceManager::~ServiceManager() {
+}
+
+void ServiceManager::OnStarted() {
+ CHECK(!is_running_ && !was_stopped_);
+ CHECK(outer_service_ == NULL || outer_service_->is_running_);
+ is_running_ = true;
+ if (inner_service_ == NULL)
+ return;
+
+ DLOG(INFO) << "Starting inner " << inner_service_->service_name();
+ if (!inner_service_->Start()) {
+ // Inner service could not be started, stop this layer.
+ LOG(ERROR) << "Inner service " << inner_service_->service_name()
+ << " failed. Stopping " << service_name();
+ Stop();
+ }
+}
+
+void ServiceManager::OnStopped(bool was_error) {
+ CHECK(inner_service_ == NULL || !inner_service_->is_running_);
+ is_running_ = false;
+ was_stopped_ = true;
+ if (outer_service_ != NULL) {
+ outer_service_->Stop();
+ }
+}
+
+void ServiceManager::InitializeDirectories(ScopedTempDir* scoped_temp_path) {
+ scoped_temp_path->CreateUniqueTempDirUnderPath(FilePath(temp_base_path_));
+ temp_path_ = &scoped_temp_path->path();
+ LOG(INFO) << "Using temporary directory " << temp_path_->value();
+}
+
+void ServiceManager::WriteFdToSyslog(int fd,
+ const std::string& prefix,
+ std::string* partial_line) {
+ char buffer[256];
+ ssize_t written = HANDLE_EINTR(read(fd, &buffer, sizeof(buffer) - 1));
+ if (written < 0) {
+ LOG(WARNING) << "Error condition on " << prefix << " pipe";
+ return;
+ }
+ buffer[written] = '\0';
+ partial_line->append(buffer);
+ std::vector<std::string> lines;
+ SplitString(*partial_line, '\n', &lines);
+ if (lines.empty()) {
+ partial_line->clear();
+ } else {
+ *partial_line = lines.back();
+ lines.pop_back();
+ }
+ for (size_t i = 0; i < lines.size(); ++i) {
+ LOG(INFO) << prefix << lines[i];
+ }
+}
« no previous file with comments | « service_manager.h ('k') | service_manager_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698