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 "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/strtol.h"
23   	#include "common/valgrind.h"
24   	#include "common/zipkin_trace.h"
25   	
26   	#define dout_subsys ceph_subsys_
27   	
28   	#ifndef WITH_SEASTAR
29   	CephContext *common_preinit(const CephInitParameters &iparams,
30   				    enum code_environment_t code_env, int flags)
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
(1) Event fun_call_w_exception: Called function throws an exception of type "ceph::buffer::v14_2_0::end_of_buffer". [details]
37   	  CephContext *cct = new CephContext(iparams.module_type, code_env, flags);
38   	
39   	  auto& conf = cct->_conf;
40   	  // add config observers here
41   	
42   	  // Set up our entity name.
43   	  conf->name = iparams.name;
44   	
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()) {
49   	    conf.set_val_default("keyring", "$mds_data/keyring");
50   	  } else if (conf->name.is_osd()) {
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");
58   	  }
59   	
60   	  if (code_env == CODE_ENVIRONMENT_LIBRARY ||
61   	      code_env == CODE_ENVIRONMENT_UTILITY_NODOUT) {
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");
65   	  }
66   	
67   	  return cct;
68   	}
69   	#endif	// #ifndef WITH_SEASTAR
70   	
71   	void complain_about_parse_error(CephContext *cct,
72   					const string& parse_error)
73   	{
74   	  if (parse_error.empty())
75   	    return;
76   	  lderr(cct) << "Errors while parsing config file!" << dendl;
77   	  lderr(cct) << parse_error << dendl;
78   	}
79   	
80   	#ifndef WITH_SEASTAR
81   	
82   	/* Please be sure that this can safely be called multiple times by the
83   	 * same application. */
84   	void common_init_finish(CephContext *cct)
85   	{
86   	  // only do this once per cct
87   	  if (cct->_finished) {
88   	    return;
89   	  }
90   	  cct->_finished = true;
91   	  cct->init_crypto();
92   	  ZTracer::ztrace_init();
93   	
94   	  if (!cct->_log->is_started()) {
95   	    cct->_log->start();
96   	  }
97   	
98   	  int flags = cct->get_init_flags();
99   	  if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS))
100  	    cct->start_service_thread();
101  	
102  	  if ((flags & CINIT_FLAG_DEFER_DROP_PRIVILEGES) &&
103  	      (cct->get_set_uid() || cct->get_set_gid())) {
104  	    cct->get_admin_socket()->chown(cct->get_set_uid(), cct->get_set_gid());
105  	  }
106  	
107  	  const auto& conf = cct->_conf;
108  	
109  	  if (!conf->admin_socket.empty() && !conf->admin_socket_mode.empty()) {
110  	    int ret = 0;
111  	    std::string err;
112  	
113  	    ret = strict_strtol(conf->admin_socket_mode.c_str(), 8, &err);
114  	    if (err.empty()) {
115  	      if (!(ret & (~ACCESSPERMS))) {
116  	        cct->get_admin_socket()->chmod(static_cast<mode_t>(ret));
117  	      } else {
118  	        lderr(cct) << "Invalid octal permissions string: "
119  	            << conf->admin_socket_mode << dendl;
120  	      }
121  	    } else {
122  	      lderr(cct) << "Invalid octal string: " << err << dendl;
123  	    }
124  	  }
125  	}
126  	
127  	#endif	// #ifndef WITH_SEASTAR
128