Merge lp:~thomas-voss/location-service/fix-1447110 into lp:location-service/15.04

Proposed by Thomas Voß on 2016-03-23
Status: Merged
Approved by: Scott Sweeny on 2016-03-31
Approved revision: 225
Merged at revision: 220
Proposed branch: lp:~thomas-voss/location-service/fix-1447110
Merge into: lp:location-service/15.04
Diff against target: 202 lines (+86/-35)
6 files modified
doc/debugging.md (+0/-1)
src/location_service/com/ubuntu/location/service/daemon.cpp (+15/-0)
src/location_service/com/ubuntu/location/service/daemon_main.cpp (+0/-31)
src/location_service/com/ubuntu/location/service/session/skeleton.cpp (+3/-3)
tests/CMakeLists.txt (+2/-0)
tests/bug_1447110.cpp (+66/-0)
To merge this branch: bzr merge lp:~thomas-voss/location-service/fix-1447110
Reviewer Review Type Date Requested Status
Scott Sweeny (community) 2016-03-23 Approve on 2016-03-29
Review via email: mp+289979@code.launchpad.net

Commit Message

Log to stderr by default, relying on upstart to rotate logs appropriately.

Description of the Change

Log to stderr by default, relying on upstart to rotate logs appropriately.

To post a comment you must log in.
222. By Thomas Voß on 2016-03-29

Dial down logging of issues in communicating updates to clients.

Scott Sweeny (ssweeny) wrote :

LGTM

review: Approve
223. By Thomas Voß on 2016-03-30

Remove obsolete /var/log/ubuntu-location-service on startup.

224. By Thomas Voß on 2016-03-31

Remove directory even if not empty (ensure consistent semantics across boost versions).

225. By Thomas Voß on 2016-03-31

