popen.h 2.1 KB

123456789101112131415161718192021222324252627282930313233
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_POPEN_H
  3. #define NETDATA_POPEN_H 1
  4. #include "../libnetdata.h"
  5. #define PIPE_READ 0
  6. #define PIPE_WRITE 1
  7. /* custom_popene_variadic_internal_dont_use_directly flag definitions */
  8. #define POPEN_FLAG_NONE 0
  9. #define POPEN_FLAG_CLOSE_FD (1 << 0) // Close all file descriptors other than STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO
  10. // the flags to be used by default
  11. #define POPEN_FLAGS_DEFAULT (POPEN_FLAG_CLOSE_FD)
  12. // mypopen_raw is the interface to use instead of custom_popene_variadic_internal_dont_use_directly()
  13. // mypopen_raw will add the terminating NULL at the arguments list
  14. // we append the parameter 'command' twice - this is because the underlying call needs the command to execute and the argv[0] to pass to it
  15. #define netdata_popen_raw_default_flags_and_environment(pidptr, fpp_child_input, fpp_child_output, command, args...) netdata_popene_variadic_internal_dont_use_directly(pidptr, environ, POPEN_FLAGS_DEFAULT, fpp_child_input, fpp_child_output, command, command, ##args, NULL)
  16. #define netdata_popen_raw_default_flags(pidptr, env, fpp_child_input, fpp_child_output, command, args...) netdata_popene_variadic_internal_dont_use_directly(pidptr, env, POPEN_FLAGS_DEFAULT, fpp_child_input, fpp_child_output, command, command, ##args, NULL)
  17. #define netdata_popen_raw(pidptr, env, flags, fpp_child_input, fpp_child_output, command, args...) netdata_popene_variadic_internal_dont_use_directly(pidptr, env, flags, fpp_child_input, fpp_child_output, command, command, ##args, NULL)
  18. FILE *netdata_popen(const char *command, volatile pid_t *pidptr, FILE **fp_child_input);
  19. FILE *netdata_popene(const char *command, volatile pid_t *pidptr, char **env, FILE **fp_child_input);
  20. int netdata_popene_variadic_internal_dont_use_directly(volatile pid_t *pidptr, char **env, uint8_t flags, FILE **fpp_child_input, FILE **fpp_child_output, const char *command, ...);
  21. int netdata_pclose(FILE *fp_child_input, FILE *fp_child_output, pid_t pid);
  22. int netdata_spawn(const char *command, volatile pid_t *pidptr);
  23. int netdata_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
  24. #endif /* NETDATA_POPEN_H */