corosync-cfgtool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * Copyright (c) 2006-2020 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake <sdake@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 MontaVista Software, 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 <stdlib.h>
  37. #include <errno.h>
  38. #include <unistd.h>
  39. #include <string.h>
  40. #include <pthread.h>
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #include <sys/select.h>
  44. #include <sys/un.h>
  45. #include <netinet/in.h>
  46. #include <arpa/inet.h>
  47. #include <limits.h>
  48. #include <getopt.h>
  49. #include <corosync/corotypes.h>
  50. #include <corosync/totem/totem.h>
  51. #include <corosync/cfg.h>
  52. #include <corosync/cmap.h>
  53. #include "util.h"
  54. #define cs_repeat(result, max, code) \
  55. do { \
  56. int counter = 0; \
  57. do { \
  58. result = code; \
  59. if (result == CS_ERR_TRY_AGAIN) { \
  60. sleep(1); \
  61. counter++; \
  62. } else { \
  63. break; \
  64. } \
  65. } while (counter < max); \
  66. } while (0)
  67. enum user_action {
  68. ACTION_NOOP=0,
  69. ACTION_LINKSTATUS_GET,
  70. ACTION_NODESTATUS_GET,
  71. ACTION_RELOAD_CONFIG,
  72. ACTION_REOPEN_LOG_FILES,
  73. ACTION_SHUTDOW,
  74. ACTION_SHOWADDR,
  75. ACTION_KILL_NODE,
  76. };
  77. static int node_compare(const void *aptr, const void *bptr)
  78. {
  79. uint32_t a,b;
  80. a = *(uint32_t *)aptr;
  81. b = *(uint32_t *)bptr;
  82. return a > b;
  83. }
  84. static int
  85. nodestatusget_do (enum user_action action, int brief)
  86. {
  87. cs_error_t result;
  88. corosync_cfg_handle_t handle;
  89. cmap_handle_t cmap_handle;
  90. char iter_key[CMAP_KEYNAME_MAXLEN];
  91. cmap_iter_handle_t iter;
  92. unsigned int local_nodeid;
  93. unsigned int local_nodeid_index=0;
  94. unsigned int other_nodeid_index=0;
  95. unsigned int nodeid;
  96. int nodeid_match_guard;
  97. cmap_value_types_t type;
  98. size_t value_len;
  99. char *str;
  100. char *transport_str = NULL;
  101. uint32_t nodeid_list[KNET_MAX_HOST];
  102. const char *link_transport[KNET_MAX_LINK];
  103. int s = 0;
  104. int rc = EXIT_SUCCESS;
  105. int transport_number = TOTEM_TRANSPORT_KNET;
  106. int i,j;
  107. struct corosync_cfg_node_status_v1 node_status;
  108. result = corosync_cfg_initialize (&handle, NULL);
  109. if (result != CS_OK) {
  110. fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result);
  111. exit (EXIT_FAILURE);
  112. }
  113. result = cmap_initialize (&cmap_handle);
  114. if (result != CS_OK) {
  115. fprintf (stderr, "Could not initialize corosync cmap API error %d\n", result);
  116. exit (EXIT_FAILURE);
  117. }
  118. result = cmap_get_string(cmap_handle, "totem.transport", &str);
  119. if (result == CS_OK) {
  120. if (strcmp (str, "udpu") == 0) {
  121. transport_number = TOTEM_TRANSPORT_UDPU;
  122. }
  123. if (strcmp (str, "udp") == 0) {
  124. transport_number = TOTEM_TRANSPORT_UDP;
  125. }
  126. transport_str = str;
  127. }
  128. if (!transport_str) {
  129. transport_str = strdup("knet"); /* It's the default */
  130. }
  131. result = corosync_cfg_local_get(handle, &local_nodeid);
  132. if (result != CS_OK) {
  133. fprintf (stderr, "Could not get the local node id, the error is: %d\n", result);
  134. free(transport_str);
  135. cmap_finalize(cmap_handle);
  136. corosync_cfg_finalize(handle);
  137. return EXIT_FAILURE;
  138. }
  139. /* Get a list of nodes. We do it this way rather than using votequorum as cfgtool
  140. * needs to be independent of quorum type
  141. */
  142. result = cmap_iter_init(cmap_handle, "nodelist.node.", &iter);
  143. if (result != CS_OK) {
  144. fprintf (stderr, "Could not get nodelist from cmap. error %d\n", result);
  145. free(transport_str);
  146. cmap_finalize(cmap_handle);
  147. corosync_cfg_finalize(handle);
  148. exit (EXIT_FAILURE);
  149. }
  150. while ((cmap_iter_next(cmap_handle, iter, iter_key, &value_len, &type)) == CS_OK) {
  151. nodeid_match_guard = 0;
  152. if (sscanf(iter_key, "nodelist.node.%*u.nodeid%n", &nodeid_match_guard) != 0) {
  153. continue;
  154. }
  155. /* check for exact match */
  156. if (nodeid_match_guard != strlen(iter_key)) {
  157. continue;
  158. }
  159. if (cmap_get_uint32(cmap_handle, iter_key, &nodeid) == CS_OK) {
  160. nodeid_list[s++] = nodeid;
  161. }
  162. }
  163. if (s == 0) {
  164. fprintf(stderr, "No nodes found in nodelist\n");
  165. exit (EXIT_FAILURE);
  166. }
  167. /* It's nice to have these in nodeid order */
  168. qsort(nodeid_list, s, sizeof(uint32_t), node_compare);
  169. /*
  170. * Find local and other nodeid index in nodeid_list
  171. */
  172. for (i = 0; i < s; i++) {
  173. if (nodeid_list[i] == local_nodeid) {
  174. local_nodeid_index = i;
  175. } else {
  176. /* Bit of an odd one this. but local node only uses one link (of course, to itself)
  177. so if we want to know which links are active across the cluster we need to look
  178. at another node (any other) node's link list */
  179. other_nodeid_index = i;
  180. }
  181. }
  182. /* Get the transport of each link - but set reasonable defaults */
  183. if (transport_number == TOTEM_TRANSPORT_KNET) {
  184. for (i = 0; i<KNET_MAX_LINK; i++) {
  185. link_transport[i] = "udp";
  186. }
  187. } else {
  188. for (i = 0; i<KNET_MAX_LINK; i++) {
  189. link_transport[i] = ""; /* No point in displaying "udp" again */
  190. }
  191. }
  192. result = cmap_iter_init(cmap_handle, "totem.interface.", &iter);
  193. if (result == CS_OK) { /* it's fine for this to fail, we just use the defaults */
  194. while ((cmap_iter_next(cmap_handle, iter, iter_key, &value_len, &type)) == CS_OK) {
  195. unsigned int link_number;
  196. char *knet_transport;
  197. char knet_transport_str[CMAP_KEYNAME_MAXLEN];
  198. /* transport is (sensibly) indexed by link number */
  199. if (sscanf(iter_key, "totem.interface.%u.knet_transport", &link_number) != 1) {
  200. continue;
  201. }
  202. snprintf(knet_transport_str, sizeof(knet_transport_str),
  203. "totem.interface.%u.knet_transport", link_number);
  204. if (cmap_get_string(cmap_handle, knet_transport_str, &knet_transport) == CS_OK) {
  205. link_transport[link_number] = knet_transport;
  206. }
  207. }
  208. cmap_iter_finalize(cmap_handle, iter);
  209. }
  210. cmap_finalize(cmap_handle);
  211. printf ("Local node ID " CS_PRI_NODE_ID ", transport %s\n", local_nodeid, transport_str);
  212. /* If node status requested then do print node-based info */
  213. if (action == ACTION_NODESTATUS_GET) {
  214. for (i=0; i<s; i++) {
  215. result = corosync_cfg_node_status_get(handle, nodeid_list[i], CFG_NODE_STATUS_V1, &node_status);
  216. if (result == CS_OK) {
  217. /* Only display node info if it is reachable (and not us) */
  218. if (node_status.reachable && node_status.nodeid != local_nodeid) {
  219. printf("nodeid: " CS_PRI_NODE_ID "", node_status.nodeid);
  220. printf(" reachable");
  221. if (node_status.remote) {
  222. printf(" remote");
  223. }
  224. if (node_status.external) {
  225. printf(" external");
  226. }
  227. #ifdef HAVE_KNET_ONWIRE_VER
  228. if (transport_number == TOTEM_TRANSPORT_KNET) {
  229. printf(" onwire (min/max/cur): %d, %d, %d",
  230. node_status.onwire_min,
  231. node_status.onwire_max,
  232. node_status.onwire_ver);
  233. }
  234. #endif
  235. printf("\n");
  236. for (j=0; j<CFG_MAX_LINKS; j++) {
  237. if (node_status.link_status[j].enabled) {
  238. printf(" LINK: %d %s", j, link_transport[j]);
  239. printf(" (%s%s%s)",
  240. node_status.link_status[j].src_ipaddr,
  241. transport_number==TOTEM_TRANSPORT_KNET?"->":"",
  242. node_status.link_status[j].dst_ipaddr);
  243. if (node_status.link_status[j].enabled) {
  244. printf(" enabled");
  245. }
  246. if (node_status.link_status[j].connected) {
  247. printf(" connected");
  248. }
  249. if (node_status.link_status[j].dynconnected) {
  250. printf(" dynconnected");
  251. }
  252. printf(" mtu: %d\n", node_status.link_status[j].mtu);
  253. }
  254. }
  255. printf("\n");
  256. }
  257. }
  258. }
  259. }
  260. /* Print in link order */
  261. else {
  262. struct corosync_cfg_node_status_v1 node_info[s];
  263. memset(node_info, 0, sizeof(node_info));
  264. for (i=0; i<s; i++) {
  265. result = corosync_cfg_node_status_get(handle, nodeid_list[i], CFG_NODE_STATUS_V1, &node_info[i]);
  266. if (result != CS_OK) {
  267. fprintf (stderr, "Could not get the node status for nodeid %d, the error is: %d\n", nodeid_list[i], result);
  268. }
  269. }
  270. for (i=0; i<CFG_MAX_LINKS; i++) {
  271. if (node_info[other_nodeid_index].link_status[i].enabled) {
  272. printf("LINK ID %d %s\n", i, link_transport[i]);
  273. printf("\taddr\t= %s\n", node_info[other_nodeid_index].link_status[i].src_ipaddr);
  274. if (brief) {
  275. printf("\tstatus\t= ");
  276. for (j=0; j<s; j++) {
  277. char status = (node_info[j].link_status[i].enabled |
  278. (node_info[j].link_status[i].connected << 1)) + '0';
  279. if (j == local_nodeid_index) {
  280. status = 'n';
  281. }
  282. printf("%c", status);
  283. }
  284. printf("\n");
  285. } else {
  286. printf("\tstatus:\n");
  287. for (j=0; j<s; j++) {
  288. printf("\t\tnodeid: " CS_PRI_NODE_ID_PADDED ":\t", node_info[j].nodeid);
  289. if (j == local_nodeid_index) {
  290. printf("localhost");
  291. } else {
  292. if (node_info[j].link_status[i].connected) {
  293. printf("connected");
  294. } else {
  295. printf("disconnected");
  296. }
  297. }
  298. printf("\n");
  299. }
  300. }
  301. }
  302. }
  303. }
  304. free(transport_str);
  305. corosync_cfg_finalize(handle);
  306. return rc;
  307. }
  308. static int check_for_reload_errors(void)
  309. {
  310. cmap_handle_t cmap_handle;
  311. cs_error_t result;
  312. char *str;
  313. int res;
  314. result = cmap_initialize (&cmap_handle);
  315. if (result != CS_OK) {
  316. fprintf (stderr, "Could not initialize corosync cmap API error %d\n", result);
  317. exit (EXIT_FAILURE);
  318. }
  319. result = cmap_get_string(cmap_handle, "config.reload_error_message", &str);
  320. if (result == CS_OK) {
  321. printf("ERROR from reload: %s - see syslog for more information\n", str);
  322. free(str);
  323. res = 1;
  324. }
  325. else {
  326. res = 0;
  327. }
  328. cmap_finalize(cmap_handle);
  329. return res;
  330. }
  331. static int reload_config_do (void)
  332. {
  333. cs_error_t result;
  334. corosync_cfg_handle_t handle;
  335. int rc;
  336. rc = EXIT_SUCCESS;
  337. printf ("Reloading corosync.conf...\n");
  338. result = corosync_cfg_initialize (&handle, NULL);
  339. if (result != CS_OK) {
  340. fprintf (stderr, "Could not initialize corosync configuration API error %s\n", cs_strerror(result));
  341. exit (EXIT_FAILURE);
  342. }
  343. result = corosync_cfg_reload_config (handle);
  344. if (result != CS_OK) {
  345. fprintf (stderr, "Could not reload configuration. Error %s\n", cs_strerror(result));
  346. rc = (int)result;
  347. }
  348. else {
  349. printf ("Done\n");
  350. }
  351. (void)corosync_cfg_finalize (handle);
  352. if ((rc = check_for_reload_errors())) {
  353. fprintf(stderr, "Errors in appying config, corosync.conf might not match the running system\n");
  354. }
  355. return (rc);
  356. }
  357. static int reopen_log_files_do (void)
  358. {
  359. cs_error_t result;
  360. corosync_cfg_handle_t handle;
  361. int rc;
  362. rc = EXIT_SUCCESS;
  363. result = corosync_cfg_initialize (&handle, NULL);
  364. if (result != CS_OK) {
  365. fprintf (stderr, "Could not initialize corosync configuration API error %s\n", cs_strerror(result));
  366. exit (EXIT_FAILURE);
  367. }
  368. result = corosync_cfg_reopen_log_files (handle);
  369. if (result != CS_OK) {
  370. fprintf (stderr, "Could not reopen corosync logging files. Error %s\n", cs_strerror(result));
  371. rc = (int)result;
  372. }
  373. (void)corosync_cfg_finalize (handle);
  374. return (rc);
  375. }
  376. static void shutdown_do(int force)
  377. {
  378. cs_error_t result;
  379. corosync_cfg_handle_t handle;
  380. corosync_cfg_callbacks_t callbacks;
  381. int flag;
  382. callbacks.corosync_cfg_shutdown_callback = NULL;
  383. if (force) {
  384. flag = COROSYNC_CFG_SHUTDOWN_FLAG_REGARDLESS;
  385. } else {
  386. flag = COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST;
  387. }
  388. result = corosync_cfg_initialize (&handle, &callbacks);
  389. if (result != CS_OK) {
  390. fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result);
  391. exit (EXIT_FAILURE);
  392. }
  393. printf ("Shutting down corosync\n");
  394. cs_repeat(result, 30, corosync_cfg_try_shutdown (handle, flag));
  395. if (result != CS_OK) {
  396. fprintf (stderr, "Could not shutdown (error = %d)\n", result);
  397. }
  398. (void)corosync_cfg_finalize (handle);
  399. }
  400. static int showaddrs_do(unsigned int nodeid)
  401. {
  402. cs_error_t result;
  403. corosync_cfg_handle_t handle;
  404. int numaddrs;
  405. int i;
  406. int rc = EXIT_SUCCESS;
  407. corosync_cfg_node_address_t addrs[INTERFACE_MAX];
  408. result = corosync_cfg_initialize (&handle, NULL);
  409. if (result != CS_OK) {
  410. fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result);
  411. exit (EXIT_FAILURE);
  412. }
  413. if (corosync_cfg_get_node_addrs(handle, nodeid, INTERFACE_MAX, &numaddrs, addrs) == CS_OK) {
  414. for (i=0; i<numaddrs; i++) {
  415. char buf[INET6_ADDRSTRLEN];
  416. struct sockaddr_storage *ss = (struct sockaddr_storage *)addrs[i].address;
  417. struct sockaddr_in *sin = (struct sockaddr_in *)addrs[i].address;
  418. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addrs[i].address;
  419. void *saddr;
  420. if (!ss->ss_family) {
  421. continue;
  422. }
  423. if (ss->ss_family == AF_INET6) {
  424. saddr = &sin6->sin6_addr;
  425. } else {
  426. saddr = &sin->sin_addr;
  427. }
  428. inet_ntop(ss->ss_family, saddr, buf, sizeof(buf));
  429. if (i != 0) {
  430. printf(" ");
  431. }
  432. printf("%s", buf);
  433. }
  434. printf("\n");
  435. } else {
  436. fprintf (stderr, "Could not get node address for nodeid %d\n", nodeid);
  437. rc = EXIT_FAILURE;
  438. }
  439. (void)corosync_cfg_finalize (handle);
  440. return rc;
  441. }
  442. static void killnode_do(unsigned int nodeid)
  443. {
  444. cs_error_t result;
  445. corosync_cfg_handle_t handle;
  446. printf ("Killing node " CS_PRI_NODE_ID "\n", nodeid);
  447. result = corosync_cfg_initialize (&handle, NULL);
  448. if (result != CS_OK) {
  449. fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result);
  450. exit (EXIT_FAILURE);
  451. }
  452. result = corosync_cfg_kill_node (handle, nodeid, "Killed by corosync-cfgtool");
  453. if (result != CS_OK) {
  454. fprintf (stderr, "Could not kill node (error = %s)\n", cs_strerror(result));
  455. exit(EXIT_FAILURE);
  456. }
  457. (void)corosync_cfg_finalize (handle);
  458. }
  459. static void usage_do (void)
  460. {
  461. printf ("corosync-cfgtool [[-i <interface ip>] [-b] -s] [-R] [-L] [-k nodeid] [-a nodeid] [-h] [-H]\n\n");
  462. printf ("A tool for displaying and configuring active parameters within corosync.\n");
  463. printf ("options:\n");
  464. printf ("\t-i\tFinds only information about the specified interface IP address or link id when used with -s..\n");
  465. printf ("\t-s\tDisplays the status of the current links on this node.\n");
  466. printf ("\t-n\tDisplays the status of the connected nodes and their links.\n");
  467. printf ("\t-b\tDisplays the brief status of the current links on this node when used with -s.\n");
  468. printf ("\t-R\tTell all instances of corosync in this cluster to reload corosync.conf.\n");
  469. printf ("\t-L\tTell corosync to reopen all logging files.\n");
  470. printf ("\t-k\tKill a node identified by node id.\n");
  471. printf ("\t-a\tDisplay the IP address(es) of a node\n");
  472. printf ("\t-h\tPrint basic usage.\n");
  473. printf ("\t-H\tShutdown corosync cleanly on this node.\n");
  474. printf ("\t\t--force will shut down corosync regardless of daemon vetos\n");
  475. }
  476. int main (int argc, char *argv[]) {
  477. int opt;
  478. unsigned int nodeid = 0;
  479. char interface_name[128] = "";
  480. int rc = EXIT_SUCCESS;
  481. enum user_action action = ACTION_NOOP;
  482. int brief = 0;
  483. long long int l;
  484. int option_index = 0;
  485. int force_shutdown = 0;
  486. const char *options = "i:snbrRLk:a:hH";
  487. struct option long_options[] = {
  488. {"if", required_argument, 0, 'i'},
  489. {"status", no_argument, 0, 's'},
  490. {"nodes", no_argument, 0, 'n'},
  491. {"brief", no_argument, 0, 'b'},
  492. {"reload", no_argument, 0, 'R'},
  493. {"reopen", no_argument, 0, 'L'},
  494. {"kill", required_argument, 0, 'k'},
  495. {"address", required_argument, 0, 'a'},
  496. {"shutdown", no_argument, 0, 'H'},
  497. {"force", no_argument, 0, 0},
  498. {0, 0, 0, 0}
  499. };
  500. while ( (opt = getopt_long(argc, argv, options, long_options, &option_index)) != -1 ) {
  501. switch (opt) {
  502. case 0: // options with no short equivalent - just --force ATM
  503. if (strcmp(long_options[option_index].name, "force") == 0) {
  504. force_shutdown = 1;
  505. }
  506. break;
  507. case 'i':
  508. strncpy(interface_name, optarg, sizeof(interface_name));
  509. interface_name[sizeof(interface_name) - 1] = '\0';
  510. break;
  511. case 's':
  512. action = ACTION_LINKSTATUS_GET;
  513. break;
  514. case 'n':
  515. action = ACTION_NODESTATUS_GET;
  516. break;
  517. case 'b':
  518. brief = 1;
  519. break;
  520. case 'R':
  521. action = ACTION_RELOAD_CONFIG;
  522. break;
  523. case 'L':
  524. action = ACTION_REOPEN_LOG_FILES;
  525. break;
  526. case 'k':
  527. if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) {
  528. fprintf(stderr, "The nodeid was not valid, try a positive number\n");
  529. exit(EXIT_FAILURE);
  530. }
  531. nodeid = l;
  532. action = ACTION_KILL_NODE;
  533. break;
  534. case 'H':
  535. action = ACTION_SHUTDOW;
  536. break;
  537. case 'a':
  538. if (util_strtonum(optarg, 1, UINT_MAX, &l) == -1) {
  539. fprintf(stderr, "The nodeid was not valid, try a positive number\n");
  540. exit(EXIT_FAILURE);
  541. }
  542. nodeid = l;
  543. action = ACTION_SHOWADDR;
  544. break;
  545. case '?':
  546. return (EXIT_FAILURE);
  547. break;
  548. case 'h':
  549. default:
  550. break;
  551. }
  552. }
  553. switch(action) {
  554. case ACTION_LINKSTATUS_GET:
  555. rc = nodestatusget_do(action, brief);
  556. break;
  557. case ACTION_NODESTATUS_GET:
  558. rc = nodestatusget_do(action, brief);
  559. break;
  560. case ACTION_RELOAD_CONFIG:
  561. rc = reload_config_do();
  562. break;
  563. case ACTION_REOPEN_LOG_FILES:
  564. rc = reopen_log_files_do();
  565. break;
  566. case ACTION_KILL_NODE:
  567. killnode_do(nodeid);
  568. break;
  569. case ACTION_SHUTDOW:
  570. shutdown_do(force_shutdown);
  571. break;
  572. case ACTION_SHOWADDR:
  573. rc = showaddrs_do(nodeid);
  574. break;
  575. case ACTION_NOOP:
  576. default:
  577. usage_do();
  578. break;
  579. }
  580. return (rc);
  581. }