commands.h 2.3 KB

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