parent.c 865 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdlib.h>
  2. #include <reproc/reproc.h>
  3. // Forwards the provided command to `reproc_start` and redirects the standard
  4. // streams of the child process to the standard streams of the parent process.
  5. int main(int argc, const char **argv)
  6. {
  7. if (argc <= 1) {
  8. fprintf(stderr,
  9. "No arguments provided. Example usage: ./inherit cmake --help");
  10. return EXIT_FAILURE;
  11. }
  12. reproc_t *process = NULL;
  13. int r = REPROC_ENOMEM;
  14. process = reproc_new();
  15. if (process == NULL) {
  16. goto finish;
  17. }
  18. r = reproc_start(process, argv + 1,
  19. (reproc_options){ .redirect.parent = true });
  20. if (r < 0) {
  21. goto finish;
  22. }
  23. r = reproc_wait(process, REPROC_INFINITE);
  24. if (r < 0) {
  25. goto finish;
  26. }
  27. finish:
  28. reproc_destroy(process);
  29. if (r < 0) {
  30. fprintf(stderr, "%s\n", reproc_strerror(r));
  31. }
  32. return abs(r);
  33. }