2 * This file is part of attach-p-cmd strace test.
4 * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "attach-p-cmd.h"
18 write_pidfile(const pid_t pid)
20 FILE *fp = fopen(pidfile, "w");
22 perror_msg_and_fail("fopen: %s", pidfile);
24 if (fprintf(fp, "%d", pid) < 0)
25 perror_msg_and_fail("fprintf: %s", pidfile);
28 perror_msg_and_fail("fclose: %s", pidfile);
32 wait_for_peer_invocation(void)
34 /* wait for the lock directory to be created by peer */
35 while (rmdir(lockdir)) {
37 perror_msg_and_fail("rmdir: %s", lockdir);
44 const pid_t pid = getpid();
47 wait_for_peer_invocation();
49 static const char dir[] = "attach-p-cmd.test cmd";
52 printf("%-5d chdir(\"%s\") = %s\n"
53 "%-5d +++ exited with 0 +++\n",
54 pid, dir, sprintrc(rc), pid);