commands.h 2.3 KB

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