commands.h 2.2 KB

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