commands.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_COMMANDS_H
  3. #define NETDATA_COMMANDS_H 1
  4. #ifdef _WIN32
  5. # define PIPENAME "\\\\?\\pipe\\netdata-cli"
  6. #else
  7. # define PIPENAME "/tmp/netdata-ipc"
  8. #endif
  9. #define MAX_COMMAND_LENGTH 4096
  10. #define MAX_EXIT_STATUS_LENGTH 23 /* Can't ever be bigger than "X-18446744073709551616" */
  11. typedef enum cmd {
  12. CMD_HELP = 0,
  13. CMD_RELOAD_HEALTH,
  14. CMD_SAVE_DATABASE,
  15. CMD_REOPEN_LOGS,
  16. CMD_EXIT,
  17. CMD_FATAL,
  18. CMD_RELOAD_CLAIMING_STATE,
  19. CMD_RELOAD_LABELS,
  20. CMD_READ_CONFIG,
  21. CMD_WRITE_CONFIG,
  22. CMD_PING,
  23. CMD_ACLK_STATE,
  24. CMD_TOTAL_COMMANDS
  25. } cmd_t;
  26. typedef enum cmd_status {
  27. CMD_STATUS_SUCCESS = 0,
  28. CMD_STATUS_FAILURE,
  29. CMD_STATUS_BUSY
  30. } cmd_status_t;
  31. #define CMD_PREFIX_INFO 'O' /* Following string should go to cli stdout */
  32. #define CMD_PREFIX_ERROR 'E' /* Following string should go to cli stderr */
  33. #define CMD_PREFIX_EXIT_CODE 'X' /* Following string is cli integer exit code */
  34. typedef enum cmd_type {
  35. /*
  36. * No other command is allowed to run at the same time (except for CMD_TYPE_HIGH_PRIORITY).
  37. */
  38. CMD_TYPE_EXCLUSIVE = 0,
  39. /*
  40. * Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) but calls to this command are
  41. * serialized.
  42. */
  43. CMD_TYPE_ORTHOGONAL,
  44. /*
  45. * Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) as are calls to this command.
  46. */
  47. CMD_TYPE_CONCURRENT,
  48. /*
  49. * Those commands are always allowed to run.
  50. */
  51. CMD_TYPE_HIGH_PRIORITY
  52. } cmd_type_t;
  53. /**
  54. * Executes a command and returns the status.
  55. *
  56. * @param args a string that may contain additional parameters to be parsed
  57. * @param message allocate and return a message if need be (up to MAX_COMMAND_LENGTH bytes)
  58. * @return CMD_FAILURE or CMD_SUCCESS
  59. */
  60. typedef cmd_status_t (command_action_t) (char *args, char **message);
  61. typedef struct command_info {
  62. char *cmd_str; // the command string
  63. command_action_t *func; // the function that executes the command
  64. cmd_type_t type; // Concurrency control information for the command
  65. } command_info_t;
  66. typedef void (command_lock_t) (unsigned index);
  67. cmd_status_t execute_command(cmd_t idx, char *args, char **message);
  68. extern void commands_init(void);
  69. extern void commands_exit(void);
  70. #endif //NETDATA_COMMANDS_H