From: Petri Latvala <petri.latvala@intel.com>
To: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 2/9] lib/tests: Add support for redirecting fork output to /dev/null
Date: Fri, 14 Feb 2020 14:01:20 +0200 [thread overview]
Message-ID: <20200214120120.GX25209@platvala-desk.ger.corp.intel.com> (raw)
In-Reply-To: <20200212132123.108506-3-arkadiusz.hiler@intel.com>
On Wed, Feb 12, 2020 at 03:21:16PM +0200, Arkadiusz Hiler wrote:
> Trying to read interleaved writes is a bit tricky, so let's just use
> /dev/null if we care about contents on only one of those pipes.
>
> Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Reviewed-by: Petri Latvala <petri.latvala@intel.com>
> ---
> lib/tests/igt_tests_common.h | 35 +++++++++++++++++++++++++++--------
> 1 file changed, 27 insertions(+), 8 deletions(-)
>
> diff --git a/lib/tests/igt_tests_common.h b/lib/tests/igt_tests_common.h
> index b3da3b34..f285d657 100644
> --- a/lib/tests/igt_tests_common.h
> +++ b/lib/tests/igt_tests_common.h
> @@ -28,6 +28,8 @@
> #include <assert.h>
> #include <sys/wait.h>
> #include <errno.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
>
> /*
> * We need to hide assert from the cocci igt test refactor spatch.
> @@ -72,19 +74,32 @@ static inline pid_t do_fork_bg_with_pipes(void (*test_to_run)(void), int *out, i
> int outfd[2], errfd[2];
> pid_t pid;
>
> - internal_assert(pipe(outfd) != -1);
> - internal_assert(pipe(errfd) != -1);
> + if (out != NULL)
> + internal_assert(pipe(outfd) != -1);
> +
> + if (err != NULL)
> + internal_assert(pipe(errfd) != -1);
>
> pid = fork();
> internal_assert(pid != -1);
>
> if (pid == 0) {
> + /* we'll leak the /dev/null fds, let them die with the forked
> + * process, also close reading ends if they are any */
> + if (out == NULL)
> + outfd[1] = open("/dev/null", O_WRONLY);
> + else
> + close(outfd[0]);
> +
> + if (err == NULL)
> + errfd[1] = open("/dev/null", O_WRONLY);
> + else
> + close(errfd[0]);
> +
> while (dup2(outfd[1], STDOUT_FILENO) == -1 && errno == EINTR) {}
> while (dup2(errfd[1], STDERR_FILENO) == -1 && errno == EINTR) {}
>
> - close(outfd[0]);
> close(outfd[1]);
> - close(errfd[0]);
> close(errfd[1]);
>
> test_to_run();
> @@ -92,11 +107,15 @@ static inline pid_t do_fork_bg_with_pipes(void (*test_to_run)(void), int *out, i
> exit(-1);
> } else {
> /* close the writing ends */
> - close(outfd[1]);
> - close(errfd[1]);
> + if (out != NULL) {
> + close(outfd[1]);
> + *out = outfd[0];
> + }
>
> - *out = outfd[0];
> - *err = errfd[0];
> + if (err != NULL) {
> + close(errfd[1]);
> + *err = errfd[0];
> + }
>
> return pid;
> }
> --
> 2.24.1
>
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2020-02-14 12:01 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-12 13:21 [igt-dev] [PATCH i-g-t 0/9] Abort on Chamelium failure Arkadiusz Hiler
2020-02-12 13:21 ` [igt-dev] [PATCH i-g-t 1/9] lib/tests: Extract fork helpers Arkadiusz Hiler
2020-02-14 11:57 ` Petri Latvala
2020-02-12 13:21 ` [igt-dev] [PATCH i-g-t 2/9] lib/tests: Add support for redirecting fork output to /dev/null Arkadiusz Hiler
2020-02-14 12:01 ` Petri Latvala [this message]
2020-02-12 13:21 ` [igt-dev] [PATCH i-g-t 3/9] lib: Make it possible to abort the whole execution from inside of a test Arkadiusz Hiler
2020-02-14 12:04 ` Petri Latvala
2020-02-12 13:21 ` [igt-dev] [PATCH i-g-t 4/9] runner/runner_tests: Extract helper for inspecting test result Arkadiusz Hiler
2020-02-12 13:37 ` Petri Latvala
2020-02-12 13:42 ` Petri Latvala
2020-02-12 13:59 ` Arkadiusz Hiler
2020-02-14 12:05 ` Petri Latvala
2020-02-12 13:22 ` [igt-dev] [PATCH i-g-t 5/9] runner: Abort the run when test exits with IGT_EXIT_ABORT Arkadiusz Hiler
2020-02-14 12:16 ` Petri Latvala
2020-02-12 13:22 ` [igt-dev] [PATCH i-g-t 6/9] lib/chamelium: Clear error after checking if chamelium is reachable Arkadiusz Hiler
2020-02-14 12:17 ` Petri Latvala
2020-02-12 13:23 ` [igt-dev] [PATCH i-g-t 7/9] lib/chamelium: Make it clear that function asserts Arkadiusz Hiler
2020-02-14 12:19 ` Petri Latvala
2020-02-17 13:45 ` Arkadiusz Hiler
2020-02-17 14:00 ` Petri Latvala
2020-02-17 14:11 ` Arkadiusz Hiler
2020-02-17 14:13 ` Petri Latvala
2020-02-12 13:23 ` [igt-dev] [PATCH i-g-t 8/9] lib/chamelium: Add functions to initialize XMLRPC only Arkadiusz Hiler
2020-02-14 12:22 ` Petri Latvala
2020-02-12 13:23 ` [igt-dev] [PATCH i-g-t 9/9] lib/kms: Try to plug all Chamelium ports, abort if it fails Arkadiusz Hiler
2020-02-14 12:27 ` Petri Latvala
2020-02-12 16:38 ` [igt-dev] ✓ Fi.CI.BAT: success for Abort on Chamelium failure Patchwork
2020-02-14 15:37 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2020-02-25 16:52 [igt-dev] [PATCH i-g-t 1/9] lib/tests: Extract fork helpers Arkadiusz Hiler
2020-02-25 16:52 ` [igt-dev] [PATCH i-g-t 2/9] lib/tests: Add support for redirecting fork output to /dev/null Arkadiusz Hiler
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=20200214120120.GX25209@platvala-desk.ger.corp.intel.com \
--to=petri.latvala@intel.com \
--cc=arkadiusz.hiler@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/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