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