diff options
Diffstat (limited to 'tests/attach-p-cmd-cmd.c')
-rw-r--r-- | tests/attach-p-cmd-cmd.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/tests/attach-p-cmd-cmd.c b/tests/attach-p-cmd-cmd.c index d0f824e9..70e3a2de 100644 --- a/tests/attach-p-cmd-cmd.c +++ b/tests/attach-p-cmd-cmd.c @@ -1,7 +1,7 @@ /* * This file is part of attach-p-cmd strace test. * - * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org> + * Copyright (c) 2016-2017 Dmitry V. Levin <ldv@altlinux.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,19 +32,41 @@ #include <stdio.h> #include <sys/stat.h> #include <unistd.h> +#include "attach-p-cmd.h" -int -main(void) +static void +write_pidfile(const pid_t pid) +{ + FILE *fp = fopen(pidfile, "w"); + if (!fp) + perror_msg_and_fail("fopen: %s", pidfile); + + if (fprintf(fp, "%d", pid) < 0) + perror_msg_and_fail("fprintf: %s", pidfile); + + if (fclose(fp)) + perror_msg_and_fail("fclose: %s", pidfile); +} + +static void +wait_for_peer_invocation(void) { - static const char lockdir[] = "attach-p-cmd.test-lock"; /* wait for the lock directory to be created by peer */ while (rmdir(lockdir)) { if (ENOENT != errno) perror_msg_and_fail("rmdir: %s", lockdir); } +} + +int +main(void) +{ + const pid_t pid = getpid(); + write_pidfile(pid); + + wait_for_peer_invocation(); static const char dir[] = "attach-p-cmd.test cmd"; - pid_t pid = getpid(); int rc = chdir(dir); printf("%-5d chdir(\"%s\") = %s\n" |