File Index
Files and directories
Sign in
FILE

wait-pipe.c

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/landlock/wait-pipe.c C
 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
10#define _GNU_SOURCE
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14
15int main(int argc, char *argv[])
16{
17	int pipe_child, pipe_parent;
18	char buf;
19
20	/* The first argument must be the file descriptor number of a pipe. */
21	if (argc != 3) {
22		fprintf(stderr, "Wrong number of arguments (not two)\n");
23		return 1;
24	}
25
26	pipe_child = atoi(argv[1]);
27	pipe_parent = atoi(argv[2]);
28
29	/* Signals that we are waiting. */
30	if (write(pipe_child, ".", 1) != 1) {
31		perror("Failed to write to first argument");
32		return 1;
33	}
34
35	/* Waits for the parent do its test. */
36	if (read(pipe_parent, &buf, 1) != 1) {
37		perror("Failed to write to the second argument");
38		return 1;
39	}
40
41	return 0;
42}
~/ Read-only file preview.