-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Colin McCabe <[email protected]>
- Loading branch information
Showing
42 changed files
with
319 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,24 +13,19 @@ | |
*/ | ||
|
||
#include "common/DoutStreambuf.h" | ||
#include "common/Thread.h" | ||
#include "common/ceph_argparse.h" | ||
#include "common/ceph_crypto.h" | ||
#include "common/code_environment.h" | ||
#include "common/common_init.h" | ||
#include "common/config.h" | ||
#include "common/errno.h" | ||
#include "common/pidfile.h" | ||
#include "common/safe_io.h" | ||
#include "common/signal.h" | ||
#include "common/version.h" | ||
#include "include/color.h" | ||
#include "common/Thread.h" | ||
#include "common/pidfile.h" | ||
|
||
#include <errno.h> | ||
#include <deque> | ||
#include <syslog.h> | ||
|
||
#define _STR(x) #x | ||
#define STRINGIFY(x) _STR(x) | ||
|
@@ -87,168 +82,6 @@ void complain_about_parse_errors(std::deque<std::string> *parse_errors) | |
} | ||
} | ||
|
||
void common_init(std::vector < const char* >& args, | ||
uint32_t module_type, code_environment_t code_env, int flags) | ||
{ | ||
CephInitParameters iparams = | ||
ceph_argparse_early_args(args, module_type, flags); | ||
CephContext *cct = common_preinit(iparams, code_env, flags); | ||
md_config_t *conf = cct->_conf; | ||
|
||
std::deque<std::string> parse_errors; | ||
int ret = conf->parse_config_files(iparams.get_conf_files(), &parse_errors); | ||
if (ret == -EDOM) { | ||
dout_emergency("common_init: error parsing config file.\n"); | ||
_exit(1); | ||
} | ||
else if (ret == -EINVAL) { | ||
if (!(flags & CINIT_FLAG_NO_DEFAULT_CONFIG_FILE)) { | ||
dout_emergency("common_init: unable to open config file.\n"); | ||
_exit(1); | ||
} | ||
} | ||
else if (ret) { | ||
dout_emergency("common_init: error reading config file.\n"); | ||
_exit(1); | ||
} | ||
|
||
conf->parse_env(); // environment variables override | ||
|
||
conf->parse_argv(args); // argv override | ||
|
||
if (code_env == CODE_ENVIRONMENT_DAEMON) { | ||
if (conf->log_dir.empty() && conf->log_file.empty()) { | ||
conf->set_val_or_die("log_file", "/var/log/ceph/$name.log"); | ||
} | ||
} | ||
|
||
// Expand metavariables. Invoke configuration observers. | ||
conf->apply_changes(); | ||
|
||
// Now we're ready to complain about config file parse errors | ||
complain_about_parse_errors(&parse_errors); | ||
|
||
// signal stuff | ||
int siglist[] = { SIGPIPE, 0 }; | ||
block_signals(siglist, NULL); | ||
install_standard_sighandlers(); | ||
|
||
if (code_env == CODE_ENVIRONMENT_DAEMON) { | ||
cout << TEXT_YELLOW | ||
<< " ** WARNING: Ceph is still under development. Any feedback can be directed **" | ||
<< TEXT_NORMAL << "\n" << TEXT_YELLOW | ||
<< " ** at [email protected] or http://ceph.newdream.net/. **" | ||
<< TEXT_NORMAL << std::endl; | ||
output_ceph_version(); | ||
} | ||
if (g_lockdep) { | ||
cout << TEXT_YELLOW << "*** lockdep is enabled (" << g_lockdep | ||
<< ") ***" << TEXT_NORMAL << std::endl; | ||
lockdep_register_ceph_context(cct); | ||
} | ||
} | ||
|
||
static void pidfile_remove_void(void) | ||
{ | ||
pidfile_remove(); | ||
} | ||
|
||
/* Map stderr to /dev/null. This isn't really re-entrant; we rely on the old unix | ||
* behavior that the file descriptor that gets assigned is the lowest | ||
* available one. | ||
*/ | ||
int common_init_shutdown_stderr(CephContext *cct) | ||
{ | ||
TEMP_FAILURE_RETRY(close(STDERR_FILENO)); | ||
if (open("/dev/null", O_RDONLY) < 0) { | ||
int err = errno; | ||
derr << "common_init_shutdown_stderr: open(/dev/null) failed: error " | ||
<< err << dendl; | ||
return 1; | ||
} | ||
cct->_doss->handle_stderr_shutdown(); | ||
return 0; | ||
} | ||
|
||
void common_init_daemonize(CephContext *cct, int flags) | ||
{ | ||
if (g_code_env != CODE_ENVIRONMENT_DAEMON) | ||
return; | ||
const md_config_t *conf = cct->_conf; | ||
if (!conf->daemonize) | ||
return; | ||
int num_threads = Thread::get_num_threads(); | ||
if (num_threads > 1) { | ||
derr << "common_init_daemonize: BUG: there are " << num_threads - 1 | ||
<< " child threads already started that will now die!" << dendl; | ||
exit(1); | ||
} | ||
|
||
int ret = daemon(1, 1); | ||
if (ret) { | ||
ret = errno; | ||
derr << "common_init_daemonize: BUG: daemon error: " | ||
<< cpp_strerror(ret) << dendl; | ||
exit(1); | ||
} | ||
|
||
if (atexit(pidfile_remove_void)) { | ||
derr << "common_init_daemonize: failed to set pidfile_remove function " | ||
<< "to run at exit." << dendl; | ||
} | ||
|
||
/* This is the old trick where we make file descriptors 0, 1, and possibly 2 | ||
* point to /dev/null. | ||
* | ||
* We have to do this because otherwise some arbitrary call to open() later | ||
* in the program might get back one of these file descriptors. It's hard to | ||
* guarantee that nobody ever writes to stdout, even though they're not | ||
* supposed to. | ||
*/ | ||
TEMP_FAILURE_RETRY(close(STDIN_FILENO)); | ||
if (open("/dev/null", O_RDONLY) < 0) { | ||
int err = errno; | ||
derr << "common_init_daemonize: open(/dev/null) failed: error " | ||
<< err << dendl; | ||
exit(1); | ||
} | ||
TEMP_FAILURE_RETRY(close(STDOUT_FILENO)); | ||
if (open("/dev/null", O_RDONLY) < 0) { | ||
int err = errno; | ||
derr << "common_init_daemonize: open(/dev/null) failed: error " | ||
<< err << dendl; | ||
exit(1); | ||
} | ||
if (!(flags & CINIT_FLAG_NO_DEFAULT_CONFIG_FILE)) { | ||
ret = common_init_shutdown_stderr(cct); | ||
if (ret) { | ||
derr << "common_init_daemonize: common_init_shutdown_stderr failed with " | ||
<< "error code " << ret << dendl; | ||
exit(1); | ||
} | ||
} | ||
pidfile_write(g_conf); | ||
ret = cct->_doss->handle_pid_change(g_conf); | ||
if (ret) { | ||
derr << "common_init_daemonize: _doss->handle_pid_change failed with " | ||
<< "error code " << ret << dendl; | ||
exit(1); | ||
} | ||
ldout(cct, 1) << "finished common_init_daemonize" << dendl; | ||
} | ||
|
||
void common_init_chdir(const CephContext *cct) | ||
{ | ||
const md_config_t *conf = cct->_conf; | ||
if (conf->chdir.empty()) | ||
return; | ||
if (::chdir(conf->chdir.c_str())) { | ||
int err = errno; | ||
derr << "common_init_chdir: failed to chdir to directory: '" | ||
<< conf->chdir << "': " << cpp_strerror(err) << dendl; | ||
} | ||
} | ||
|
||
/* Please be sure that this can safely be called multiple times by the | ||
* same application. */ | ||
void common_init_finish(CephContext *cct) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.