public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] runner/executor: refactor error handling
@ 2019-03-20  9:33 Ser, Simon
  2019-03-20 10:19 ` Petri Latvala
  2019-03-20 13:47 ` Rhys Kidd
  0 siblings, 2 replies; 4+ messages in thread
From: Ser, Simon @ 2019-03-20  9:33 UTC (permalink / raw)
  To: igt-dev@lists.freedesktop.org

* Refactor to use goto error handling
* Make execute_test_process noreturn to remove uninitialized variable
  warning
* Check fork() return value

Signed-off-by: Simon Ser <simon.ser@intel.com>
---
 runner/executor.c | 63 ++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 31 deletions(-)

diff --git a/runner/executor.c b/runner/executor.c
index d535c276..6bf7ce1c 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -753,9 +753,10 @@ static int monitor_output(pid_t child,
 	return killed;
 }
 
-static void execute_test_process(int outfd, int errfd,
-				 struct settings *settings,
-				 struct job_list_entry *entry)
+static void __attribute__((noreturn))
+execute_test_process(int outfd, int errfd,
+		     struct settings *settings,
+		     struct job_list_entry *entry)
 {
 	char *argv[4] = {};
 	size_t rootlen;
@@ -884,9 +885,9 @@ static int execute_next_entry(struct execute_state
*state,
 	}
 
 	if (!open_output_files(dirfd, outputs, true)) {
-		close(dirfd);
 		fprintf(stderr, "Error opening output files\n");
-		return -1;
+		result = -1;
+		goto out_dirfd;
 	}
 
 	if (settings->sync) {
@@ -895,14 +896,9 @@ static int execute_next_entry(struct execute_state
*state,
 	}
 
 	if (pipe(outpipe) || pipe(errpipe)) {
-		close_outputs(outputs);
-		close(dirfd);
-		close(outpipe[0]);
-		close(outpipe[1]);
-		close(errpipe[0]);
-		close(errpipe[1]);
 		fprintf(stderr, "Error creating pipes: %s\n",
strerror(errno));
-		return -1;
+		result = -1;
+		goto out_pipe;
 	}
 
 	if ((kmsgfd = open("/dev/kmsg", O_RDONLY | O_CLOEXEC)) < 0) {
@@ -923,14 +919,8 @@ static int execute_next_entry(struct execute_state
*state,
 	if (sigfd < 0) {
 		/* TODO: Handle better */
 		fprintf(stderr, "Cannot monitor child process with
signalfd\n");
-		close(outpipe[0]);
-		close(errpipe[0]);
-		close(outpipe[1]);
-		close(errpipe[1]);
-		close(kmsgfd);
-		close_outputs(outputs);
-		close(dirfd);
-		return -1;
+		result = -1;
+		goto out_kmsgfd;
 	}
 
 	if (settings->log_level >= LOG_LEVEL_NORMAL) {
@@ -951,19 +941,15 @@ static int execute_next_entry(struct
execute_state *state,
 	 * Flush outputs before forking so our (buffered) output won't
 	 * end up in the test outputs.
 	 */
-
 	fflush(stdout);
 	fflush(stderr);
 
-	if ((child = fork())) {
-		int outfd = outpipe[0];
-		int errfd = errpipe[0];
-		close(outpipe[1]);
-		close(errpipe[1]);
-
-		result = monitor_output(child, outfd, errfd, kmsgfd,
sigfd,
-					outputs, time_spent, settings);
-	} else {
+	child = fork();
+	if (child < 0) {
+		fprintf(stderr, "Failed to fork()");
+		result = -1;
+		goto out_kmsgfd;
+	} else if (child == 0) {
 		int outfd = outpipe[1];
 		int errfd = errpipe[1];
 		close(outpipe[0]);
@@ -974,13 +960,28 @@ static int execute_next_entry(struct
execute_state *state,
 		setenv("IGT_SENTINEL_ON_STDERR", "1", 1);
 
 		execute_test_process(outfd, errfd, settings, entry);
+		/* unreachable */
 	}
 
-	/* TODO: Refactor this whole function to use onion teardown */
+	int outfd = outpipe[0];
+	int errfd = errpipe[0];
 	close(outpipe[1]);
 	close(errpipe[1]);
+	outpipe[1] = errpipe[1] = -1;
+
+	result = monitor_output(child, outfd, errfd, kmsgfd, sigfd,
+				outputs, time_spent, settings);
+
+out_kmsgfd:
 	close(kmsgfd);
+out_pipe:
+	close_outputs(outputs);
+	close(outpipe[0]);
+	close(outpipe[1]);
+	close(errpipe[0]);
+	close(errpipe[1]);
 	close_outputs(outputs);
+out_dirfd:
 	close(dirfd);
 
 	return result;
-- 
2.21.0

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] runner/executor: refactor error handling
  2019-03-20  9:33 [igt-dev] [PATCH i-g-t] runner/executor: refactor error handling Ser, Simon
@ 2019-03-20 10:19 ` Petri Latvala
  2019-03-20 13:47 ` Rhys Kidd
  1 sibling, 0 replies; 4+ messages in thread
From: Petri Latvala @ 2019-03-20 10:19 UTC (permalink / raw)
  To: Ser, Simon; +Cc: igt-dev@lists.freedesktop.org

On Wed, Mar 20, 2019 at 09:33:55AM +0000, Ser, Simon wrote:
> * Refactor to use goto error handling
> * Make execute_test_process noreturn to remove uninitialized variable
>   warning
> * Check fork() return value
> 
> Signed-off-by: Simon Ser <simon.ser@intel.com>
> ---
>  runner/executor.c | 63 ++++++++++++++++++++++++-----------------------
>  1 file changed, 32 insertions(+), 31 deletions(-)
> 
> diff --git a/runner/executor.c b/runner/executor.c
> index d535c276..6bf7ce1c 100644
> --- a/runner/executor.c
> +++ b/runner/executor.c
> @@ -753,9 +753,10 @@ static int monitor_output(pid_t child,
>  	return killed;
>  }
>  
> -static void execute_test_process(int outfd, int errfd,
> -				 struct settings *settings,
> -				 struct job_list_entry *entry)
> +static void __attribute__((noreturn))
> +execute_test_process(int outfd, int errfd,
> +		     struct settings *settings,
> +		     struct job_list_entry *entry)
>  {
>  	char *argv[4] = {};
>  	size_t rootlen;
> @@ -884,9 +885,9 @@ static int execute_next_entry(struct execute_state
> *state,
>  	}
>  
>  	if (!open_output_files(dirfd, outputs, true)) {
> -		close(dirfd);
>  		fprintf(stderr, "Error opening output files\n");
> -		return -1;
> +		result = -1;
> +		goto out_dirfd;
>  	}
>  
>  	if (settings->sync) {
> @@ -895,14 +896,9 @@ static int execute_next_entry(struct execute_state
> *state,
>  	}
>  
>  	if (pipe(outpipe) || pipe(errpipe)) {
> -		close_outputs(outputs);
> -		close(dirfd);
> -		close(outpipe[0]);
> -		close(outpipe[1]);
> -		close(errpipe[0]);
> -		close(errpipe[1]);
>  		fprintf(stderr, "Error creating pipes: %s\n",
> strerror(errno));
> -		return -1;
> +		result = -1;
> +		goto out_pipe;
>  	}
>  
>  	if ((kmsgfd = open("/dev/kmsg", O_RDONLY | O_CLOEXEC)) < 0) {
> @@ -923,14 +919,8 @@ static int execute_next_entry(struct execute_state
> *state,
>  	if (sigfd < 0) {
>  		/* TODO: Handle better */
>  		fprintf(stderr, "Cannot monitor child process with
> signalfd\n");
> -		close(outpipe[0]);
> -		close(errpipe[0]);
> -		close(outpipe[1]);
> -		close(errpipe[1]);
> -		close(kmsgfd);
> -		close_outputs(outputs);
> -		close(dirfd);
> -		return -1;
> +		result = -1;
> +		goto out_kmsgfd;
>  	}
>  
>  	if (settings->log_level >= LOG_LEVEL_NORMAL) {
> @@ -951,19 +941,15 @@ static int execute_next_entry(struct
> execute_state *state,
>  	 * Flush outputs before forking so our (buffered) output won't
>  	 * end up in the test outputs.
>  	 */
> -
>  	fflush(stdout);
>  	fflush(stderr);
>  
> -	if ((child = fork())) {
> -		int outfd = outpipe[0];
> -		int errfd = errpipe[0];
> -		close(outpipe[1]);
> -		close(errpipe[1]);
> -
> -		result = monitor_output(child, outfd, errfd, kmsgfd,
> sigfd,
> -					outputs, time_spent, settings);
> -	} else {
> +	child = fork();
> +	if (child < 0) {
> +		fprintf(stderr, "Failed to fork()");
> +		result = -1;
> +		goto out_kmsgfd;
> +	} else if (child == 0) {
>  		int outfd = outpipe[1];
>  		int errfd = errpipe[1];
>  		close(outpipe[0]);
> @@ -974,13 +960,28 @@ static int execute_next_entry(struct
> execute_state *state,
>  		setenv("IGT_SENTINEL_ON_STDERR", "1", 1);
>  
>  		execute_test_process(outfd, errfd, settings, entry);
> +		/* unreachable */
>  	}
>  
> -	/* TODO: Refactor this whole function to use onion teardown */
> +	int outfd = outpipe[0];
> +	int errfd = errpipe[0];

Try to keep variable declarations at the beginning of the block.


Otherwise LGTM,

Reviewed-by: Petri Latvala <petri.latvala@intel.com>
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] runner/executor: refactor error handling
  2019-03-20  9:33 [igt-dev] [PATCH i-g-t] runner/executor: refactor error handling Ser, Simon
  2019-03-20 10:19 ` Petri Latvala
@ 2019-03-20 13:47 ` Rhys Kidd
  2019-03-21  7:16   ` Ser, Simon
  1 sibling, 1 reply; 4+ messages in thread
From: Rhys Kidd @ 2019-03-20 13:47 UTC (permalink / raw)
  To: Ser, Simon; +Cc: igt-dev@lists.freedesktop.org


[-- Attachment #1.1: Type: text/plain, Size: 6277 bytes --]

On Wed, Mar 20, 2019 at 8:34 PM Ser, Simon <simon.ser@intel.com> wrote:

> * Refactor to use goto error handling
> * Make execute_test_process noreturn to remove uninitialized variable
>   warning
> * Check fork() return value
>
> Signed-off-by: Simon Ser <simon.ser@intel.com>
> ---
>  runner/executor.c | 63 ++++++++++++++++++++++++-----------------------
>  1 file changed, 32 insertions(+), 31 deletions(-)
>
> diff --git a/runner/executor.c b/runner/executor.c
> index d535c276..6bf7ce1c 100644
> --- a/runner/executor.c
> +++ b/runner/executor.c
> @@ -753,9 +753,10 @@ static int monitor_output(pid_t child,
>         return killed;
>  }
>
> -static void execute_test_process(int outfd, int errfd,
> -                                struct settings *settings,
> -                                struct job_list_entry *entry)
> +static void __attribute__((noreturn))
> +execute_test_process(int outfd, int errfd,
> +                    struct settings *settings,
> +                    struct job_list_entry *entry)
>  {
>         char *argv[4] = {};
>         size_t rootlen;
> @@ -884,9 +885,9 @@ static int execute_next_entry(struct execute_state
> *state,
>         }
>
>         if (!open_output_files(dirfd, outputs, true)) {
> -               close(dirfd);
>                 fprintf(stderr, "Error opening output files\n");
> -               return -1;
> +               result = -1;
> +               goto out_dirfd;
>         }
>
>         if (settings->sync) {
> @@ -895,14 +896,9 @@ static int execute_next_entry(struct execute_state
> *state,
>         }
>
>         if (pipe(outpipe) || pipe(errpipe)) {
> -               close_outputs(outputs);
> -               close(dirfd);
> -               close(outpipe[0]);
> -               close(outpipe[1]);
> -               close(errpipe[0]);
> -               close(errpipe[1]);
>                 fprintf(stderr, "Error creating pipes: %s\n",
> strerror(errno));
> -               return -1;
> +               result = -1;
> +               goto out_pipe;
>         }
>
>         if ((kmsgfd = open("/dev/kmsg", O_RDONLY | O_CLOEXEC)) < 0) {
> @@ -923,14 +919,8 @@ static int execute_next_entry(struct execute_state
> *state,
>         if (sigfd < 0) {
>                 /* TODO: Handle better */
>                 fprintf(stderr, "Cannot monitor child process with
> signalfd\n");
> -               close(outpipe[0]);
> -               close(errpipe[0]);
> -               close(outpipe[1]);
> -               close(errpipe[1]);
> -               close(kmsgfd);
> -               close_outputs(outputs);
> -               close(dirfd);
> -               return -1;
> +               result = -1;
> +               goto out_kmsgfd;
>         }
>
>         if (settings->log_level >= LOG_LEVEL_NORMAL) {
> @@ -951,19 +941,15 @@ static int execute_next_entry(struct
> execute_state *state,
>          * Flush outputs before forking so our (buffered) output won't
>          * end up in the test outputs.
>          */
> -
>         fflush(stdout);
>         fflush(stderr);
>
> -       if ((child = fork())) {
> -               int outfd = outpipe[0];
> -               int errfd = errpipe[0];
> -               close(outpipe[1]);
> -               close(errpipe[1]);
> -
> -               result = monitor_output(child, outfd, errfd, kmsgfd,
> sigfd,
> -                                       outputs, time_spent, settings);
> -       } else {
> +       child = fork();
> +       if (child < 0) {
> +               fprintf(stderr, "Failed to fork()");
> +               result = -1;
> +               goto out_kmsgfd;
> +       } else if (child == 0) {
>                 int outfd = outpipe[1];
>                 int errfd = errpipe[1];
>                 close(outpipe[0]);
> @@ -974,13 +960,28 @@ static int execute_next_entry(struct
> execute_state *state,
>                 setenv("IGT_SENTINEL_ON_STDERR", "1", 1);
>
>                 execute_test_process(outfd, errfd, settings, entry);
> +               /* unreachable */
>         }
>
> -       /* TODO: Refactor this whole function to use onion teardown */
> +       int outfd = outpipe[0];
> +       int errfd = errpipe[0];
>         close(outpipe[1]);
>         close(errpipe[1]);
> +       outpipe[1] = errpipe[1] = -1;
> +
> +       result = monitor_output(child, outfd, errfd, kmsgfd, sigfd,
> +                               outputs, time_spent, settings);
> +
> +out_kmsgfd:
>         close(kmsgfd);
> +out_pipe:
> +       close_outputs(outputs);
> +       close(outpipe[0]);
> +       close(outpipe[1]);
> +       close(errpipe[0]);
> +       close(errpipe[1]);
>         close_outputs(outputs);
> +out_dirfd:
>         close(dirfd);
>
>         return result;
> --
> 2.21.0
>
> ---------------------------------------------------------------------
> Intel Finland Oy
> Registered Address: PL 281, 00181 Helsinki
> Business Identity Code: 0357606 - 4
> Domiciled in Helsinki
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.


Hello Simon,

Welcome to igt.

The above corporate boilerplate text should be removed from emails to
public mailing lists, and definitely from emails with code that you are
distributing under the MIT License.

I expect that you didn’t really intend for that paragraph to apply to your
patch - but in particular the restrictions on distribution by others is
problematic.

https://gitlab.freedesktop.org/drm/igt-gpu-tools/blob/master/CONTRIBUTING.md

You can read further there on the Developer’s Certificate of Origin that
igt adopts and what it entails, which I understand is what you intended to
use instead of this boilerplate.

Other Intel contributors might be able to assist you with whatever internal
corporate proxy changes you need to make.


> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

[-- Attachment #1.2: Type: text/html, Size: 8244 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] runner/executor: refactor error handling
  2019-03-20 13:47 ` Rhys Kidd
@ 2019-03-21  7:16   ` Ser, Simon
  0 siblings, 0 replies; 4+ messages in thread
From: Ser, Simon @ 2019-03-21  7:16 UTC (permalink / raw)
  To: rhyskidd@gmail.com; +Cc: igt-dev@lists.freedesktop.org

On Thu, 2019-03-21 at 00:47 +1100, Rhys Kidd wrote:
> > Intel Finland Oy
> > Registered Address: PL 281, 00181 Helsinki 
> > Business Identity Code: 0357606 - 4 
> > Domiciled in Helsinki 
> > 
> > This e-mail and any attachments may contain confidential material
> > for
> > the sole use of the intended recipient(s). Any review or
> > distribution
> > by others is strictly prohibited. If you are not the intended
> > recipient, please contact the sender and delete all copies.
> 
> Hello Simon,
> 
> Welcome to igt.
>
> The above corporate boilerplate text should be removed from emails to
> public mailing lists, and definitely from emails with code that you
> are distributing under the MIT License.
> 
> I expect that you didn’t really intend for that paragraph to apply to
> your patch - but in particular the restrictions on distribution by
> others is problematic.
> 
> https://gitlab.freedesktop.org/drm/igt-gpu-tools/blob/master/CONTRIBUTING.md
> 
> You can read further there on the Developer’s Certificate of Origin
> that igt adopts and what it entails, which I understand is what you
> intended to use instead of this boilerplate.
> 
> Other Intel contributors might be able to assist you with whatever
> internal corporate proxy changes you need to make.

Hi,

Indeed, this disclaimer needs to go away. I've already taken action to
remove it, but it takes some time. Hopefully I'll soon be able to send
e-mails without it. In the meantime, we can hold off merging patches if
it causes legal issues (reviews still welcome!). I can re-send patches
without the disclaimer once it gets removed from my outgoing e-mails.

Thanks!
---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-21  7:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-20  9:33 [igt-dev] [PATCH i-g-t] runner/executor: refactor error handling Ser, Simon
2019-03-20 10:19 ` Petri Latvala
2019-03-20 13:47 ` Rhys Kidd
2019-03-21  7:16   ` Ser, Simon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox