popen.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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_CREATE_PIPE 1 // Create a pipe like popen() when set, otherwise set stdout to /dev/null
  10. #define POPEN_FLAG_CLOSE_FD 2 // Close all file descriptors other than STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO
  11. // the flags to be used by default
  12. #define POPEN_FLAGS_DEFAULT (POPEN_FLAG_CREATE_PIPE|POPEN_FLAG_CLOSE_FD)
  13. // mypopen_raw is the interface to use instead of custom_popene_variadic_internal_dont_use_directly()
  14. // mypopen_raw will add the terminating NULL at the arguments list
  15. // 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
  16. #define mypopen_raw_default_flags_and_environment(pidptr, fpp, command, args...) custom_popene_variadic_internal_dont_use_directly(pidptr, environ, POPEN_FLAGS_DEFAULT, fpp, command, command, ##args, NULL)
  17. #define mypopen_raw_default_flags(pidptr, env, fpp, command, args...) custom_popene_variadic_internal_dont_use_directly(pidptr, env, POPEN_FLAGS_DEFAULT, fpp, command, command, ##args, NULL)
  18. #define mypopen_raw(pidptr, env, flags, fpp, command, args...) custom_popene_variadic_internal_dont_use_directly(pidptr, env, flags, fpp, command, command, ##args, NULL)
  19. extern int custom_popene_variadic_internal_dont_use_directly(volatile pid_t *pidptr, char **env, uint8_t flags, FILE **fpp, const char *command, ...);
  20. extern FILE *mypopen(const char *command, volatile pid_t *pidptr);
  21. extern FILE *mypopene(const char *command, volatile pid_t *pidptr, char **env);
  22. extern int mypclose(FILE *fp, pid_t pid);
  23. extern int netdata_spawn(const char *command, volatile pid_t *pidptr);
  24. extern int netdata_spawn_waitpid(pid_t pid);
  25. extern void myp_init(void);
  26. extern void myp_free(void);
  27. extern int myp_reap(pid_t pid);
  28. extern void signals_unblock(void);
  29. extern void signals_reset(void);
  30. #endif /* NETDATA_POPEN_H */