4
0

mainconfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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_log_destination_set (
  233. struct objdb_iface_ver0 *objdb,
  234. hdb_handle_t object_handle,
  235. const char *subsys,
  236. const char **error_string,
  237. const char *objdb_key,
  238. unsigned int mode_mask,
  239. char deprecated,
  240. const char *replacement)
  241. {
  242. static char formatted_error_reason[128];
  243. char *value;
  244. unsigned int mode;
  245. if (!objdb_get_string (objdb, object_handle, objdb_key, &value)) {
  246. if (deprecated) {
  247. log_printf(LOGSYS_LEVEL_WARNING,
  248. "Warning: the %s config paramater has been obsoleted."
  249. " See corosync.conf man page %s directive.",
  250. objdb_key, replacement);
  251. }
  252. mode = logsys_config_mode_get (subsys);
  253. if (strcmp (value, "yes") == 0 || strcmp (value, "on") == 0) {
  254. mode |= mode_mask;
  255. if (logsys_config_mode_set(subsys, mode) < 0) {
  256. sprintf (formatted_error_reason, "unable to set mode %s", objdb_key);
  257. *error_string = formatted_error_reason;
  258. return -1;
  259. }
  260. } else
  261. if (strcmp (value, "no") == 0 || strcmp (value, "off") == 0) {
  262. mode &= ~mode_mask;
  263. if (logsys_config_mode_set(subsys, mode) < 0) {
  264. sprintf (formatted_error_reason, "unable to unset mode %s", objdb_key);
  265. *error_string = formatted_error_reason;
  266. return -1;
  267. }
  268. } else {
  269. sprintf (formatted_error_reason, "unknown value for %s", objdb_key);
  270. *error_string = formatted_error_reason;
  271. return -1;
  272. }
  273. }
  274. return 0;
  275. }
  276. static int corosync_main_config_set (
  277. struct objdb_iface_ver0 *objdb,
  278. hdb_handle_t object_handle,
  279. const char *subsys,
  280. const char **error_string)
  281. {
  282. const char *error_reason = error_string_response;
  283. char *value;
  284. int mode;
  285. /*
  286. * this bit abuses the internal logsys exported API
  287. * to guarantee that all configured subsystems are
  288. * initialized too.
  289. *
  290. * using this approach avoids some headaches caused
  291. * by IPC and TOTEM that have a special logging
  292. * handling requirements
  293. */
  294. if (subsys != NULL) {
  295. if (_logsys_subsys_create(subsys) < 0) {
  296. error_reason = "unable to create new logging subsystem";
  297. goto parse_error;
  298. }
  299. }
  300. mode = logsys_config_mode_get(subsys);
  301. if (mode < 0) {
  302. error_reason = "unable to get mode";
  303. goto parse_error;
  304. }
  305. if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
  306. "to_logfile", LOGSYS_MODE_OUTPUT_FILE, 0, NULL) != 0)
  307. goto parse_error;
  308. if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
  309. "to_stderr", LOGSYS_MODE_OUTPUT_STDERR, 0, NULL) != 0)
  310. goto parse_error;
  311. if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
  312. "to_syslog", LOGSYS_MODE_OUTPUT_SYSLOG, 0, NULL) != 0)
  313. goto parse_error;
  314. if (corosync_main_config_log_destination_set (objdb, object_handle, subsys, &error_reason,
  315. "to_file", LOGSYS_MODE_OUTPUT_FILE, 1, "to_logfile") != 0)
  316. goto parse_error;
  317. if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
  318. int syslog_facility;
  319. syslog_facility = logsys_facility_id_get(value);
  320. if (syslog_facility < 0) {
  321. error_reason = "unknown syslog facility specified";
  322. goto parse_error;
  323. }
  324. if (logsys_config_syslog_facility_set(subsys,
  325. syslog_facility) < 0) {
  326. error_reason = "unable to set syslog facility";
  327. goto parse_error;
  328. }
  329. }
  330. if (!objdb_get_string (objdb,object_handle, "syslog_level", &value)) {
  331. int syslog_priority;
  332. log_printf(LOGSYS_LEVEL_WARNING,
  333. "Warning: the syslog_level config paramater has been obsoleted."
  334. " See corosync.conf man page syslog_priority directive.");
  335. syslog_priority = logsys_priority_id_get(value);
  336. if (syslog_priority < 0) {
  337. error_reason = "unknown syslog level specified";
  338. goto parse_error;
  339. }
  340. if (logsys_config_syslog_priority_set(subsys,
  341. syslog_priority) < 0) {
  342. error_reason = "unable to set syslog level";
  343. goto parse_error;
  344. }
  345. }
  346. if (!objdb_get_string (objdb,object_handle, "syslog_priority", &value)) {
  347. int syslog_priority;
  348. syslog_priority = logsys_priority_id_get(value);
  349. if (syslog_priority < 0) {
  350. error_reason = "unknown syslog priority specified";
  351. goto parse_error;
  352. }
  353. if (logsys_config_syslog_priority_set(subsys,
  354. syslog_priority) < 0) {
  355. error_reason = "unable to set syslog priority";
  356. goto parse_error;
  357. }
  358. }
  359. if (!objdb_get_string (objdb,object_handle, "logfile", &value)) {
  360. if (logsys_config_file_set (subsys, error_string, value) < 0) {
  361. goto parse_error;
  362. }
  363. }
  364. if (!objdb_get_string (objdb,object_handle, "logfile_priority", &value)) {
  365. int logfile_priority;
  366. logfile_priority = logsys_priority_id_get(value);
  367. if (logfile_priority < 0) {
  368. error_reason = "unknown logfile priority specified";
  369. goto parse_error;
  370. }
  371. if (logsys_config_logfile_priority_set(subsys,
  372. logfile_priority) < 0) {
  373. error_reason = "unable to set logfile priority";
  374. goto parse_error;
  375. }
  376. }
  377. if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
  378. if (strcmp (value, "on") == 0) {
  379. if (logsys_config_debug_set (subsys, 1) < 0) {
  380. error_reason = "unable to set debug on";
  381. goto parse_error;
  382. }
  383. } else
  384. if (strcmp (value, "off") == 0) {
  385. if (logsys_config_debug_set (subsys, 0) < 0) {
  386. error_reason = "unable to set debug off";
  387. goto parse_error;
  388. }
  389. } else {
  390. error_reason = "unknown value for debug";
  391. goto parse_error;
  392. }
  393. }
  394. return (0);
  395. parse_error:
  396. *error_string = error_reason;
  397. return (-1);
  398. }
  399. static int corosync_main_config_read_logging (
  400. struct objdb_iface_ver0 *objdb,
  401. const char **error_string)
  402. {
  403. hdb_handle_t object_service_handle;
  404. hdb_handle_t object_logger_subsys_handle;
  405. hdb_handle_t object_find_handle;
  406. hdb_handle_t object_find_logsys_handle;
  407. const char *error_reason;
  408. char *value;
  409. objdb->object_find_create (
  410. OBJECT_PARENT_HANDLE,
  411. "logging",
  412. strlen ("logging"),
  413. &object_find_handle);
  414. if (objdb->object_find_next (
  415. object_find_handle,
  416. &object_service_handle) == 0) {
  417. /* format set is supported only for toplevel */
  418. if (corosync_main_config_format_set (objdb,
  419. object_service_handle,
  420. &error_reason) < 0) {
  421. goto parse_error;
  422. }
  423. if (corosync_main_config_set (objdb,
  424. object_service_handle,
  425. NULL,
  426. &error_reason) < 0) {
  427. goto parse_error;
  428. }
  429. /* we will need 2 of these to compensate for new logging
  430. * config format */
  431. objdb->object_find_create (
  432. object_service_handle,
  433. "logger_subsys",
  434. strlen ("logger_subsys"),
  435. &object_find_logsys_handle);
  436. while (objdb->object_find_next (
  437. object_find_logsys_handle,
  438. &object_logger_subsys_handle) == 0) {
  439. if (!objdb_get_string (objdb,
  440. object_logger_subsys_handle,
  441. "subsys", &value)) {
  442. if (corosync_main_config_set (objdb,
  443. object_logger_subsys_handle,
  444. value,
  445. &error_reason) < 0) {
  446. goto parse_error;
  447. }
  448. }
  449. else {
  450. error_reason = "subsys required for logger directive";
  451. goto parse_error;
  452. }
  453. }
  454. objdb->object_find_destroy (object_find_logsys_handle);
  455. objdb->object_find_create (
  456. object_service_handle,
  457. "logging_daemon",
  458. strlen ("logging_daemon"),
  459. &object_find_logsys_handle);
  460. while (objdb->object_find_next (
  461. object_find_logsys_handle,
  462. &object_logger_subsys_handle) == 0) {
  463. if (!objdb_get_string (objdb,
  464. object_logger_subsys_handle,
  465. "name", &value)) {
  466. if (strcmp(value, "corosync") == 0) {
  467. if (!objdb_get_string (objdb,
  468. object_logger_subsys_handle,
  469. "subsys", &value)) {
  470. if (corosync_main_config_set (objdb,
  471. object_logger_subsys_handle,
  472. value,
  473. &error_reason) < 0) {
  474. goto parse_error;
  475. }
  476. }
  477. else {
  478. if (corosync_main_config_set (objdb,
  479. object_logger_subsys_handle,
  480. NULL,
  481. &error_reason) < 0) {
  482. goto parse_error;
  483. }
  484. }
  485. }
  486. }
  487. else {
  488. error_reason = "name required for logging_daemon directive";
  489. goto parse_error;
  490. }
  491. }
  492. objdb->object_find_destroy (object_find_logsys_handle);
  493. }
  494. objdb->object_find_destroy (object_find_handle);
  495. return 0;
  496. parse_error:
  497. *error_string = error_reason;
  498. return (-1);
  499. }
  500. static int uid_determine (const char *req_user)
  501. {
  502. struct passwd passwd;
  503. struct passwd* pwdptr = &passwd;
  504. struct passwd* temp_pwd_pt;
  505. char pwdbuffer[200];
  506. int pwdlinelen = sizeof(pwdbuffer);
  507. if ((getpwnam_r (req_user, pwdptr, pwdbuffer, pwdlinelen, &temp_pwd_pt)) != 0) {
  508. log_printf (LOGSYS_LEVEL_ERROR,
  509. "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n",
  510. req_user);
  511. corosync_exit_error (AIS_DONE_UID_DETERMINE);
  512. }
  513. return passwd.pw_uid;
  514. }
  515. static int gid_determine (const char *req_group)
  516. {
  517. int ais_gid = 0;
  518. struct group group;
  519. struct group * grpptr = &group;
  520. struct group * temp_grp_pt;
  521. char grpbuffer[200];
  522. int grplinelen = sizeof(grpbuffer);
  523. if ((getgrnam_r (req_group, grpptr, grpbuffer, grplinelen, &temp_grp_pt)) != 0) {
  524. log_printf (LOGSYS_LEVEL_ERROR,
  525. "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n",
  526. req_group);
  527. corosync_exit_error (AIS_DONE_GID_DETERMINE);
  528. }
  529. ais_gid = group.gr_gid;
  530. return ais_gid;
  531. }
  532. static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
  533. void *priv_data_pt)
  534. {
  535. const char *error_string;
  536. if (type == OBJDB_RELOAD_NOTIFY_END) {
  537. /*
  538. * Reload the logsys configuration
  539. */
  540. logsys_format_set(NULL);
  541. corosync_main_config_read_logging(global_objdb,
  542. &error_string);
  543. }
  544. }
  545. static void add_logsys_config_notification(
  546. struct objdb_iface_ver0 *objdb)
  547. {
  548. global_objdb = objdb;
  549. objdb->object_track_start(OBJECT_PARENT_HANDLE,
  550. 1,
  551. NULL,
  552. NULL,
  553. NULL,
  554. main_objdb_reload_notify,
  555. NULL);
  556. }
  557. static int corosync_main_config_read_uidgid (
  558. struct objdb_iface_ver0 *objdb,
  559. const char **error_string)
  560. {
  561. hdb_handle_t object_find_handle;
  562. hdb_handle_t object_service_handle;
  563. char *value;
  564. int uid, gid;
  565. struct uidgid_item *ugi;
  566. objdb->object_find_create (
  567. OBJECT_PARENT_HANDLE,
  568. "uidgid",
  569. strlen ("uidgid"),
  570. &object_find_handle);
  571. while (objdb->object_find_next (
  572. object_find_handle,
  573. &object_service_handle) == 0) {
  574. uid = -1;
  575. gid = -1;
  576. if (!objdb_get_string (objdb,object_service_handle, "uid", &value)) {
  577. uid = uid_determine(value);
  578. }
  579. if (!objdb_get_string (objdb,object_service_handle, "gid", &value)) {
  580. gid = gid_determine(value);
  581. }
  582. if (uid > -1 || gid > -1) {
  583. ugi = malloc (sizeof (*ugi));
  584. if (ugi == NULL) {
  585. _corosync_out_of_memory_error();
  586. }
  587. ugi->uid = uid;
  588. ugi->gid = gid;
  589. list_init (&ugi->list);
  590. list_add (&ugi->list, &uidgid_list_head);
  591. }
  592. }
  593. objdb->object_find_destroy (object_find_handle);
  594. return 0;
  595. }
  596. int corosync_main_config_read (
  597. struct objdb_iface_ver0 *objdb,
  598. const char **error_string)
  599. {
  600. const char *error_reason = error_string_response;
  601. if (corosync_main_config_read_logging(objdb, error_string) < 0) {
  602. error_reason = *error_string;
  603. goto parse_error;
  604. }
  605. corosync_main_config_read_uidgid (objdb, error_string);
  606. add_logsys_config_notification(objdb);
  607. return 0;
  608. parse_error:
  609. snprintf (error_string_response, sizeof(error_string_response),
  610. "parse error in config: %s.\n",
  611. error_reason);
  612. *error_string = error_string_response;
  613. return (-1);
  614. }
  615. int corosync_main_config_compatibility_read (
  616. struct objdb_iface_ver0 *objdb,
  617. enum cs_sync_mode *minimum_sync_mode,
  618. const char **error_string)
  619. {
  620. const char *error_reason = error_string_response;
  621. char *value;
  622. *minimum_sync_mode = CS_SYNC_V1;
  623. if (!objdb_get_string (objdb, OBJECT_PARENT_HANDLE, "compatibility", &value)) {
  624. if (strcmp (value, "whitetank") == 0) {
  625. *minimum_sync_mode = CS_SYNC_V1;
  626. } else
  627. if (strcmp (value, "none") == 0) {
  628. *minimum_sync_mode = CS_SYNC_V2;
  629. } else {
  630. snprintf (error_string_response, sizeof (error_string_response),
  631. "Invalid compatibility option '%s' specified, must be none or whitetank.\n", value);
  632. goto parse_error;
  633. }
  634. }
  635. return 0;
  636. parse_error:
  637. *error_string = error_reason;
  638. return (-1);
  639. }