~mathiaz/+junk/ceph-new-pkg-review

« back to all changes in this revision

Viewing changes to src/common/common_init.cc

  • Committer: Mathias Gug
  • Date: 2010-07-29 03:10:42 UTC
  • Revision ID: mathias.gug@canonical.com-20100729031042-n9n8kky962qb4onb
Import ceph_0.21-0ubuntu1 from https://launchpad.net/~clint-fewbar/+archive/ceph/+packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "config.h"
 
3
#include "tls.h"
 
4
 
 
5
#include "include/color.h"
 
6
 
 
7
#include "auth/KeyRing.h"
 
8
#include "auth/AuthSupported.h"
 
9
 
 
10
void common_set_defaults(bool daemon)
 
11
{
 
12
  if (daemon) {
 
13
    cout << TEXT_YELLOW << " ** WARNING: Ceph is still under heavy development, and is only suitable for **" << TEXT_NORMAL << std::endl;
 
14
    cout << TEXT_YELLOW <<  " **          testing and review.  Do not trust it with important data.       **" << TEXT_NORMAL << std::endl;
 
15
 
 
16
    g_conf.daemonize = true;
 
17
    g_conf.logger = true;
 
18
    g_conf.log_to_stdout = false;
 
19
  } else {
 
20
    g_conf.pid_file = 0;
 
21
  }
 
22
}
 
23
 
 
24
void common_init(std::vector<const char*>& args, const char *module_type, bool init_keys)
 
25
{
 
26
  tls_init();
 
27
  tls_get_val()->disable_assert = 0;
 
28
 
 
29
  parse_startup_config_options(args, module_type);
 
30
  parse_config_options(args);
 
31
 
 
32
  if (g_conf.log_file && g_conf.log_file[0])
 
33
    g_conf.log_to_stdout = false;
 
34
 
 
35
  // open log file?
 
36
  if (!g_conf.log_to_stdout)
 
37
    _dout_open_log();
 
38
 
 
39
  if (init_keys && is_supported_auth(CEPH_AUTH_CEPHX)) {
 
40
    g_keyring.load(g_conf.keyring);
 
41
 
 
42
    if (strlen(g_conf.key)) {
 
43
      string k = g_conf.key;
 
44
      EntityAuth ea;
 
45
      ea.key.decode_base64(k);
 
46
      g_keyring.add(*g_conf.entity_name, ea);
 
47
    } else if (strlen(g_conf.keyfile)) {
 
48
      char buf[100];
 
49
      int fd = ::open(g_conf.keyfile, O_RDONLY);
 
50
      if (fd < 0) {
 
51
        cerr << "unable to open " << g_conf.keyfile << ": " << strerror(errno) << std::endl;
 
52
        exit(1);
 
53
      }
 
54
      int len = ::read(fd, buf, sizeof(buf));
 
55
      if (len < 0) {
 
56
        cerr << "unable to read key from " << g_conf.keyfile << ": " << strerror(errno) << std::endl;
 
57
        exit(1);
 
58
      }
 
59
      ::close(fd);
 
60
 
 
61
      buf[len] = 0;
 
62
      string k = buf;
 
63
      EntityAuth ea;
 
64
      ea.key.decode_base64(k);
 
65
      g_keyring.add(*g_conf.entity_name, ea);
 
66
    }
 
67
  }
 
68
}
 
69