wait-pipe.c 861 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Write in a pipe and wait.
  4. *
  5. * Used by layout1.umount_sandboxer from fs_test.c
  6. *
  7. * Copyright © 2024-2025 Microsoft Corporation
  8. */
  9. #define _GNU_SOURCE
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. int main(int argc, char *argv[])
  14. {
  15. int pipe_child, pipe_parent;
  16. char buf;
  17. /* The first argument must be the file descriptor number of a pipe. */
  18. if (argc != 3) {
  19. fprintf(stderr, "Wrong number of arguments (not two)\n");
  20. return 1;
  21. }
  22. pipe_child = atoi(argv[1]);
  23. pipe_parent = atoi(argv[2]);
  24. /* Signals that we are waiting. */
  25. if (write(pipe_child, ".", 1) != 1) {
  26. perror("Failed to write to first argument");
  27. return 1;
  28. }
  29. /* Waits for the parent do its test. */
  30. if (read(pipe_parent, &buf, 1) != 1) {
  31. perror("Failed to write to the second argument");
  32. return 1;
  33. }
  34. return 0;
  35. }