mtp

Merge lp:~cyphermox/mtp/dbus-cpp-except into lp:mtp

Proposed by Mathieu Trudel-Lapierre
Status: Merged
Approved by: Mathieu Trudel-Lapierre
Approved revision: 53
Merged at revision: 53
Proposed branch: lp:~cyphermox/mtp/dbus-cpp-except
Merge into: lp:mtp
Diff against target: 100 lines (+26/-5)
3 files modified
include/MtpServer.h (+4/-0)
server/server.cpp (+16/-4)
src/MtpServer.cpp (+6/-1)
To merge this branch: bzr merge lp:~cyphermox/mtp/dbus-cpp-except
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Manuel de la Peña (community) Approve
Review via email: mp+240037@code.launchpad.net

Commit message

Watch for exceptions in the dbus thread; and stop mtp-server gracefully if there are any.

Description of the change

Watch for exceptions in the dbus thread; and stop mtp-server gracefully if there are any.

To post a comment you must log in.
lp:~cyphermox/mtp/dbus-cpp-except updated
53. By Mathieu Trudel-Lapierre

Watch for exceptions in the dbus thread; and stop mtp-server gracefully if there are any.

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: Approve (continuous-integration)
lp:~cyphermox/mtp/dbus-cpp-except updated
54. By Mathieu Trudel-Lapierre

Simplify the main loop for the MtpServer object.

55. By Mathieu Trudel-Lapierre

Initialize mRunning to a sane value when we call run()

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/MtpServer.h'
2--- include/MtpServer.h 2013-11-27 17:21:38 +0000
3+++ include/MtpServer.h 2014-10-31 15:57:06 +0000
4@@ -39,6 +39,9 @@
5
6 MtpDatabase* mDatabase;
7
8+ // keep state whether the server should be running
9+ bool mRunning;
10+
11 // appear as a PTP device
12 bool mPtp;
13
14@@ -101,6 +104,7 @@
15 void removeStorage(MtpStorage* storage);
16
17 void run();
18+ void stop();
19
20 void sendObjectAdded(MtpObjectHandle handle);
21 void sendObjectRemoved(MtpObjectHandle handle);
22
23=== modified file 'server/server.cpp'
24--- server/server.cpp 2014-09-04 01:11:14 +0000
25+++ server/server.cpp 2014-10-31 15:57:06 +0000
26@@ -113,6 +113,8 @@
27
28 private:
29 struct passwd *userdata;
30+ dbus::Bus::Ptr bus;
31+ boost::thread dbus_thread;
32
33 // Mtp stuff
34 MtpServer* server;
35@@ -238,6 +240,17 @@
36 read_more_notify();
37 }
38
39+ void drive_bus()
40+ {
41+ try {
42+ bus->run();
43+ }
44+ catch (...) {
45+ PLOG(ERROR) << "There was an unexpected error in DBus; terminating.";
46+ server->stop();
47+ }
48+ }
49+
50 public:
51
52 MtpDaemon(int fd):
53@@ -272,14 +285,12 @@
54 FileSystemConfig::directory_perm);
55
56 // security / screen locking
57- auto bus = core::the_session_bus();
58+ bus = core::the_session_bus();
59 bus->install_executor(core::dbus::asio::make_executor(bus));
60- std::thread t {std::bind(&dbus::Bus::run, bus)};
61+ dbus_thread = boost::thread(&MtpDaemon::drive_bus, this);
62 auto greeter_service = dbus::Service::use_service(bus, "com.canonical.UnityGreeter");
63 dbus::Object::Ptr greeter = greeter_service->object_for_path(dbus::types::ObjectPath("/"));
64
65- t.detach();
66-
67 is_active = greeter->get_property<core::UnityGreeter::Properties::IsActive>();
68 }
69
70@@ -339,6 +350,7 @@
71 // Cleanup
72 inotify_rm_watch(inotify_fd, watch_fd);
73 io_svc.stop();
74+ dbus_thread.detach();
75 notifier_thread.detach();
76 io_service_thread.join();
77 close(inotify_fd);
78
79=== modified file 'src/MtpServer.cpp'
80--- src/MtpServer.cpp 2014-03-27 15:50:32 +0000
81+++ src/MtpServer.cpp 2014-10-31 15:57:06 +0000
82@@ -158,12 +158,17 @@
83 return (getStorage(id) != NULL);
84 }
85
86+void MtpServer::stop() {
87+ mRunning = false;
88+}
89+
90 void MtpServer::run() {
91 int fd = mFD;
92
93 VLOG(1) << "MtpServer::run fd: " << fd;
94
95- while (1) {
96+ mRunning = true;
97+ while (mRunning) {
98 int ret = mRequest.read(fd);
99 if (ret < 0) {
100 PLOG(ERROR) << "request read returned " << ret;

Subscribers

People subscribed via source and target branches