commands.h 2.4 KB

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