commands.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_VERSION,
  25. CMD_DUMPCONFIG,
  26. CMD_TOTAL_COMMANDS
  27. } cmd_t;
  28. typedef enum cmd_status {
  29. CMD_STATUS_SUCCESS = 0,
  30. CMD_STATUS_FAILURE,
  31. CMD_STATUS_BUSY
  32. } cmd_status_t;
  33. #define CMD_PREFIX_INFO 'O' /* Following string should go to cli stdout */
  34. #define CMD_PREFIX_ERROR 'E' /* Following string should go to cli stderr */
  35. #define CMD_PREFIX_EXIT_CODE 'X' /* Following string is cli integer exit code */
  36. typedef enum cmd_type {
  37. /*
  38. * No other command is allowed to run at the same time (except for CMD_TYPE_HIGH_PRIORITY).
  39. */
  40. CMD_TYPE_EXCLUSIVE = 0,
  41. /*
  42. * Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) but calls to this command are
  43. * serialized.
  44. */
  45. CMD_TYPE_ORTHOGONAL,
  46. /*
  47. * Other commands are allowed to run concurrently (except for CMD_TYPE_EXCLUSIVE) as are calls to this command.
  48. */
  49. CMD_TYPE_CONCURRENT,
  50. /*
  51. * Those commands are always allowed to run.
  52. */
  53. CMD_TYPE_HIGH_PRIORITY
  54. } cmd_type_t;
  55. /**
  56. * Executes a command and returns the status.
  57. *
  58. * @param args a string that may contain additional parameters to be parsed
  59. * @param message allocate and return a message if need be (up to MAX_COMMAND_LENGTH bytes)
  60. * @return CMD_FAILURE or CMD_SUCCESS
  61. */
  62. typedef cmd_status_t (command_action_t) (char *args, char **message);
  63. typedef struct command_info {
  64. char *cmd_str; // the command string
  65. command_action_t *func; // the function that executes the command
  66. cmd_type_t type; // Concurrency control information for the command
  67. } command_info_t;
  68. typedef void (command_lock_t) (unsigned index);
  69. cmd_status_t execute_command(cmd_t idx, char *args, char **message);
  70. void commands_init(void);
  71. void commands_exit(void);
  72. #endif //NETDATA_COMMANDS_H