1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2010-2011 Dreamhost
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.
15 #include "include/compat.h"
16 #include "common/common_init.h"
17 #include "common/admin_socket.h"
18 #include "common/ceph_argparse.h"
19 #include "common/ceph_context.h"
20 #include "common/config.h"
21 #include "common/dout.h"
22 #include "common/hostname.h"
23 #include "common/strtol.h"
24 #include "common/valgrind.h"
25 #include "common/zipkin_trace.h"
27 #define dout_subsys ceph_subsys_
30 CephContext
*common_preinit(const CephInitParameters
&iparams
,
31 enum code_environment_t code_env
, int flags
)
33 // set code environment
34 ANNOTATE_BENIGN_RACE_SIZED(&g_code_env
, sizeof(g_code_env
), "g_code_env");
35 g_code_env
= code_env
;
37 // Create a configuration object
38 CephContext
*cct
= new CephContext(iparams
.module_type
, code_env
, flags
);
40 auto& conf
= cct
->_conf
;
41 // add config observers here
43 // Set up our entity name.
44 conf
->name
= iparams
.name
;
46 // different default keyring locations for osd and mds. this is
47 // for backward compatibility. moving forward, we want all keyrings
48 // in these locations. the mon already forces $mon_data/keyring.
49 if (conf
->name
.is_mds()) {
50 conf
.set_val_default("keyring", "$mds_data/keyring");
51 } else if (conf
->name
.is_osd()) {
52 conf
.set_val_default("keyring", "$osd_data/keyring");
55 if ((flags
& CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS
)) {
56 // make this unique despite multiple instances by the same name.
57 conf
.set_val_default("admin_socket",
58 "$run_dir/$cluster-$name.$pid.$cctid.asok");
61 if (code_env
== CODE_ENVIRONMENT_LIBRARY
||
62 code_env
== CODE_ENVIRONMENT_UTILITY_NODOUT
) {
63 conf
.set_val_default("log_to_stderr", "false");
64 conf
.set_val_default("err_to_stderr", "false");
65 conf
.set_val_default("log_flush_on_exit", "false");
68 conf
.set_val("no_config_file", iparams
.no_config_file
? "true" : "false");
70 if (conf
->host
.empty()) {
71 conf
.set_val("host", ceph_get_short_hostname());
75 #endif // #ifndef WITH_SEASTAR
77 void complain_about_parse_error(CephContext
*cct
,
78 const std::string
& parse_error
)
80 if (parse_error
.empty())
82 lderr(cct
) << "Errors while parsing config file!" << dendl
;
83 lderr(cct
) << parse_error
<< dendl
;
88 /* Please be sure that this can safely be called multiple times by the
89 * same application. */
90 void common_init_finish(CephContext
*cct
)
92 // only do this once per cct
96 cct
->_finished
= true;
98 ZTracer::ztrace_init();
100 if (!cct
->_log
->is_started()) {
104 int flags
= cct
->get_init_flags();
105 if (!(flags
& CINIT_FLAG_NO_DAEMON_ACTIONS
))
106 cct
->start_service_thread();
108 if ((flags
& CINIT_FLAG_DEFER_DROP_PRIVILEGES
) &&
109 (cct
->get_set_uid() || cct
->get_set_gid())) {
110 cct
->get_admin_socket()->chown(cct
->get_set_uid(), cct
->get_set_gid());
113 const auto& conf
= cct
->_conf
;
115 if (!conf
->admin_socket
.empty() && !conf
->admin_socket_mode
.empty()) {
119 ret
= strict_strtol(conf
->admin_socket_mode
.c_str(), 8, &err
);
121 if (!(ret
& (~ACCESSPERMS
))) {
122 cct
->get_admin_socket()->chmod(static_cast<mode_t
>(ret
));
124 lderr(cct
) << "Invalid octal permissions string: "
125 << conf
->admin_socket_mode
<< dendl
;
128 lderr(cct
) << "Invalid octal string: " << err
<< dendl
;
133 #endif // #ifndef WITH_SEASTAR