1 /*
2 * This file is part of strace-p-Y-p strace test.
3 *
4 * Copyright (c) 2021 Dmitry V. Levin <ldv@strace.io>
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 #ifndef MY_COMM
16 # define MY_COMM "strace-p1-Y-p"
17 #endif
18
19 int
20 main(int ac, char **av)
21 {
22 if (ac < 2)
23 error_msg_and_fail("missing operand");
24
25 if (ac > 2)
26 error_msg_and_fail("extra operand");
27
28 static const char proc_self_comm[] = "/proc/self/comm";
29 skip_if_unavailable(proc_self_comm);
30
31 int seconds = atoi(av[1]);
32 FILE *fp = fdopen(3, "a");
33 if (!fp)
34 error_msg_and_fail("fdopen(3, \"a\")");
35
36 fprintf(fp, "%u<%s> +++ exited with 0 +++\n", getpid(), MY_COMM);
37 fclose(fp);
38
39 if (sleep(seconds))
40 perror_msg_and_skip("sleep: %d", seconds);
41
42 return 0;
43 }