corosync-cmapctl.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Copyright (c) 2011 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Jan Friesse (jfriesse@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the Red Hat, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <stdio.h>
  36. #include <poll.h>
  37. #include <corosync/corotypes.h>
  38. #include <corosync/cmap.h>
  39. #include "../lib/util.h"
  40. #ifndef INFTIM
  41. #define INFTIM -1
  42. #endif
  43. #define MAX_TRY_AGAIN 10
  44. enum user_action {
  45. ACTION_GET,
  46. ACTION_SET,
  47. ACTION_DELETE,
  48. ACTION_PRINT_ALL,
  49. ACTION_PRINT_DEFAULT,
  50. ACTION_PRINT_PREFIX,
  51. ACTION_TRACK
  52. };
  53. struct name_to_type_item {
  54. const char *name;
  55. cmap_value_types_t type;
  56. };
  57. struct name_to_type_item name_to_type[] = {
  58. {"i8", CMAP_VALUETYPE_INT8},
  59. {"u8", CMAP_VALUETYPE_UINT8},
  60. {"i16", CMAP_VALUETYPE_INT16},
  61. {"u16", CMAP_VALUETYPE_UINT16},
  62. {"i32", CMAP_VALUETYPE_INT32},
  63. {"u32", CMAP_VALUETYPE_UINT32},
  64. {"i64", CMAP_VALUETYPE_INT64},
  65. {"u64", CMAP_VALUETYPE_UINT64},
  66. {"flt", CMAP_VALUETYPE_FLOAT},
  67. {"dbl", CMAP_VALUETYPE_DOUBLE},
  68. {"str", CMAP_VALUETYPE_STRING},
  69. {"bin", CMAP_VALUETYPE_BINARY}};
  70. static int convert_name_to_type(const char *name)
  71. {
  72. int i;
  73. for (i = 0; i < sizeof(name_to_type) / sizeof(*name_to_type); i++) {
  74. if (strcmp(name, name_to_type[i].name) == 0) {
  75. return (name_to_type[i].type);
  76. }
  77. }
  78. return (-1);
  79. }
  80. static int print_help(void)
  81. {
  82. printf("\n");
  83. printf("usage: corosync-cmapctl ");
  84. printf("\n");
  85. return (0);
  86. }
  87. static void print_key(cmap_handle_t handle,
  88. const char *key_name,
  89. size_t value_len,
  90. const void *value,
  91. cmap_value_types_t type)
  92. {
  93. char *str;
  94. cs_error_t err;
  95. int8_t i8;
  96. uint8_t u8;
  97. int16_t i16;
  98. uint16_t u16;
  99. int32_t i32;
  100. uint32_t u32;
  101. int64_t i64;
  102. uint64_t u64;
  103. float flt;
  104. double dbl;
  105. int end_loop;
  106. int no_retries;
  107. end_loop = 0;
  108. no_retries = 0;
  109. err = CS_OK;
  110. while (!end_loop) {
  111. switch (type) {
  112. case CMAP_VALUETYPE_INT8:
  113. if (value == NULL) {
  114. err = cmap_get_int8(handle, key_name, &i8);
  115. } else {
  116. i8 = *((int8_t *)value);
  117. }
  118. break;
  119. case CMAP_VALUETYPE_INT16:
  120. if (value == NULL) {
  121. err = cmap_get_int16(handle, key_name, &i16);
  122. } else {
  123. i16 = *((int16_t *)value);
  124. }
  125. break;
  126. case CMAP_VALUETYPE_INT32:
  127. if (value == NULL) {
  128. err = cmap_get_int32(handle, key_name, &i32);
  129. } else {
  130. i32 = *((int32_t *)value);
  131. }
  132. break;
  133. case CMAP_VALUETYPE_INT64:
  134. if (value == NULL) {
  135. err = cmap_get_int64(handle, key_name, &i64);
  136. } else {
  137. i64 = *((int64_t *)value);
  138. }
  139. break;
  140. case CMAP_VALUETYPE_UINT8:
  141. if (value == NULL) {
  142. err = cmap_get_uint8(handle, key_name, &u8);
  143. } else {
  144. u8 = *((uint8_t *)value);
  145. }
  146. break;
  147. case CMAP_VALUETYPE_UINT16:
  148. if (value == NULL) {
  149. err = cmap_get_uint16(handle, key_name, &u16);
  150. } else {
  151. u16 = *((uint16_t *)value);
  152. }
  153. break;
  154. case CMAP_VALUETYPE_UINT32:
  155. if (value == NULL) {
  156. err = cmap_get_uint32(handle, key_name, &u32);
  157. } else {
  158. u32 = *((uint32_t *)value);
  159. }
  160. break;
  161. case CMAP_VALUETYPE_UINT64:
  162. if (value == NULL) {
  163. err = cmap_get_uint64(handle, key_name, &u64);
  164. } else {
  165. u64 = *((uint64_t *)value);
  166. }
  167. break;
  168. case CMAP_VALUETYPE_FLOAT:
  169. if (value == NULL) {
  170. err = cmap_get_float(handle, key_name, &flt);
  171. } else {
  172. flt = *((float *)value);
  173. }
  174. break;
  175. case CMAP_VALUETYPE_DOUBLE:
  176. if (value == NULL) {
  177. err = cmap_get_double(handle, key_name, &dbl);
  178. } else {
  179. dbl = *((double *)value);
  180. }
  181. break;
  182. case CMAP_VALUETYPE_STRING:
  183. if (value == NULL) {
  184. err = cmap_get_string(handle, key_name, &str);
  185. } else {
  186. str = (char *)value;
  187. }
  188. break;
  189. case CMAP_VALUETYPE_BINARY: break;
  190. }
  191. if (err == CS_OK)
  192. end_loop = 1;
  193. if (err == CS_ERR_TRY_AGAIN) {
  194. sleep(1);
  195. no_retries++;
  196. }
  197. if (no_retries > MAX_TRY_AGAIN) {
  198. end_loop = 1;
  199. }
  200. };
  201. if (err != CS_OK) {
  202. fprintf(stderr, "Can't get value of %s. Error %s\n", key_name, cs_strerror(err));
  203. return ;
  204. }
  205. printf("%s (", key_name);
  206. switch (type) {
  207. case CMAP_VALUETYPE_INT8:
  208. printf("%s) = %"PRId8, "i8", i8);
  209. break;
  210. case CMAP_VALUETYPE_UINT8:
  211. printf("%s) = %"PRIu8, "u8", u8);
  212. break;
  213. case CMAP_VALUETYPE_INT16:
  214. printf("%s) = %"PRId16, "i16", i16);
  215. break;
  216. case CMAP_VALUETYPE_UINT16:
  217. printf("%s) = %"PRIu16, "u16", u16);
  218. break;
  219. case CMAP_VALUETYPE_INT32:
  220. printf("%s) = %"PRId32, "i32", i32);
  221. break;
  222. case CMAP_VALUETYPE_UINT32:
  223. printf("%s) = %"PRIu32, "u32", u32);
  224. break;
  225. case CMAP_VALUETYPE_INT64:
  226. printf("%s) = %"PRId64, "i64", i64);
  227. break;
  228. case CMAP_VALUETYPE_UINT64:
  229. printf("%s) = %"PRIu64, "u64", u64);
  230. break;
  231. case CMAP_VALUETYPE_FLOAT:
  232. printf("%s) = %f", "flt", flt);
  233. break;
  234. case CMAP_VALUETYPE_DOUBLE:
  235. printf("%s) = %lf", "dbl", dbl);
  236. break;
  237. case CMAP_VALUETYPE_STRING:
  238. printf("%s) = %s", "str", str);
  239. if (value == NULL) {
  240. free(str);
  241. }
  242. break;
  243. case CMAP_VALUETYPE_BINARY:
  244. printf("%s)", "bin");
  245. break;
  246. }
  247. printf("\n");
  248. }
  249. static void print_iter(enum user_action action, cmap_handle_t handle, const char *prefix)
  250. {
  251. cmap_iter_handle_t iter_handle;
  252. char key_name[CMAP_KEYNAME_MAXLEN + 1];
  253. size_t value_len;
  254. cmap_value_types_t type;
  255. cs_error_t err;
  256. err = cmap_iter_init(handle, prefix, &iter_handle);
  257. if (err != CS_OK) {
  258. fprintf (stderr, "Failed to initialize iteration. Error %s\n", cs_strerror(err));
  259. exit (EXIT_FAILURE);
  260. }
  261. while ((err = cmap_iter_next(handle, iter_handle, key_name, &value_len, &type)) == CS_OK) {
  262. if (action == ACTION_PRINT_DEFAULT &&
  263. strncmp(key_name, "internal_configuration", strlen("internal_configuration") == 0))
  264. continue;
  265. print_key(handle, key_name, value_len, NULL, type);
  266. }
  267. }
  268. static void cmap_notify_fn(
  269. cmap_handle_t cmap_handle,
  270. cmap_track_handle_t cmap_track_handle,
  271. int32_t event,
  272. const char *key_name,
  273. struct cmap_notify_value new_val,
  274. struct cmap_notify_value old_val,
  275. void *user_data)
  276. {
  277. switch (event) {
  278. case CMAP_TRACK_ADD:
  279. printf("create> ");
  280. print_key(cmap_handle, key_name, new_val.len, new_val.data, new_val.type);
  281. break;
  282. case CMAP_TRACK_DELETE:
  283. printf("delete> ");
  284. print_key(cmap_handle, key_name, old_val.len, old_val.data, old_val.type);
  285. break;
  286. case CMAP_TRACK_MODIFY:
  287. printf("modify> ");
  288. print_key(cmap_handle, key_name, new_val.len, new_val.data, new_val.type);
  289. break;
  290. default:
  291. printf("unknown change> ");
  292. break;
  293. }
  294. }
  295. static void add_track(cmap_handle_t handle, const char *key_name, int prefix)
  296. {
  297. cmap_track_handle_t track_handle;
  298. int32_t track_type;
  299. cs_error_t err;
  300. track_type = CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_MODIFY;
  301. if (prefix) {
  302. track_type |= CMAP_TRACK_PREFIX;
  303. }
  304. err = cmap_track_add(handle, key_name, track_type, cmap_notify_fn, NULL, &track_handle);
  305. if (err != CS_OK) {
  306. fprintf(stderr, "Failed to add tracking function. Error %s\n", cs_strerror(err));
  307. exit (EXIT_FAILURE);
  308. }
  309. }
  310. static void track_changes(cmap_handle_t handle)
  311. {
  312. struct pollfd pfd[2];
  313. int cmap_fd;
  314. cs_error_t err;
  315. int poll_res;
  316. char inbuf[3];
  317. int quit = CS_FALSE;
  318. err = cmap_fd_get(handle, &cmap_fd);
  319. if (err != CS_OK) {
  320. fprintf(stderr, "Failed to get file handle. Error %s\n", cs_strerror(err));
  321. exit (EXIT_FAILURE);
  322. }
  323. pfd[0].fd = cmap_fd;
  324. pfd[1].fd = STDIN_FILENO;
  325. pfd[0].events = pfd[1].events = POLLIN;
  326. printf("Type \"q\" to finish\n");
  327. do {
  328. pfd[0].revents = pfd[1].revents = 0;
  329. poll_res = poll(pfd, 2, INFTIM);
  330. if (poll_res == -1) {
  331. perror("poll");
  332. }
  333. if (pfd[1].revents & POLLIN) {
  334. if (fgets(inbuf, sizeof(inbuf), stdin) == NULL) {
  335. quit = CS_TRUE;
  336. } else if (strncmp(inbuf, "q", 1) == 0) {
  337. quit = CS_TRUE;
  338. }
  339. }
  340. if (pfd[0].revents & POLLIN) {
  341. err = cmap_dispatch(handle, CS_DISPATCH_ALL);
  342. if (err != CS_OK) {
  343. fprintf(stderr, "Dispatch error %s\n", cs_strerror(err));
  344. quit = CS_TRUE;
  345. }
  346. }
  347. } while (poll_res > 0 && !quit);
  348. }
  349. static cs_error_t set_key_bin(cmap_handle_t handle, const char *key_name, const char *fname)
  350. {
  351. FILE *f;
  352. char *val;
  353. char buf[4096];
  354. size_t size;
  355. size_t readed;
  356. size_t pos;
  357. cs_error_t err;
  358. if (strcmp(fname, "-") == 0) {
  359. f = stdin;
  360. } else {
  361. f = fopen(fname, "rb");
  362. if (f == NULL) {
  363. perror("Can't open input file");
  364. exit(EXIT_FAILURE);
  365. }
  366. }
  367. val = NULL;
  368. size = 0;
  369. pos = 0;
  370. while ((readed = fread(buf, 1, sizeof(buf), f)) != 0) {
  371. size += readed;
  372. if ((val = realloc(val, size)) == NULL) {
  373. fprintf(stderr, "Can't alloc memory\n");
  374. exit (EXIT_FAILURE);
  375. }
  376. memcpy(val + pos, buf, readed);
  377. pos += readed;
  378. }
  379. if (f != stdin) {
  380. fclose(f);
  381. }
  382. err = cmap_set(handle, key_name, val, size, CMAP_VALUETYPE_BINARY);
  383. free(val);
  384. return (err);
  385. }
  386. static void set_key(cmap_handle_t handle, const char *key_name, const char *key_type_s, const char *key_value_s)
  387. {
  388. int64_t i64;
  389. uint64_t u64;
  390. double dbl;
  391. float flt;
  392. cs_error_t err;
  393. int scanf_res;
  394. cmap_value_types_t type;
  395. if (convert_name_to_type(key_type_s) == -1) {
  396. fprintf(stderr, "Unknown type %s\n", key_type_s);
  397. exit (EXIT_FAILURE);
  398. }
  399. type = convert_name_to_type(key_type_s);
  400. switch (type) {
  401. case CMAP_VALUETYPE_INT8:
  402. case CMAP_VALUETYPE_INT16:
  403. case CMAP_VALUETYPE_INT32:
  404. case CMAP_VALUETYPE_INT64:
  405. scanf_res = sscanf(key_value_s, "%"PRId64, &i64);
  406. break;
  407. case CMAP_VALUETYPE_UINT8:
  408. case CMAP_VALUETYPE_UINT16:
  409. case CMAP_VALUETYPE_UINT32:
  410. case CMAP_VALUETYPE_UINT64:
  411. scanf_res = sscanf(key_value_s, "%"PRIu64, &u64);
  412. break;
  413. case CMAP_VALUETYPE_FLOAT:
  414. scanf_res = sscanf(key_value_s, "%f", &flt);
  415. break;
  416. case CMAP_VALUETYPE_DOUBLE:
  417. scanf_res = sscanf(key_value_s, "%lf", &dbl);
  418. break;
  419. case CMAP_VALUETYPE_STRING:
  420. case CMAP_VALUETYPE_BINARY:
  421. /*
  422. * Do nothing
  423. */
  424. scanf_res = 1;
  425. break;
  426. }
  427. if (scanf_res != 1) {
  428. fprintf(stderr, "%s is not valid %s type value\n", key_value_s, key_type_s);
  429. exit(EXIT_FAILURE);
  430. }
  431. /*
  432. * We have parsed value, so insert value
  433. */
  434. switch (type) {
  435. case CMAP_VALUETYPE_INT8:
  436. if (i64 > INT8_MAX || i64 < INT8_MIN) {
  437. fprintf(stderr, "%s is not valid i8 integer\n", key_value_s);
  438. exit(EXIT_FAILURE);
  439. }
  440. err = cmap_set_int8(handle, key_name, i64);
  441. break;
  442. case CMAP_VALUETYPE_INT16:
  443. if (i64 > INT16_MAX || i64 < INT16_MIN) {
  444. fprintf(stderr, "%s is not valid i16 integer\n", key_value_s);
  445. exit(EXIT_FAILURE);
  446. }
  447. err = cmap_set_int16(handle, key_name, i64);
  448. break;
  449. case CMAP_VALUETYPE_INT32:
  450. if (i64 > INT32_MAX || i64 < INT32_MIN) {
  451. fprintf(stderr, "%s is not valid i32 integer\n", key_value_s);
  452. exit(EXIT_FAILURE);
  453. }
  454. err = cmap_set_int32(handle, key_name, i64);
  455. break;
  456. case CMAP_VALUETYPE_INT64:
  457. err = cmap_set_int64(handle, key_name, i64);
  458. break;
  459. case CMAP_VALUETYPE_UINT8:
  460. if (u64 > UINT8_MAX) {
  461. fprintf(stderr, "%s is not valid u8 integer\n", key_value_s);
  462. exit(EXIT_FAILURE);
  463. }
  464. err = cmap_set_uint8(handle, key_name, u64);
  465. break;
  466. case CMAP_VALUETYPE_UINT16:
  467. if (u64 > UINT16_MAX) {
  468. fprintf(stderr, "%s is not valid u16 integer\n", key_value_s);
  469. exit(EXIT_FAILURE);
  470. }
  471. err = cmap_set_uint16(handle, key_name, u64);
  472. break;
  473. case CMAP_VALUETYPE_UINT32:
  474. if (u64 > UINT32_MAX) {
  475. fprintf(stderr, "%s is not valid u32 integer\n", key_value_s);
  476. exit(EXIT_FAILURE);
  477. }
  478. err = cmap_set_uint32(handle, key_name, u64);
  479. break;
  480. case CMAP_VALUETYPE_UINT64:
  481. err = cmap_set_uint64(handle, key_name, u64);
  482. break;
  483. case CMAP_VALUETYPE_FLOAT:
  484. err = cmap_set_float(handle, key_name, flt);
  485. break;
  486. case CMAP_VALUETYPE_DOUBLE:
  487. err = cmap_set_double(handle, key_name, dbl);
  488. break;
  489. case CMAP_VALUETYPE_STRING:
  490. err = cmap_set_string(handle, key_name, key_value_s);
  491. break;
  492. case CMAP_VALUETYPE_BINARY:
  493. err = set_key_bin(handle, key_name, key_value_s);
  494. break;
  495. }
  496. if (err != CS_OK) {
  497. fprintf (stderr, "Failed to set key %s. Error %s\n", key_name, cs_strerror(err));
  498. exit (EXIT_FAILURE);
  499. }
  500. }
  501. int main(int argc, char *argv[])
  502. {
  503. enum user_action action;
  504. int c;
  505. cs_error_t err;
  506. cmap_handle_t handle;
  507. int i;
  508. size_t value_len;
  509. cmap_value_types_t type;
  510. int track_prefix;
  511. int no_retries;
  512. action = ACTION_PRINT_PREFIX;
  513. track_prefix = 1;
  514. while ((c = getopt(argc, argv, "hagsdtT")) != -1) {
  515. switch (c) {
  516. case 'h':
  517. return print_help();
  518. break;
  519. case 'a':
  520. action = ACTION_PRINT_ALL;
  521. break;
  522. case 'g':
  523. action = ACTION_GET;
  524. break;
  525. case 's':
  526. action = ACTION_SET;
  527. break;
  528. case 'd':
  529. action = ACTION_DELETE;
  530. break;
  531. case 't':
  532. action = ACTION_TRACK;
  533. break;
  534. case 'T':
  535. action = ACTION_TRACK;
  536. track_prefix = 0;
  537. break;
  538. case '?':
  539. return (EXIT_FAILURE);
  540. break;
  541. default:
  542. action = ACTION_PRINT_PREFIX;
  543. break;
  544. }
  545. }
  546. if (argc == 1) {
  547. action = ACTION_PRINT_DEFAULT;
  548. }
  549. argc -= optind;
  550. argv += optind;
  551. if (argc == 0 && action != ACTION_PRINT_DEFAULT && action != ACTION_PRINT_ALL) {
  552. fprintf(stderr, "Expected key after options\n");
  553. return (EXIT_FAILURE);
  554. }
  555. no_retries = 0;
  556. while ((err = cmap_initialize(&handle)) == CS_ERR_TRY_AGAIN && no_retries++ < MAX_TRY_AGAIN) {
  557. sleep(1);
  558. }
  559. if (err != CS_OK) {
  560. fprintf (stderr, "Failed to initialize the cmap API. Error %s\n", cs_strerror(err));
  561. exit (EXIT_FAILURE);
  562. }
  563. switch (action) {
  564. case ACTION_PRINT_DEFAULT:
  565. case ACTION_PRINT_ALL:
  566. print_iter(action, handle, NULL);
  567. break;
  568. case ACTION_PRINT_PREFIX:
  569. for (i = 0; i < argc; i++) {
  570. print_iter(action, handle, argv[i]);
  571. }
  572. break;
  573. case ACTION_GET:
  574. for (i = 0; i < argc; i++) {
  575. err = cmap_get(handle, argv[i], NULL, &value_len, &type);
  576. if (err == CS_OK) {
  577. print_key(handle, argv[i], value_len, NULL, type);
  578. } else {
  579. fprintf(stderr, "Can't get key %s. Error %s\n", argv[i], cs_strerror(err));
  580. }
  581. }
  582. break;
  583. case ACTION_DELETE:
  584. for (i = 0; i < argc; i++) {
  585. err = cmap_delete(handle, argv[i]);
  586. if (err != CS_OK) {
  587. fprintf(stderr, "Can't delete key %s. Error %s\n", argv[i], cs_strerror(err));
  588. }
  589. }
  590. break;
  591. case ACTION_TRACK:
  592. for (i = 0; i < argc; i++) {
  593. add_track(handle, argv[i], track_prefix);
  594. }
  595. track_changes(handle);
  596. break;
  597. case ACTION_SET:
  598. if (argc < 3) {
  599. fprintf(stderr, "At least 3 parameters are expected for set\n");
  600. return (EXIT_FAILURE);
  601. }
  602. set_key(handle, argv[0], argv[1], argv[2]);
  603. break;
  604. }
  605. err = cmap_finalize(handle);
  606. if (err != CS_OK) {
  607. fprintf (stderr, "Failed to finalize the cmap API. Error %s\n", cs_strerror(err));
  608. exit (EXIT_FAILURE);
  609. }
  610. return (0);
  611. }