]>
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 | ||
15 | #include "common/admin_socket.h" | |
16 | #include "common/ceph_argparse.h" | |
7c673cae | 17 | #include "common/common_init.h" |
7c673cae | 18 | #include "common/valgrind.h" |
7c673cae | 19 | #include "common/zipkin_trace.h" |
7c673cae FG |
20 | |
21 | #define dout_subsys ceph_subsys_ | |
22 | ||
23 | #define _STR(x) #x | |
24 | #define STRINGIFY(x) _STR(x) | |
25 | ||
26 | CephContext *common_preinit(const CephInitParameters &iparams, | |
27 | enum code_environment_t code_env, int flags, | |
28 | const char *data_dir_option) | |
29 | { | |
30 | // set code environment | |
31 | ANNOTATE_BENIGN_RACE_SIZED(&g_code_env, sizeof(g_code_env), "g_code_env"); | |
32 | g_code_env = code_env; | |
33 | ||
34 | // Create a configuration object | |
c07f9fc5 | 35 | CephContext *cct = new CephContext(iparams.module_type, code_env, flags); |
7c673cae FG |
36 | |
37 | md_config_t *conf = cct->_conf; | |
38 | // add config observers here | |
39 | ||
40 | // Set up our entity name. | |
41 | conf->name = iparams.name; | |
42 | ||
43 | if (data_dir_option) | |
44 | conf->data_dir_option = data_dir_option; | |
45 | ||
c07f9fc5 FG |
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("keyring", "$mds_data/keyring", false); | |
51 | } else if (conf->name.is_osd()) { | |
52 | conf->set_val("keyring", "$osd_data/keyring", false); | |
53 | } | |
7c673cae | 54 | |
c07f9fc5 FG |
55 | if (code_env == CODE_ENVIRONMENT_LIBRARY || |
56 | code_env == CODE_ENVIRONMENT_UTILITY_NODOUT) { | |
7c673cae FG |
57 | conf->set_val_or_die("log_to_stderr", "false"); |
58 | conf->set_val_or_die("err_to_stderr", "false"); | |
59 | conf->set_val_or_die("log_flush_on_exit", "false"); | |
7c673cae | 60 | } |
3efd9988 FG |
61 | if (code_env != CODE_ENVIRONMENT_DAEMON) { |
62 | // NOTE: disable ms subsystem gathering in clients by default | |
63 | conf->set_val_or_die("debug_ms", "0/0"); | |
64 | } | |
7c673cae FG |
65 | |
66 | return cct; | |
67 | } | |
68 | ||
69 | void complain_about_parse_errors(CephContext *cct, | |
70 | std::deque<std::string> *parse_errors) | |
71 | { | |
72 | if (parse_errors->empty()) | |
73 | return; | |
74 | lderr(cct) << "Errors while parsing config file!" << dendl; | |
75 | int cur_err = 0; | |
76 | static const int MAX_PARSE_ERRORS = 20; | |
77 | for (std::deque<std::string>::const_iterator p = parse_errors->begin(); | |
78 | p != parse_errors->end(); ++p) | |
79 | { | |
80 | lderr(cct) << *p << dendl; | |
81 | if (cur_err == MAX_PARSE_ERRORS) { | |
82 | lderr(cct) << "Suppressed " << (parse_errors->size() - MAX_PARSE_ERRORS) | |
83 | << " more errors." << dendl; | |
84 | break; | |
85 | } | |
86 | ++cur_err; | |
87 | } | |
88 | } | |
89 | ||
90 | /* Please be sure that this can safely be called multiple times by the | |
91 | * same application. */ | |
92 | void common_init_finish(CephContext *cct) | |
93 | { | |
94 | cct->init_crypto(); | |
95 | ZTracer::ztrace_init(); | |
96 | ||
97 | int flags = cct->get_init_flags(); | |
98 | if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS)) | |
99 | cct->start_service_thread(); | |
100 | ||
101 | if ((flags & CINIT_FLAG_DEFER_DROP_PRIVILEGES) && | |
102 | (cct->get_set_uid() || cct->get_set_gid())) { | |
103 | cct->get_admin_socket()->chown(cct->get_set_uid(), cct->get_set_gid()); | |
104 | } | |
105 | ||
106 | md_config_t *conf = cct->_conf; | |
107 | ||
108 | if (!conf->admin_socket.empty() && !conf->admin_socket_mode.empty()) { | |
109 | int ret = 0; | |
110 | std::string err; | |
111 | ||
112 | ret = strict_strtol(conf->admin_socket_mode.c_str(), 8, &err); | |
113 | if (err.empty()) { | |
114 | if (!(ret & (~ACCESSPERMS))) { | |
115 | cct->get_admin_socket()->chmod(static_cast<mode_t>(ret)); | |
116 | } else { | |
117 | lderr(cct) << "Invalid octal permissions string: " | |
118 | << conf->admin_socket_mode << dendl; | |
119 | } | |
120 | } else { | |
121 | lderr(cct) << "Invalid octal string: " << err << dendl; | |
122 | } | |
123 | } | |
124 | } |