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

Side by Side 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: Add line combining 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "vpn-manager/service_manager.h"
6
7 #include <stdlib.h>
8
9 #include "base/eintr_wrapper.h"
10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/string_util.h"
13
14 FilePath* ServiceManager::temp_path_ = NULL;
15
16 const char kTempDirectory[] = "/home/chronos/user/tmp/l2tpipsec";
17
18 ServiceManager::ServiceManager(const std::string& service_name)
19 : is_running_(false),
20 was_stopped_(false),
21 inner_service_(NULL),
22 outer_service_(NULL),
23 service_name_(service_name) {
24 }
25
26 ServiceManager::~ServiceManager() {
27 }
28
29 void ServiceManager::OnStarted() {
30 CHECK(!is_running_ && !was_stopped_);
31 CHECK(outer_service_ == NULL || outer_service_->is_running_);
32 is_running_ = true;
33 if (inner_service_ == NULL)
34 return;
35
36 DLOG(INFO) << "Starting inner " << inner_service_->service_name();
37 if (!inner_service_->Start()) {
38 // Inner service could not be started, stop this layer.
39 LOG(ERROR) << "Inner service " << inner_service_->service_name()
40 << " failed. Stopping " << service_name();
41 Stop();
42 }
43 }
44
45 void ServiceManager::OnStopped(bool was_error) {
46 CHECK(inner_service_ == NULL || !inner_service_->is_running_);
47 is_running_ = false;
48 was_stopped_ = true;
49 if (outer_service_ != NULL) {
50 outer_service_->Stop();
51 }
52 }
53
54 void ServiceManager::InitializeDirectories() {
55 if (!temp_path_)
56 temp_path_ = new FilePath(kTempDirectory);
57 CHECK(file_util::CreateDirectory(*temp_path_))
58 << "Unable to create " << temp_path_->value();
59 atexit(ServiceManager::DeleteTemp);
60 }
61
62 void ServiceManager::DeleteTemp() {
63 if (!temp_path_)
64 return;
65 file_util::Delete(*temp_path_, true);
66 delete temp_path_;
67 temp_path_ = NULL;
68 }
69
70 void ServiceManager::WriteFdToSyslog(int fd,
71 const std::string& prefix,
72 std::string* partial_line) {
73 char buffer[256];
74 int written = HANDLE_EINTR(read(fd, &buffer, sizeof(buffer) - 1));
75 if (written < 0) {
76 LOG(WARNING) << "Error condition on " << prefix << " pipe";
77 return;
78 }
79 buffer[written] = '\0';
80 partial_line->append(buffer);
81 std::vector<std::string> lines;
82 SplitString(*partial_line, '\n', &lines);
83 if (lines.empty()) {
84 partial_line->clear();
85 } else {
86 *partial_line = lines.back();
87 lines.pop_back();
88 }
89 for (size_t i = 0; i < lines.size(); ++i)
90 LOG(INFO) << prefix << lines[i];
91 }
OLDNEW
« l2tp_manager.cc ('K') | « service_manager.h ('k') | service_manager_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698