From: Jan Kiszka <jan.kiszka@siemens.com>
To: Fabian Scheler <Fabian.Scheler@siemens.com>, xenomai@lists.linux.dev
Subject: Re: [PATCH v2] testsuite/smokey/gdb: Fix race-condition
Date: Wed, 20 Mar 2024 08:40:41 +0100 [thread overview]
Message-ID: <62f6cf88-2aac-4300-8e9e-b868c42ebbf6@siemens.com> (raw)
In-Reply-To: <20240314134411.28121-2-Fabian.Scheler@siemens.com>
On 14.03.24 14:44, Fabian Scheler wrote:
> When quitting gdb by sending the quit-command, gdb may actually finish before
> the father-process calls pause. In that case the father-process would wait
> endlessly.
>
> The fix now uses waitpid instead of pause to explicitly wait for the
> child-process, in contrast to pause waitpid also handles child-processes that
> already have been terminated.
>
> Signed-off-by: Fabian Scheler <Fabian.Scheler@siemens.com>
> ---
> testsuite/smokey/gdb/gdb.c | 23 +++++++++++++++--------
> 1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/testsuite/smokey/gdb/gdb.c b/testsuite/smokey/gdb/gdb.c
> index b09b78b4e..1daa7ee4c 100644
> --- a/testsuite/smokey/gdb/gdb.c
> +++ b/testsuite/smokey/gdb/gdb.c
> @@ -78,7 +78,7 @@ static void handle_sigchld(int signum)
> if (WEXITSTATUS(status) == ESRCH)
> smokey_note("gdb: skipped (gdb not available)");
> else
> - check("gdb execution", WEXITSTATUS(status), 0);
> + check("gdb terminated unexpectedly", 0, 1);
> child_terminated = 1;
> close(pipe_out[0]);
> }
> @@ -202,6 +202,8 @@ static int run_gdb(struct smokey_test *t, int argc, char *const argv[])
> pthread_attr_t attr;
> char run_param[32];
> cpu_set_t cpu_set;
> + pid_t childpid;
> + int status;
> int err;
>
> smokey_parse_args(t, argc, argv);
> @@ -257,7 +259,8 @@ static int run_gdb(struct smokey_test *t, int argc, char *const argv[])
> err = pipe(pipe_out);
> check_no_error("pipe_out", err);
>
> - switch (do_fork()) {
> + childpid = do_fork();
> + switch (childpid) {
> case -1:
> error(1, errno, "fork/vfork");
>
> @@ -283,8 +286,14 @@ static int run_gdb(struct smokey_test *t, int argc, char *const argv[])
>
> default:
> wait_for_pattern("(gdb) ");
> +
> + /* the signal handler only is used to skip the test if
> + gdb is missing */
> if (child_terminated)
> break;
> + else
> + signal(SIGCHLD, SIG_DFL);
> +
> send_command("b breakpoint_target\n", 1);
> send_command("r\n", 1);
>
> @@ -301,13 +310,11 @@ static int run_gdb(struct smokey_test *t, int argc, char *const argv[])
> eval_expression("thread_loops==expected_loops", "1");
>
> send_command("q\n", 0);
> - pause();
>
> - if (!child_terminated) {
> - fprintf(stderr,
> - "FAILURE: gdb still running?!\n");
> - exit(1);
> - }
> + err = waitpid(childpid, &status, 0);
> + check("waitpid", err, childpid);
> + check("gdb execution", WEXITSTATUS(status), 0);
> + close(pipe_out[0]);
> }
>
> signal(SIGCHLD, SIG_DFL);
Thanks, applied.
Jan
--
Siemens AG, Technology
Linux Expert Center
prev parent reply other threads:[~2024-03-20 7:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 6:38 [PATCH] testsuite/smokey/gdb: Fix race-condition Fabian Scheler
2024-03-12 7:48 ` Florian Bezdeka
2024-03-12 7:59 ` Scheler, Fabian (T CED SES-DE)
2024-03-12 7:49 ` Jan Kiszka
2024-03-12 8:15 ` Scheler, Fabian (T CED SES-DE)
2024-03-14 13:44 ` [PATCH v2] " Fabian Scheler
2024-03-20 7:40 ` Jan Kiszka [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=62f6cf88-2aac-4300-8e9e-b868c42ebbf6@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=Fabian.Scheler@siemens.com \
--cc=xenomai@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).