Add test ensuring correct behavior.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/debugging.md'
2--- doc/debugging.md 2015-10-20 12:02:02 +0000
3+++ doc/debugging.md 2016-03-31 10:16:15 +0000
4@@ -54,7 +54,6 @@
5 sequence to add some env vars:
6
7 export GLOG_v=200
8- export GLOG_logtostderr=1
9
10 before the exec. Reboot, and start some app. You should have some log
11 files under /var/log/upstart/ubuntu-espoo-service.log and
12
13=== modified file 'src/location_service/com/ubuntu/location/service/daemon.cpp'
14--- src/location_service/com/ubuntu/location/service/daemon.cpp 2016-01-06 16:15:26 +0000
15+++ src/location_service/com/ubuntu/location/service/daemon.cpp 2016-03-31 10:16:15 +0000
16@@ -42,6 +42,7 @@
17 #include <core/posix/signal.h>
18
19 #include <boost/asio.hpp>
20+#include <boost/filesystem.hpp>
21
22 #include <system_error>
23 #include <thread>
24@@ -170,6 +171,20 @@
25
26 int location::service::Daemon::main(const location::service::Daemon::Configuration& config)
27 {
28+ // Ensure that log files dating back to before the fix
29+ // for lp:1447110 are removed and do not waste space.
30+ {
31+ static const boost::filesystem::path old_log_dir{"/var/log/ubuntu-location-service"};
32+ boost::system::error_code ec;
33+ boost::filesystem::remove_all(old_log_dir, ec);
34+ }
35+ // Setup logging for the daemon.
36+ FLAGS_logtostderr = true;
37+ FLAGS_stop_logging_if_full_disk = true;
38+ FLAGS_max_log_size = 5;
39+
40+ google::InitGoogleLogging("com.ubuntu.location");
41+
42 auto trap = core::posix::trap_signals_for_all_subsequent_threads(
43 {
44 core::posix::Signal::sig_term,
45
46=== modified file 'src/location_service/com/ubuntu/location/service/daemon_main.cpp'
47--- src/location_service/com/ubuntu/location/service/daemon_main.cpp 2015-01-13 16:35:20 +0000
48+++ src/location_service/com/ubuntu/location/service/daemon_main.cpp 2016-03-31 10:16:15 +0000
49@@ -18,41 +18,10 @@
50
51 #include "daemon.h"
52
53-#include <com/ubuntu/location/logging.h>
54-
55-#include <boost/filesystem.hpp>
56-
57 namespace location = com::ubuntu::location;
58
59-namespace
60-{
61-// The directory we put log files in.
62-constexpr const char* log_dir{"/var/log/ubuntu-location-service"};
63-}
64-
65 int main(int argc, const char** argv)
66 {
67- // Setup logging for the daemon.
68- boost::system::error_code ec;
69- boost::filesystem::create_directories(boost::filesystem::path{log_dir}, ec);
70-
71- // According to http://www.boost.org/doc/libs/1_55_0/libs/filesystem/doc/reference.html#create_directories
72- // Creation failure because p resolves to an existing directory shall not be treated as an error.
73- // With that, we are free to check the error condition and adjust to stderr
74- // logging accordingly.
75- if (ec)
76- {
77- FLAGS_logtostderr = true;
78- VLOG(1) << "Problem creating directory for log files: " << ec << "."
79- << "Falling back to stderr logging.";
80- }
81-
82- FLAGS_log_dir = log_dir;
83- FLAGS_stop_logging_if_full_disk = true;
84- FLAGS_max_log_size = 5;
85-
86- google::InitGoogleLogging("com.ubuntu.location");
87-
88 location::service::Daemon::Configuration config;
89 try
90 {
91
92=== modified file 'src/location_service/com/ubuntu/location/service/session/skeleton.cpp'
93--- src/location_service/com/ubuntu/location/service/session/skeleton.cpp 2015-10-22 19:32:08 +0000
94+++ src/location_service/com/ubuntu/location/service/session/skeleton.cpp 2016-03-31 10:16:15 +0000
95@@ -287,7 +287,7 @@
96 {
97 if (result.is_error())
98 {
99- LOG(INFO) << "Failed to communicate position update to client: " << result.error().print();
100+ VLOG(10) << "Failed to communicate position update to client: " << result.error().print();
101 }
102 }, position);
103 } catch(const std::exception&)
104@@ -310,7 +310,7 @@
105 {
106 if (result.is_error())
107 {
108- LOG(INFO) << "Failed to communicate position update to client: " << result.error().print();
109+ VLOG(10) << "Failed to communicate heading update to client: " << result.error().print();
110 }
111 }, heading);
112 } catch(const std::exception&)
113@@ -333,7 +333,7 @@
114 {
115 if (result.is_error())
116 {
117- LOG(INFO) << "Failed to communicate position update to client: " << result.error().print();
118+ VLOG(10) << "Failed to communicate velocity update to client: " << result.error().print();
119 }
120 }, velocity);
121 } catch(const std::exception&)
122
123=== modified file 'tests/CMakeLists.txt'
124--- tests/CMakeLists.txt 2016-02-01 15:58:06 +0000
125+++ tests/CMakeLists.txt 2016-03-31 10:16:15 +0000
126@@ -127,3 +127,5 @@
127 LOCATION_SERVICE_ADD_TEST(remote_provider_test remote_provider_test.cpp)
128 LOCATION_SERVICE_ADD_TEST(espoo_provider_test espoo_provider_test.cpp)
129 LOCATION_SERVICE_ADD_TEST(delayed_service_test delayed_service_test.cpp)
130+
131+LOCATION_SERVICE_ADD_TEST(bug_1447110 bug_1447110.cpp)
132
133=== added file 'tests/bug_1447110.cpp'
134--- tests/bug_1447110.cpp 1970-01-01 00:00:00 +0000
135+++ tests/bug_1447110.cpp 2016-03-31 10:16:15 +0000
136@@ -0,0 +1,66 @@
137+/*
138+ * Copyright © 2016 Canonical Ltd.
139+ *
140+ * This program is free software: you can redistribute it and/or modify it
141+ * under the terms of the GNU Lesser General Public License version 3,
142+ * as published by the Free Software Foundation.
143+ *
144+ * This program is distributed in the hope that it will be useful,
145+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
146+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147+ * GNU Lesser General Public License for more details.
148+ *
149+ * You should have received a copy of the GNU Lesser General Public License
150+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
151+ *
152+ * Authored by: Thomas Voß <thomas.voss@canonical.com>
153+ */
154+
155+#include <com/ubuntu/location/service/daemon.h>
156+
157+#include <core/posix/fork.h>
158+
159+#include <gtest/gtest.h>
160+#include <boost/filesystem.hpp>
161+
162+namespace location = com::ubuntu::location;
163+
164+namespace
165+{
166+auto null_dbus_connection_factory = [](core::dbus::WellKnownBus)
167+{
168+ return core::dbus::Bus::Ptr{};
169+};
170+}
171+
172+TEST(Bug1447110, obsolete_log_directory_is_removed_on_startup)
173+{
174+ // We are trying to establish the pre-condition that a non-empty
175+ // directory /var/log/ubuntu-location-service exists. If we fail to do
176+ // so, we leave a message and bail out, not marking the test as failure.
177+ {
178+ boost::system::error_code ec;
179+ boost::filesystem::remove_all("/var/log/ubuntu-location-service/not_empty", ec);
180+ if (not boost::filesystem::create_directories("/var/log/ubuntu-location-service/not_empty", ec) || ec)
181+ {
182+ std::cerr << "Unable to create directory for testing purposes." << std::endl;
183+ return;
184+ }
185+ }
186+
187+ auto cp = core::posix::fork([]()
188+ {
189+ const char* args[] =
190+ {
191+ "--bus", "session",
192+ "--testing"
193+ };
194+ auto config = location::service::Daemon::Configuration::from_command_line_args(3, args, null_dbus_connection_factory);
195+ location::service::Daemon::main(config);
196+
197+ return core::posix::exit::Status::success;
198+ }, core::posix::StandardStream::stderr);
199+
200+ std::this_thread::sleep_for(std::chrono::seconds{1});
201+ EXPECT_FALSE(boost::filesystem::exists("/var/log/ubuntu-location-service"));
202+}

Subscribers

People subscribed via source and target branches