mainconfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <config.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <errno.h>
  40. #include <sys/socket.h>
  41. #include <netinet/in.h>
  42. #include <arpa/inet.h>
  43. #include <pwd.h>
  44. #include <grp.h>
  45. #include <limits.h>
  46. #include <corosync/corotypes.h>
  47. #include <corosync/list.h>
  48. #include <corosync/totem/totem.h>
  49. #include <corosync/engine/logsys.h>
  50. #include "util.h"
  51. #include "mainconfig.h"
  52. static char error_string_response[512];
  53. static struct objdb_iface_ver0 *global_objdb;
  54. DECLARE_LIST_INIT(uidgid_list_head);
  55. /* This just makes the code below a little neater */
  56. static inline int objdb_get_string (
  57. const struct objdb_iface_ver0 *objdb,
  58. hdb_handle_t object_service_handle,
  59. const char *key, char **value)
  60. {
  61. int res;
  62. *value = NULL;
  63. if ( !(res = objdb->object_key_get (object_service_handle,
  64. key,
  65. strlen (key),
  66. (void *)value,
  67. NULL))) {
  68. if (*value) {
  69. return 0;
  70. }
  71. }
  72. return -1;
  73. }
  74. static inline void objdb_get_int (
  75. const struct objdb_iface_ver0 *objdb,
  76. hdb_handle_t object_service_handle,
  77. char *key, unsigned int *intvalue)
  78. {
  79. char *value = NULL;
  80. if (!objdb->object_key_get (object_service_handle,
  81. key,
  82. strlen (key),
  83. (void *)&value,
  84. NULL)) {
  85. if (value) {
  86. *intvalue = atoi(value);
  87. }
  88. }
  89. }
  90. /**
  91. * insert_into_buffer
  92. * @target_buffer: a buffer where to write results
  93. * @bufferlen: tell us the size of the buffer to avoid overflows
  94. * @entry: entry that needs to be added to the buffer
  95. * @after: can either be NULL or set to a string.
  96. * if NULL, @entry is prependend to logsys_format_get buffer.
  97. * if set, @entry is added immediately after @after.
  98. *
  99. * Since the function is specific to logsys_format_get handling, it is implicit
  100. * that source is logsys_format_get();
  101. *
  102. * In case of failure, target_buffer could be left dirty. So don't trust
  103. * any data leftover in it.
  104. *
  105. * Searching for "after" assumes that there is only entry of "after"
  106. * in the source. Afterall we control the string here and for logging format
  107. * it makes little to no sense to have duplicate format entries.
  108. *
  109. * Returns: 0 on success, -1 on failure
  110. **/
  111. static int insert_into_buffer(
  112. char *target_buffer,
  113. size_t bufferlen,
  114. const char *entry,
  115. const char *after)
  116. {
  117. const char *current_format = NULL;
  118. current_format = logsys_format_get();
  119. /* if the entry is already in the format we don't add it again */
  120. if (strstr(current_format, entry) != NULL) {
  121. return -1;
  122. }
  123. /* if there is no "after", simply prepend the requested entry
  124. * otherwise go for beautiful string manipulation.... </sarcasm> */
  125. if (!after) {
  126. if (snprintf(target_buffer, bufferlen - 1, "%s%s",
  127. entry,
  128. current_format) >= bufferlen - 1) {
  129. return -1;
  130. }
  131. } else {
  132. const char *afterpos;
  133. size_t afterlen;
  134. size_t templen;
  135. /* check if after is contained in the format
  136. * and afterlen has a meaning or return an error */
  137. afterpos = strstr(current_format, after);
  138. afterlen = strlen(after);
  139. if ((!afterpos) || (!afterlen)) {
  140. return -1;
  141. }
  142. templen = afterpos - current_format + afterlen;
  143. if (snprintf(target_buffer, templen + 1, "%s", current_format)
  144. >= bufferlen - 1) {
  145. return -1;
  146. }
  147. if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
  148. "%s%s", entry, current_format + templen)
  149. >= bufferlen - ( templen + 1 )) {
  150. return -1;
  151. }
  152. }
  153. return 0;
  154. }
  155. /*
  156. * format set is the only global specific option that
  157. * doesn't apply at system/subsystem level.
  158. */
  159. static int corosync_main_config_format_set (
  160. struct objdb_iface_ver0 *objdb,
  161. hdb_handle_t object_handle,
  162. const char **error_string)
  163. {
  164. const char *error_reason;
  165. char new_format_buffer[PATH_MAX];
  166. char *value;
  167. int err = 0;
  168. if (!objdb_get_string (objdb,object_handle, "fileline", &value)) {
  169. if (strcmp (value, "on") == 0) {
  170. if (!insert_into_buffer(new_format_buffer,
  171. sizeof(new_format_buffer),
  172. " %f:%l", "s]")) {
  173. err = logsys_format_set(new_format_buffer);
  174. } else
  175. if (!insert_into_buffer(new_format_buffer,
  176. sizeof(new_format_buffer),
  177. "%f:%l", NULL)) {
  178. err = logsys_format_set(new_format_buffer);
  179. }
  180. } else
  181. if (strcmp (value, "off") == 0) {
  182. /* nothing to do here */
  183. } else {
  184. error_reason = "unknown value for fileline";
  185. goto parse_error;
  186. }
  187. }
  188. if (!objdb_get_string (objdb,object_handle, "function_name", &value)) {
  189. if (strcmp (value, "on") == 0) {
  190. if (!insert_into_buffer(new_format_buffer,
  191. sizeof(new_format_buffer),
  192. "%n:", "f:")) {
  193. err = logsys_format_set(new_format_buffer);
  194. } else
  195. if (!insert_into_buffer(new_format_buffer,
  196. sizeof(new_format_buffer),
  197. " %n", "s]")) {
  198. err = logsys_format_set(new_format_buffer);
  199. }
  200. } else
  201. if (strcmp (value, "off") == 0) {
  202. /* nothing to do here */
  203. } else {
  204. error_reason = "unknown value for function_name";
  205. goto parse_error;
  206. }
  207. }
  208. if (!objdb_get_string (objdb,object_handle, "timestamp", &value)) {
  209. if (strcmp (value, "on") == 0) {
  210. if(!insert_into_buffer(new_format_buffer,
  211. sizeof(new_format_buffer),
  212. "%t ", NULL)) {
  213. err = logsys_format_set(new_format_buffer);
  214. }
  215. } else
  216. if (strcmp (value, "off") == 0) {
  217. /* nothing to do here */
  218. } else {
  219. error_reason = "unknown value for timestamp";
  220. goto parse_error;
  221. }
  222. }
  223. if (err) {
  224. error_reason = "exhausted virtual memory";
  225. goto parse_error;
  226. }
  227. return (0);
  228. parse_error:
  229. *error_string = error_reason;
  230. return (-1);
  231. }
  232. static int corosync_main_config_set (
  233. struct objdb_iface_ver0 *objdb,
  234. hdb_handle_t object_handle,
  235. const char *subsys,
  236. const char **error_string)
  237. {
  238. const char *error_reason = error_string_response;
  239. char *value;
  240. unsigned int mode;
  241. /*
  242. * this bit abuses the internal logsys exported API
  243. * to guarantee that all configured subsystems are
  244. * initialized too.
  245. *
  246. * using this approach avoids some headaches caused
  247. * by IPC and TOTEM that have a special logging
  248. * handling requirements
  249. */
  250. if (subsys != NULL) {
  251. if (_logsys_subsys_create(subsys) < 0) {
  252. error_reason = "unable to create new logging subsystem";
  253. goto parse_error;
  254. }
  255. }
  256. mode = logsys_config_mode_get(subsys);
  257. if (mode < 0) {
  258. error_reason = "unable to get mode";
  259. goto parse_error;
  260. }
  261. if (!objdb_get_string (objdb,object_handle, "to_file", &value)) {
  262. log_printf(LOGSYS_LEVEL_WARNING,
  263. "Warning: the to_file config paramater has been obsoleted."
  264. " See corosync.conf man page to_logfile directive.");
  265. if (strcmp (value, "yes") == 0) {
  266. mode |= LOGSYS_MODE_OUTPUT_FILE;
  267. if (logsys_config_mode_set(subsys, mode) < 0) {
  268. error_reason = "unable to set mode to_file";
  269. goto parse_error;
  270. }
  271. } else
  272. if (strcmp (value, "no") == 0) {
  273. mode &= ~LOGSYS_MODE_OUTPUT_FILE;
  274. if (logsys_config_mode_set(subsys, mode) < 0) {
  275. error_reason = "unable to unset mode to_file";
  276. goto parse_error;
  277. }
  278. } else {
  279. error_reason = "unknown value for to_file";
  280. goto parse_error;
  281. }
  282. }
  283. if (!objdb_get_string (objdb,object_handle, "to_logfile", &value)) {
  284. if (strcmp (value, "yes") == 0) {
  285. mode |= LOGSYS_MODE_OUTPUT_FILE;
  286. if (logsys_config_mode_set(subsys, mode) < 0) {
  287. error_reason = "unable to set mode to_logfile";
  288. goto parse_error;
  289. }
  290. } else
  291. if (strcmp (value, "no") == 0) {
  292. mode &= ~LOGSYS_MODE_OUTPUT_FILE;
  293. if (logsys_config_mode_set(subsys, mode) < 0) {
  294. error_reason = "unable to unset mode to_logfile";
  295. goto parse_error;
  296. }
  297. } else {
  298. error_reason = "unknown value for to_logfile";
  299. goto parse_error;
  300. }
  301. }
  302. if (!objdb_get_string (objdb,object_handle, "to_syslog", &value)) {
  303. if (strcmp (value, "yes") == 0) {
  304. mode |= LOGSYS_MODE_OUTPUT_SYSLOG;
  305. if (logsys_config_mode_set(subsys, mode) < 0) {
  306. error_reason = "unable to set mode to_syslog";
  307. goto parse_error;
  308. }
  309. } else
  310. if (strcmp (value, "no") == 0) {
  311. mode &= ~LOGSYS_MODE_OUTPUT_SYSLOG;
  312. if (logsys_config_mode_set(subsys, mode) < 0) {
  313. error_reason = "unable to unset mode to_syslog";
  314. goto parse_error;
  315. }
  316. } else {
  317. error_reason = "unknown value for to_syslog";
  318. goto parse_error;
  319. }
  320. }
  321. if (!objdb_get_string (objdb,object_handle, "to_stderr", &value)) {
  322. if (strcmp (value, "yes") == 0) {
  323. mode |= LOGSYS_MODE_OUTPUT_STDERR;
  324. if (logsys_config_mode_set(subsys, mode) < 0) {
  325. error_reason = "unable to set mode to_stderr";
  326. goto parse_error;
  327. }
  328. } else
  329. if (strcmp (value, "no") == 0) {
  330. mode &= ~LOGSYS_MODE_OUTPUT_STDERR;
  331. if (logsys_config_mode_set(subsys, mode) < 0) {
  332. error_reason = "unable to unset mode to_stderr";
  333. goto parse_error;
  334. }
  335. } else {
  336. error_reason = "unknown value for to_syslog";
  337. goto parse_error;
  338. }
  339. }
  340. if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
  341. int syslog_facility;
  342. syslog_facility = logsys_facility_id_get(value);
  343. if (syslog_facility < 0) {
  344. error_reason = "unknown syslog facility specified";
  345. goto parse_error;
  346. }
  347. if (logsys_config_syslog_facility_set(subsys,
  348. syslog_facility) < 0) {
  349. error_reason = "unable to set syslog facility";
  350. goto parse_error;
  351. }
  352. }
  353. if (!objdb_get_string (objdb,object_handle, "syslog_level", &value)) {
  354. int syslog_priority;
  355. log_printf(LOGSYS_LEVEL_WARNING,
  356. "Warning: the syslog_level config paramater has been obsoleted."
  357. " See corosync.conf man page syslog_priority directive.");
  358. syslog_priority = logsys_priority_id_get(value);
  359. if (syslog_priority < 0) {
  360. error_reason = "unknown syslog level specified";
  361. goto parse_error;
  362. }
  363. if (logsys_config_syslog_priority_set(subsys,
  364. syslog_priority) < 0) {
  365. error_reason = "unable to set syslog level";
  366. goto parse_error;
  367. }
  368. }
  369. if (!objdb_get_string (objdb,object_handle, "syslog_priority", &value)) {
  370. int syslog_priority;
  371. syslog_priority = logsys_priority_id_get(value);
  372. if (syslog_priority < 0) {
  373. error_reason = "unknown syslog priority specified";
  374. goto parse_error;
  375. }
  376. if (logsys_config_syslog_priority_set(subsys,
  377. syslog_priority) < 0) {
  378. error_reason = "unable to set syslog priority";
  379. goto parse_error;
  380. }
  381. }
  382. if (!objdb_get_string (objdb,object_handle, "logfile", &value)) {
  383. if (logsys_config_file_set (subsys, error_string, value) < 0) {
  384. goto parse_error;
  385. }
  386. }
  387. if (!objdb_get_string (objdb,object_handle, "logfile_priority", &value)) {
  388. int logfile_priority;
  389. logfile_priority = logsys_priority_id_get(value);
  390. if (logfile_priority < 0) {
  391. error_reason = "unknown logfile priority specified";
  392. goto parse_error;
  393. }
  394. if (logsys_config_logfile_priority_set(subsys,
  395. logfile_priority) < 0) {
  396. error_reason = "unable to set logfile priority";
  397. goto parse_error;
  398. }
  399. }
  400. if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
  401. if (strcmp (value, "on") == 0) {
  402. if (logsys_config_debug_set (subsys, 1) < 0) {
  403. error_reason = "unable to set debug on";
  404. goto parse_error;
  405. }
  406. } else
  407. if (strcmp (value, "off") == 0) {
  408. if (logsys_config_debug_set (subsys, 0) < 0) {
  409. error_reason = "unable to set debug off";
  410. goto parse_error;
  411. }
  412. } else {
  413. error_reason = "unknown value for debug";
  414. goto parse_error;
  415. }
  416. }
  417. return (0);
  418. parse_error:
  419. *error_string = error_reason;
  420. return (-1);
  421. }
  422. static int corosync_main_config_read_logging (
  423. struct objdb_iface_ver0 *objdb,
  424. const char **error_string)
  425. {
  426. hdb_handle_t object_service_handle;
  427. hdb_handle_t object_logger_subsys_handle;
  428. hdb_handle_t object_find_handle;
  429. hdb_handle_t object_find_logsys_handle;
  430. const char *error_reason;
  431. char *value;
  432. objdb->object_find_create (
  433. OBJECT_PARENT_HANDLE,
  434. "logging",
  435. strlen ("logging"),
  436. &object_find_handle);
  437. if (objdb->object_find_next (
  438. object_find_handle,
  439. &object_service_handle) == 0) {
  440. /* format set is supported only for toplevel */
  441. if (corosync_main_config_format_set (objdb,
  442. object_service_handle,
  443. &error_reason) < 0) {
  444. goto parse_error;
  445. }
  446. if (corosync_main_config_set (objdb,
  447. object_service_handle,
  448. NULL,
  449. &error_reason) < 0) {
  450. goto parse_error;
  451. }
  452. /* we will need 2 of these to compensate for new logging
  453. * config format */
  454. objdb->object_find_create (
  455. object_service_handle,
  456. "logger_subsys",
  457. strlen ("logger_subsys"),
  458. &object_find_logsys_handle);
  459. while (objdb->object_find_next (
  460. object_find_logsys_handle,
  461. &object_logger_subsys_handle) == 0) {
  462. if (!objdb_get_string (objdb,
  463. object_logger_subsys_handle,
  464. "subsys", &value)) {
  465. if (corosync_main_config_set (objdb,
  466. object_logger_subsys_handle,
  467. value,
  468. &error_reason) < 0) {
  469. goto parse_error;
  470. }
  471. }
  472. else {
  473. error_reason = "subsys required for logger directive";
  474. goto parse_error;
  475. }
  476. }
  477. objdb->object_find_destroy (object_find_logsys_handle);
  478. objdb->object_find_create (
  479. object_service_handle,
  480. "logging_daemon",
  481. strlen ("logging_daemon"),
  482. &object_find_logsys_handle);
  483. while (objdb->object_find_next (
  484. object_find_logsys_handle,
  485. &object_logger_subsys_handle) == 0) {
  486. if (!objdb_get_string (objdb,
  487. object_logger_subsys_handle,
  488. "name", &value)) {
  489. if ((strcmp(value, "corosync") == 0) &&
  490. (!objdb_get_string (objdb,
  491. object_logger_subsys_handle,
  492. "subsys", &value))) {
  493. if (corosync_main_config_set (objdb,
  494. object_logger_subsys_handle,
  495. value,
  496. &error_reason) < 0) {
  497. goto parse_error;
  498. }
  499. }
  500. else {
  501. error_reason = "subsys required for logging_daemon directive";
  502. goto parse_error;
  503. }
  504. }
  505. else {
  506. error_reason = "name required for logging_daemon directive";
  507. goto parse_error;
  508. }
  509. }
  510. objdb->object_find_destroy (object_find_logsys_handle);
  511. }
  512. objdb->object_find_destroy (object_find_handle);
  513. return 0;
  514. parse_error:
  515. *error_string = error_reason;
  516. return (-1);
  517. }
  518. static int uid_determine (const char *req_user)
  519. {
  520. struct passwd *passwd;
  521. int ais_uid = 0;
  522. passwd = getpwnam(req_user);
  523. if (passwd == 0) {
  524. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", req_user);
  525. corosync_exit_error (AIS_DONE_UID_DETERMINE);
  526. }
  527. ais_uid = passwd->pw_uid;
  528. endpwent ();
  529. return ais_uid;
  530. }
  531. static int gid_determine (const char *req_group)
  532. {
  533. struct group *group;
  534. int ais_gid = 0;
  535. group = getgrnam (req_group);
  536. if (group == 0) {
  537. log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", req_group);
  538. corosync_exit_error (AIS_DONE_GID_DETERMINE);
  539. }
  540. ais_gid = group->gr_gid;
  541. endgrent ();
  542. return ais_gid;
  543. }
  544. static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
  545. void *priv_data_pt)
  546. {
  547. const char *error_string;
  548. if (type == OBJDB_RELOAD_NOTIFY_END) {
  549. /*
  550. * Reload the logsys configuration
  551. */
  552. logsys_format_set(NULL);
  553. corosync_main_config_read_logging(global_objdb,
  554. &error_string);
  555. }
  556. }
  557. static void add_logsys_config_notification(
  558. struct objdb_iface_ver0 *objdb)
  559. {
  560. global_objdb = objdb;
  561. objdb->object_track_start(OBJECT_PARENT_HANDLE,
  562. 1,
  563. NULL,
  564. NULL,
  565. NULL,
  566. main_objdb_reload_notify,
  567. NULL);
  568. }
  569. static int corosync_main_config_read_uidgid (
  570. struct objdb_iface_ver0 *objdb,
  571. const char **error_string)
  572. {
  573. hdb_handle_t object_find_handle;
  574. hdb_handle_t object_service_handle;
  575. char *value;
  576. int uid, gid;
  577. struct uidgid_item *ugi;
  578. objdb->object_find_create (
  579. OBJECT_PARENT_HANDLE,
  580. "uidgid",
  581. strlen ("uidgid"),
  582. &object_find_handle);
  583. while (objdb->object_find_next (
  584. object_find_handle,
  585. &object_service_handle) == 0) {
  586. uid = -1;
  587. gid = -1;
  588. if (!objdb_get_string (objdb,object_service_handle, "uid", &value)) {
  589. uid = uid_determine(value);
  590. }
  591. if (!objdb_get_string (objdb,object_service_handle, "gid", &value)) {
  592. gid = gid_determine(value);
  593. }
  594. if (uid > -1 || gid > -1) {
  595. ugi = malloc (sizeof (*ugi));
  596. if (ugi == NULL) {
  597. _corosync_out_of_memory_error();
  598. }
  599. ugi->uid = uid;
  600. ugi->gid = gid;
  601. list_init (&ugi->list);
  602. list_add (&ugi->list, &uidgid_list_head);
  603. }
  604. }
  605. objdb->object_find_destroy (object_find_handle);
  606. return 0;
  607. }
  608. int corosync_main_config_read (
  609. struct objdb_iface_ver0 *objdb,
  610. const char **error_string)
  611. {
  612. const char *error_reason = error_string_response;
  613. if (corosync_main_config_read_logging(objdb, error_string) < 0) {
  614. error_reason = *error_string;
  615. goto parse_error;
  616. }
  617. corosync_main_config_read_uidgid (objdb, error_string);
  618. add_logsys_config_notification(objdb);
  619. return 0;
  620. parse_error:
  621. snprintf (error_string_response, sizeof(error_string_response),
  622. "parse error in config: %s.\n",
  623. error_reason);
  624. *error_string = error_string_response;
  625. return (-1);
  626. }
  627. int corosync_main_config_compatibility_read (
  628. struct objdb_iface_ver0 *objdb,
  629. enum cs_sync_mode *minimum_sync_mode,
  630. const char **error_string)
  631. {
  632. const char *error_reason = error_string_response;
  633. char *value;
  634. *minimum_sync_mode = CS_SYNC_V1;
  635. if (!objdb_get_string (objdb, OBJECT_PARENT_HANDLE, "compatibility", &value)) {
  636. if (strcmp (value, "whitetank") == 0) {
  637. *minimum_sync_mode = CS_SYNC_V1;
  638. } else
  639. if (strcmp (value, "none") == 0) {
  640. *minimum_sync_mode = CS_SYNC_V2;
  641. } else {
  642. snprintf (error_string_response, sizeof (error_string_response),
  643. "Invalid compatibility option '%s' specified, must be none or whitetank.\n", value);
  644. goto parse_error;
  645. }
  646. }
  647. return 0;
  648. parse_error:
  649. *error_string = error_reason;
  650. return (-1);
  651. }