OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cryptohome/service.h" | 5 #include "cryptohome/service.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 | 9 |
10 #include <base/command_line.h> | 10 #include <base/command_line.h> |
11 #include <base/logging.h> | 11 #include <base/logging.h> |
12 | 12 |
13 // TODO(wad) This is a placeholder DBus service which allows | 13 // TODO(wad) This is a placeholder DBus service which allows |
14 // chrome-login (and anything else running as chronos) | 14 // chrome-login (and anything else running as chronos) |
15 // to request to mount, unmount, or check if a mapper | 15 // to request to mount, unmount, or check if a mapper |
16 // device is mounted. This is very temporary but should | 16 // device is mounted. This is very temporary but should |
17 // serve as a baseline for moving all the shell scripts | 17 // serve as a baseline for moving all the shell scripts |
18 // into C++. | 18 // into C++. |
19 // We will need a "CheckKey" interface as well to simplify | 19 // We will need a "CheckKey" interface as well to simplify |
20 // offline authentication checks. | 20 // offline authentication checks. |
21 | 21 |
22 | 22 |
23 namespace switches { | 23 namespace switches { |
24 // Specifies the mount command to call | |
25 static const char *kMountSwitch = "mount"; | |
26 // Specifies the unmount command to call | |
27 static const char *kUnmountSwitch = "unmount"; | |
28 // Specifies the is_mounted command to call | |
29 static const char *kIsMountedSwitch = "is_mounted"; | |
30 // Keeps std* open for debugging | 24 // Keeps std* open for debugging |
31 static const char *kNoCloseOnDaemonize = "noclose"; | 25 static const char *kNoCloseOnDaemonize = "noclose"; |
32 } // namespace switches | 26 } // namespace switches |
33 | 27 |
34 int main(int argc, char **argv) { | 28 int main(int argc, char **argv) { |
35 ::g_type_init(); | 29 ::g_type_init(); |
36 CommandLine::Init(argc, argv); | 30 CommandLine::Init(argc, argv); |
37 logging::InitLogging("/var/log/cryptohomed.log", | 31 logging::InitLogging("/var/log/cryptohomed.log", |
38 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, | 32 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, |
39 logging::DONT_LOCK_LOG_FILE, | 33 logging::DONT_LOCK_LOG_FILE, |
40 logging::APPEND_TO_OLD_LOG_FILE); | 34 logging::APPEND_TO_OLD_LOG_FILE); |
41 | 35 |
42 cryptohome::Service service; | 36 cryptohome::Service service; |
43 LOG_IF(FATAL, !service.Initialize()) << "Failed"; | 37 LOG_IF(FATAL, !service.Initialize()) << "Failed"; |
44 | 38 |
45 // Allow the commands to be configurable. | 39 // Allow the commands to be configurable. |
46 CommandLine *cl = CommandLine::ForCurrentProcess(); | 40 CommandLine *cl = CommandLine::ForCurrentProcess(); |
47 int noclose = cl->HasSwitch(switches::kNoCloseOnDaemonize); | 41 int noclose = cl->HasSwitch(switches::kNoCloseOnDaemonize); |
48 PLOG_IF(FATAL, daemon(0, noclose) == -1) << "Failed to daemonize"; | 42 PLOG_IF(FATAL, daemon(0, noclose) == -1) << "Failed to daemonize"; |
49 | 43 |
50 std::string mount_command = cl->GetSwitchValueASCII(switches::kMountSwitch); | |
51 if (!mount_command.empty()) { | |
52 service.set_mount_command(mount_command.c_str()); | |
53 } | |
54 std::string unmount_command = | |
55 cl->GetSwitchValueASCII(switches::kUnmountSwitch); | |
56 if (!unmount_command.empty()) { | |
57 service.set_unmount_command(unmount_command.c_str()); | |
58 } | |
59 std::string is_mounted_command = | |
60 cl->GetSwitchValueASCII(switches::kIsMountedSwitch); | |
61 if (!is_mounted_command.empty()) { | |
62 service.set_is_mounted_command(is_mounted_command.c_str()); | |
63 } | |
64 | |
65 LOG_IF(FATAL, !service.Register(chromeos::dbus::GetSystemBusConnection())) | 44 LOG_IF(FATAL, !service.Register(chromeos::dbus::GetSystemBusConnection())) |
66 << "Failed"; | 45 << "Failed"; |
67 LOG_IF(FATAL, !service.Run()) << "Failed"; | 46 LOG_IF(FATAL, !service.Run()) << "Failed"; |
68 return 0; | 47 return 0; |
69 } | 48 } |
OLD | NEW |