threads / patch / 40075

patchrun-command: Improve readability of struct child_process

Subject: [PATCH] run-command: Improve readability of struct child_process

## tl;dr

One message between Aug 12, 2015 and Aug 12, 2015. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Stefan Beller· Aug 12, 2015, 21:50 UTC · lore

Reordering the struct member env to be next to env_array helps understanding the struct better.

This also adds comments to indicate that arg{s,v} and (env, env_array) are used for the same purpose and only one must be used. Although these comments are in the Documentation, I still think they are a good idea in the code here as well.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to run-command.h +3 −3
diff --git a/run-command.h b/run-command.h
index 1103805..e67395d 100644
--- a/run-command.h
+++ b/run-command.h
@@ -8,8 +8,9 @@
 #include "argv-array.h"
 
 struct child_process {
-	const char **argv;
+	const char **argv; /* Use only one of arg{v,s} */
 	struct argv_array args;
+	const char *const *env; /* Use only one of (env, env_array) */
 	struct argv_array env_array;
 	pid_t pid;
 	/*
@@ -34,7 +35,6 @@ struct child_process {
 	int out;
 	int err;
 	const char *dir;
-	const char *const *env;
 	unsigned no_stdin:1;
 	unsigned no_stdout:1;
 	unsigned no_stderr:1;
@@ -45,7 +45,7 @@ struct child_process {
 	unsigned clean_on_exit:1;
 };
 
-#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT, ARGV_ARRAY_INIT }
+#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT, NULL, ARGV_ARRAY_INIT }
 void child_process_init(struct child_process *);
 
 int start_command(struct child_process *);
-- 
2.5.0.234.gefc8a62

← back to recent threads