git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/7] run_command: report system call errors instead of returning error codes

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Jul 6, 2009, 07:37 UTC
Message-ID
<4A51A9BF.5050104@viscovery.net>
In-Reply-To
<ea2d8110ea70b8698bb3674ca4482db64053d841.1246734159.git.j6t@kdbg.org>
Johannes Sixt schrieb:
Show 25 quoted lines
>  	cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env);
> +	if (cmd->pid < 0 && errno != ENOENT)
> +		error("cannot spawn %s: %s", cmd->argv[0],
> +			strerror(failed_errno = errno));
>  
>  	if (cmd->env)
>  		free_environ(env);
> @@ -189,7 +203,6 @@ int start_command(struct child_process *cmd)
>  #endif
>  
>  	if (cmd->pid < 0) {
> -		int err = errno;
>  		if (need_in)
>  			close_pair(fdin);
>  		else if (cmd->in)
> @@ -200,9 +213,8 @@ int start_command(struct child_process *cmd)
>  			close(cmd->out);
>  		if (need_err)
>  			close_pair(fderr);
> -		return err == ENOENT ?
> -			-ERR_RUN_COMMAND_EXEC :
> -			-ERR_RUN_COMMAND_FORK;
> +		errno = failed_errno;
> +		return -1;
>  	}

Sorry to bother you once again. 'gcc -O2' correctly points out that failed_errno could be used uninitialized (MinGW code path only). Would you please squash this in?

-- Hannes
diff --git a/run-command.c b/run-command.c
--- a/run-command.c
+++ b/run-command.c
@@ -184,9 +184,9 @@ fail_pipe:
 	}

 	cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env);
+	failed_errno = errno;
 	if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))
-		error("cannot spawn %s: %s", cmd->argv[0],
-			strerror(failed_errno = errno));
+		error("cannot spawn %s: %s", cmd->argv[0], strerror(errno));

 	if (cmd->env)
 		free_environ(env);
Previous: Junio C HamanoNext: Johannes Sixt
Message 11 of 12 in “rework run_command error reporting”
  1. 0/7 rework run_command error reportingJohannes Sixt, Jul 4, 2009
  2. 1/7 Truncate result of run_command that is used in exit() to lowest 8 bitsJohannes Sixt, Jul 4, 2009
  3. 2/7 MinGW: simplify waitpid() emulation macrosJohannes Sixt, Jul 4, 2009
  4. 3/7 run_command: return exit code as positive valueJohannes Sixt, Jul 4, 2009
  5. 4/7 run_command: report system call errors instead of returning error codesJohannes Sixt, Jul 4, 2009
  6. 5/7 run_command: encode deadly signal number in the return valueJohannes Sixt, Jul 4, 2009
  7. 6/7 run_command: report failure to execute the program, but optionally don'tJohannes Sixt, Jul 4, 2009
  8. 7/7 receive-pack: remove unnecessary run_status reportJohannes Sixt, Jul 4, 2009
  9. Johannes SixtJul 5, 2009
  10. Junio C HamanoJul 5, 2009
  11. Johannes SixtJul 6, 2009
  12. 1/7 MinGW: truncate exit()'s argument to lowest 8 bitsJohannes Sixt, Jul 5, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.