]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2010-2011 Dreamhost | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
11fdf7f2 TL |
15 | #include "include/compat.h" |
16 | #include "common/common_init.h" | |
7c673cae FG |
17 | #include "common/admin_socket.h" |
18 | #include "common/ceph_argparse.h" | |
11fdf7f2 TL |
19 | #include "common/ceph_context.h" |
20 | #include "common/config.h" | |
21 | #include "common/dout.h" | |
22 | #include "common/strtol.h" | |
7c673cae | 23 | #include "common/valgrind.h" |
7c673cae | 24 | #include "common/zipkin_trace.h" |
7c673cae FG |
25 | |
26 | #define dout_subsys ceph_subsys_ | |
27 | ||
11fdf7f2 | 28 | #ifndef WITH_SEASTAR |
7c673cae | 29 | CephContext *common_preinit(const CephInitParameters &iparams, |
b32b8144 | 30 | enum code_environment_t code_env, int flags) |
7c673cae FG |
31 | { |
32 | // set code environment | |
33 | ANNOTATE_BENIGN_RACE_SIZED(&g_code_env, sizeof(g_code_env), "g_code_env"); | |
34 | g_code_env = code_env; | |
35 | ||
36 | // Create a configuration object | |
c07f9fc5 | 37 | CephContext *cct = new CephContext(iparams.module_type, code_env, flags); |
7c673cae | 38 | |
11fdf7f2 | 39 | auto& conf = cct->_conf; |
7c673cae FG |
40 | // add config observers here |
41 | ||
42 | // Set up our entity name. | |
43 | conf->name = iparams.name; | |
44 | ||
c07f9fc5 FG |
45 | // different default keyring locations for osd and mds. this is |
46 | // for backward compatibility. moving forward, we want all keyrings | |
47 | // in these locations. the mon already forces $mon_data/keyring. | |
48 | if (conf->name.is_mds()) { | |
11fdf7f2 | 49 | conf.set_val_default("keyring", "$mds_data/keyring"); |
c07f9fc5 | 50 | } else if (conf->name.is_osd()) { |
11fdf7f2 TL |
51 | conf.set_val_default("keyring", "$osd_data/keyring"); |
52 | } | |
53 | ||
54 | if ((flags & CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS)) { | |
55 | // make this unique despite multiple instances by the same name. | |
56 | conf.set_val_default("admin_socket", | |
57 | "$run_dir/$cluster-$name.$pid.$cctid.asok"); | |
c07f9fc5 | 58 | } |
7c673cae | 59 | |
c07f9fc5 FG |
60 | if (code_env == CODE_ENVIRONMENT_LIBRARY || |
61 | code_env == CODE_ENVIRONMENT_UTILITY_NODOUT) { | |
11fdf7f2 TL |
62 | conf.set_val_default("log_to_stderr", "false"); |
63 | conf.set_val_default("err_to_stderr", "false"); | |
64 | conf.set_val_default("log_flush_on_exit", "false"); | |
3efd9988 | 65 | } |
7c673cae | 66 | |
9f95a23c TL |
67 | conf.set_val("no_config_file", iparams.no_config_file ? "true" : "false"); |
68 | ||
7c673cae FG |
69 | return cct; |
70 | } | |
11fdf7f2 | 71 | #endif // #ifndef WITH_SEASTAR |
7c673cae | 72 | |
9f95a23c TL |
73 | void complain_about_parse_error(CephContext *cct, |
74 | const string& parse_error) | |
7c673cae | 75 | { |
9f95a23c | 76 | if (parse_error.empty()) |
7c673cae FG |
77 | return; |
78 | lderr(cct) << "Errors while parsing config file!" << dendl; | |
9f95a23c | 79 | lderr(cct) << parse_error << dendl; |
7c673cae FG |
80 | } |
81 | ||
11fdf7f2 TL |
82 | #ifndef WITH_SEASTAR |
83 | ||
7c673cae FG |
84 | /* Please be sure that this can safely be called multiple times by the |
85 | * same application. */ | |
86 | void common_init_finish(CephContext *cct) | |
87 | { | |
11fdf7f2 TL |
88 | // only do this once per cct |
89 | if (cct->_finished) { | |
90 | return; | |
91 | } | |
92 | cct->_finished = true; | |
7c673cae FG |
93 | cct->init_crypto(); |
94 | ZTracer::ztrace_init(); | |
95 | ||
11fdf7f2 TL |
96 | if (!cct->_log->is_started()) { |
97 | cct->_log->start(); | |
98 | } | |
99 | ||
7c673cae FG |
100 | int flags = cct->get_init_flags(); |
101 | if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS)) | |
102 | cct->start_service_thread(); | |
103 | ||
104 | if ((flags & CINIT_FLAG_DEFER_DROP_PRIVILEGES) && | |
105 | (cct->get_set_uid() || cct->get_set_gid())) { | |
106 | cct->get_admin_socket()->chown(cct->get_set_uid(), cct->get_set_gid()); | |
107 | } | |
108 | ||
11fdf7f2 | 109 | const auto& conf = cct->_conf; |
7c673cae FG |
110 | |
111 | if (!conf->admin_socket.empty() && !conf->admin_socket_mode.empty()) { | |
112 | int ret = 0; | |
113 | std::string err; | |
114 | ||
115 | ret = strict_strtol(conf->admin_socket_mode.c_str(), 8, &err); | |
116 | if (err.empty()) { | |
117 | if (!(ret & (~ACCESSPERMS))) { | |
118 | cct->get_admin_socket()->chmod(static_cast<mode_t>(ret)); | |
119 | } else { | |
120 | lderr(cct) << "Invalid octal permissions string: " | |
121 | << conf->admin_socket_mode << dendl; | |
122 | } | |
123 | } else { | |
124 | lderr(cct) << "Invalid octal string: " << err << dendl; | |
125 | } | |
126 | } | |
127 | } | |
11fdf7f2 TL |
128 | |
129 | #endif // #ifndef WITH_SEASTAR |