Merge lp:~thomas-voss/location-service/fix-1426307 into lp:location-service/trunk

Proposed by Thomas Voß
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 199
Merged at revision: 196
Proposed branch: lp:~thomas-voss/location-service/fix-1426307
Merge into: lp:location-service/trunk
Diff against target: 97 lines (+44/-11)
2 files modified
src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp (+40/-11)
src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp (+4/-0)
To merge this branch: bzr merge lp:~thomas-voss/location-service/fix-1426307
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Manuel de la Peña (community) Approve
Review via email: mp+260365@code.launchpad.net

Commit message

Make sure we always hand a lock owning its mutex to on_access_point_added.

Description of the change

Make sure we always hand a lock owning its mutex to on_access_point_added.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
197. By Thomas Voß

Translate timestamps.

198. By Thomas Voß

Add comment explaining timestamp translation.

199. By Thomas Voß

btime in /proc/stat is seconds since epoch.

Revision history for this message
Manuel de la Peña (mandel) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp'
2--- src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp 2014-08-14 20:33:37 +0000
3+++ src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp 2015-05-28 10:57:45 +0000
4@@ -18,6 +18,10 @@
5
6 #include <com/ubuntu/location/connectivity/cached_wireless_network.h>
7
8+#include <fstream>
9+#include <sstream>
10+#include <string>
11+
12 namespace connectivity = com::ubuntu::location::connectivity;
13
14 namespace
15@@ -50,6 +54,39 @@
16
17 return mode;
18 }
19+
20+// boot_time returns the time since the epoch when the system booted.
21+std::chrono::system_clock::time_point boot_time()
22+{
23+ std::ifstream in{"/proc/stat"};
24+ std::string line;
25+
26+ while (std::getline(in, line))
27+ {
28+ if (line.empty())
29+ continue;
30+
31+ std::stringstream ss{line};
32+ std::string name; ss >> name;
33+
34+ if (name != "btime")
35+ continue;
36+
37+ std::uint64_t ts; ss >> ts;
38+ return std::chrono::system_clock::time_point{std::chrono::seconds{ts}};
39+ }
40+
41+ // Fallback to the best estimate we can give.
42+ return std::chrono::system_clock::now();
43+}
44+
45+// NetworkManager reports AP LastSeen timestamps in seconds since boot. We map that back to the epoch
46+// to keep dependent software working.
47+std::chrono::system_clock::time_point translate_time_stamp(std::uint64_t ts)
48+{
49+ static const auto ts_when_booted = boot_time();
50+ return ts_when_booted + std::chrono::seconds{ts};
51+}
52 }
53
54 const core::Property<std::chrono::system_clock::time_point>& detail::CachedWirelessNetwork::last_seen() const
55@@ -88,10 +125,7 @@
56 : device_(device),
57 access_point_(ap)
58 {
59- last_seen_ = std::chrono::system_clock::time_point
60- {
61- std::chrono::system_clock::duration{access_point_.last_seen->get()}
62- };
63+ last_seen_ = translate_time_stamp(access_point_.last_seen->get());
64
65 bssid_ = access_point_.hw_address->get();
66 ssid_ = utf8_ssid_to_string(access_point_.ssid->get());
67@@ -162,13 +196,8 @@
68 org::freedesktop::NetworkManager::AccessPoint::LastSeen::name(),
69 [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
70 {
71- thiz.last_seen_ = std::chrono::system_clock::time_point
72- {
73- std::chrono::system_clock::duration
74- {
75- value.as<org::freedesktop::NetworkManager::AccessPoint::LastSeen::ValueType>()
76- }
77- };
78+ thiz.last_seen_ = translate_time_stamp(
79+ value.as<org::freedesktop::NetworkManager::AccessPoint::LastSeen::ValueType>());
80 }
81 }
82 };
83
84=== modified file 'src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp'
85--- src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2015-04-27 15:44:40 +0000
86+++ src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2015-05-28 10:57:45 +0000
87@@ -530,6 +530,10 @@
88 {
89 try
90 {
91+ // We have to make sure that we always hand in a lock that owns the mutex.
92+ if (not ul.owns_lock())
93+ ul.lock();
94+
95 on_access_point_added(path, device_path, ul);
96 }
97 catch (const std::exception& e)

Subscribers

People subscribed via source and target branches