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 "service.h" | 5 #include "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/at_exit.h> | 10 #include <base/at_exit.h> |
11 #include <base/command_line.h> | 11 #include <base/command_line.h> |
12 #include <base/logging.h> | 12 #include <base/logging.h> |
13 #include <chromeos/syslog_logging.h> | 13 #include <chromeos/syslog_logging.h> |
14 | 14 |
15 #include "platform.h" | |
16 | |
15 // TODO(wad) This is a placeholder DBus service which allows | 17 // TODO(wad) This is a placeholder DBus service which allows |
16 // chrome-login (and anything else running as chronos) | 18 // chrome-login (and anything else running as chronos) |
17 // to request to mount, unmount, or check if a mapper | 19 // to request to mount, unmount, or check if a mapper |
18 // device is mounted. This is very temporary but should | 20 // device is mounted. This is very temporary but should |
19 // serve as a baseline for moving all the shell scripts | 21 // serve as a baseline for moving all the shell scripts |
20 // into C++. | 22 // into C++. |
21 // We will need a "CheckKey" interface as well to simplify | 23 // We will need a "CheckKey" interface as well to simplify |
22 // offline authentication checks. | 24 // offline authentication checks. |
23 | 25 |
24 | 26 |
25 namespace switches { | 27 namespace switches { |
26 // Keeps std* open for debugging | 28 // Keeps std* open for debugging |
27 static const char *kNoCloseOnDaemonize = "noclose"; | 29 static const char *kNoCloseOnDaemonize = "noclose"; |
30 } // namespace switches | |
31 | |
28 // Enable PKCS#11 initialization via cryptohomed | 32 // Enable PKCS#11 initialization via cryptohomed |
29 // TODO(gauravsh): crosbug.com/14277 Remove this flag once this | 33 // TODO(gauravsh): crosbug.com/14277 Remove this code once this |
30 // feature is stabilized. | 34 // feature is stabilized. |
31 static const char *kEnablePkcs11Init = "cryptohome-init-pkcs11"; | 35 static const char *kEnablePkcs11Path = "/home/chronos/.cryptohome-init-pkcs11"; |
32 } // namespace switches | |
33 | 36 |
34 int main(int argc, char **argv) { | 37 int main(int argc, char **argv) { |
35 ::g_type_init(); | 38 ::g_type_init(); |
36 base::AtExitManager exit_manager; | 39 base::AtExitManager exit_manager; |
37 CommandLine::Init(argc, argv); | 40 CommandLine::Init(argc, argv); |
38 | 41 |
39 chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogToStderr); | 42 chromeos::InitLog(chromeos::kLogToSyslog | chromeos::kLogToStderr); |
40 | 43 |
41 // Allow the commands to be configurable. | 44 // Allow the commands to be configurable. |
42 CommandLine *cl = CommandLine::ForCurrentProcess(); | 45 CommandLine *cl = CommandLine::ForCurrentProcess(); |
43 int noclose = cl->HasSwitch(switches::kNoCloseOnDaemonize); | 46 int noclose = cl->HasSwitch(switches::kNoCloseOnDaemonize); |
44 PLOG_IF(FATAL, daemon(0, noclose) == -1) << "Failed to daemonize"; | 47 PLOG_IF(FATAL, daemon(0, noclose) == -1) << "Failed to daemonize"; |
45 | 48 |
46 int enable_pkcs11_init = cl->HasSwitch(switches::kEnablePkcs11Init); | 49 cryptohome::Platform platform; |
50 int enable_pkcs11_init = platform.FileExists(kEnablePkcs11Path); | |
gauravsh
2011/04/20 20:39:31
one suggestion: change this to a bool (which is al
| |
47 cryptohome::Service service(enable_pkcs11_init); | 51 cryptohome::Service service(enable_pkcs11_init); |
48 if (!service.Initialize()) { | 52 if (!service.Initialize()) { |
49 LOG(FATAL) << "Service initialization failed"; | 53 LOG(FATAL) << "Service initialization failed"; |
50 return 1; | 54 return 1; |
51 } | 55 } |
52 | 56 |
53 if (!service.Register(chromeos::dbus::GetSystemBusConnection())) { | 57 if (!service.Register(chromeos::dbus::GetSystemBusConnection())) { |
54 LOG(FATAL) << "DBUS service registration failed"; | 58 LOG(FATAL) << "DBUS service registration failed"; |
55 return 1; | 59 return 1; |
56 } | 60 } |
57 | 61 |
58 if (!service.Run()) { | 62 if (!service.Run()) { |
59 LOG(FATAL) << "Service run failed."; | 63 LOG(FATAL) << "Service run failed."; |
60 return 1; | 64 return 1; |
61 } | 65 } |
62 | 66 |
63 return 0; | 67 return 0; |
64 } | 68 } |
OLD | NEW |