Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rgw / rgw_frontend.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <signal.h>
5
6 #include "rgw_frontend.h"
7 #include "include/str_list.h"
8
9 #include "include/assert.h"
10
11
12 #define dout_context g_ceph_context
13 #define dout_subsys ceph_subsys_rgw
14
15 int RGWFrontendConfig::parse_config(const string& config,
16                                     map<string, string>& config_map)
17 {
18   list<string> config_list;
19   get_str_list(config, " ", config_list);
20
21   list<string>::iterator iter;
22   for (iter = config_list.begin(); iter != config_list.end(); ++iter) {
23     string& entry = *iter;
24     string key;
25     string val;
26
27     if (framework.empty()) {
28       framework = entry;
29       dout(0) << "framework: " << framework << dendl;
30       continue;
31     }
32
33     ssize_t pos = entry.find('=');
34     if (pos < 0) {
35       dout(0) << "framework conf key: " << entry << dendl;
36       config_map[entry] = "";
37       continue;
38     }
39
40     int ret = parse_key_value(entry, key, val);
41     if (ret < 0) {
42       cerr << "ERROR: can't parse " << entry << std::endl;
43       return ret;
44     }
45
46     dout(0) << "framework conf key: " << key << ", val: " << val << dendl;
47     config_map[key] = val;
48   }
49
50   return 0;
51 }
52
53 bool RGWFrontendConfig::get_val(const string& key, const string& def_val,
54                                 string *out)
55 {
56  map<string, string>::iterator iter = config_map.find(key);
57  if (iter == config_map.end()) {
58    *out = def_val;
59    return false;
60  }
61
62  *out = iter->second;
63  return true;
64 }
65
66 bool RGWFrontendConfig::get_val(const string& key, int def_val, int *out)
67 {
68   string str;
69   bool found = get_val(key, "", &str);
70   if (!found) {
71     *out = def_val;
72     return false;
73   }
74   string err;
75   *out = strict_strtol(str.c_str(), 10, &err);
76   if (!err.empty()) {
77     cerr << "error parsing int: " << str << ": " << err << std::endl;
78     return -EINVAL;
79   }
80   return 0;
81 }
82
83 void RGWProcessFrontend::stop()
84 {
85   pprocess->close_fd();
86   thread->kill(SIGUSR1);
87 }