Elly Jones | a44d22d | 2012-01-05 18:05:56 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 5 | #include <sys/mount.h> |
Elly Jones | d31aee2 | 2012-07-02 11:09:10 -0400 | [diff] [blame] | 6 | #include <sys/stat.h> |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 7 | #include <unistd.h> |
| 8 | |
Elly Jones | e7cb5b3 | 2011-12-01 14:18:32 -0500 | [diff] [blame] | 9 | #include <base/command_line.h> |
| 10 | #include <base/logging.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 11 | #include <brillo/daemons/dbus_daemon.h> |
Alex Vakulenko | e769653 | 2015-10-16 16:27:29 -0700 | [diff] [blame] | 12 | #include <brillo/syslog_logging.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 14 | #include <chromeos/libminijail.h> |
| 15 | |
Eric Caruso | 63c9743 | 2017-04-27 13:23:28 -0700 | [diff] [blame] | 16 | #include "debugd/src/debugd_dbus_adaptor.h" |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 17 | |
Elly Jones | e7cb5b3 | 2011-12-01 14:18:32 -0500 | [diff] [blame] | 18 | namespace { |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 19 | |
Elly Jones | e7cb5b3 | 2011-12-01 14:18:32 -0500 | [diff] [blame] | 20 | // @brief Enter a VFS namespace. |
| 21 | // |
| 22 | // We don't want anyone other than our descendants to see our tmpfs. |
| 23 | void enter_vfs_namespace() { |
| 24 | struct minijail* j = minijail_new(); |
| 25 | minijail_namespace_vfs(j); |
| 26 | minijail_enter(j); |
| 27 | minijail_destroy(j); |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 28 | } |
| 29 | |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 30 | class Daemon : public brillo::DBusServiceDaemon { |
| 31 | public: |
Eric Caruso | 5153585 | 2017-07-11 14:13:20 -0700 | [diff] [blame] | 32 | Daemon() : DBusServiceDaemon(debugd::kDebugdServiceName) {} |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 33 | |
| 34 | protected: |
| 35 | void RegisterDBusObjectsAsync( |
Eric Caruso | b298bb4 | 2017-05-09 10:53:30 -0700 | [diff] [blame] | 36 | brillo::dbus_utils::AsyncEventSequencer* sequencer) override { |
Eric Caruso | 5153585 | 2017-07-11 14:13:20 -0700 | [diff] [blame] | 37 | adaptor_.reset(new debugd::DebugdDBusAdaptor(bus_)); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 38 | adaptor_->RegisterAsync(sequencer->GetHandler( |
| 39 | "RegisterAsync() failed.", true)); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | std::unique_ptr<debugd::DebugdDBusAdaptor> adaptor_; |
| 44 | |
| 45 | DISALLOW_COPY_AND_ASSIGN(Daemon); |
| 46 | }; |
Ben Chan | af12586 | 2017-02-08 23:11:18 -0800 | [diff] [blame] | 47 | |
| 48 | } // namespace |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 49 | |
Ben Chan | c572aff | 2018-04-10 09:20:27 -0700 | [diff] [blame] | 50 | int main(int argc, char* argv[]) { |
Alex Vakulenko | 274c74a | 2015-04-02 14:31:10 -0700 | [diff] [blame] | 51 | base::CommandLine::Init(argc, argv); |
Mike Frysinger | b2f7ac5 | 2018-05-17 02:36:23 -0400 | [diff] [blame] | 52 | brillo::InitLog(brillo::kLogToSyslog | brillo::kLogToStderrIfTty); |
Elly Jones | e7cb5b3 | 2011-12-01 14:18:32 -0500 | [diff] [blame] | 53 | enter_vfs_namespace(); |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 54 | Daemon().Run(); |
Elly Jones | 9aa5eca | 2011-11-04 14:48:13 -0400 | [diff] [blame] | 55 | return 0; |
| 56 | } |