a0141f7e954bf69dcc6827a5b07e82ffb20b5bd7 — Drew DeVault 3 months ago c4de9e0
Pass environ into mrsh_populate_env
3 files changed, 5 insertions(+), 5 deletions(-)

M include/mrsh/entry.h
M main.c
M shell/entry.c
M include/mrsh/entry.h => include/mrsh/entry.h +1 -1
@@ 20,7 20,7 @@ * Copies variables from the environment and sets up internal variables like
   * IFS, PPID, PWD, etc.
   */
- bool mrsh_populate_env(struct mrsh_state *state);
+ bool mrsh_populate_env(struct mrsh_state *state, char **environ);
  
  /**
   * Sources /etc/profile and $HOME/.profile. Note that this behavior is not

M main.c => main.c +3 -1
@@ 14,6 14,8 @@ #include <unistd.h>
  #include "frontend.h"
  
+ extern char **environ;
+ 
  int main(int argc, char *argv[]) {
  	struct mrsh_state state = {0};
  	mrsh_state_init(&state);


@@ 24,7 26,7 @@ return EXIT_FAILURE;
  	}
  
- 	if (!mrsh_populate_env(&state)) {
+ 	if (!mrsh_populate_env(&state, environ)) {
  		return EXIT_FAILURE;
  	}
  

M shell/entry.c => shell/entry.c +1 -3
@@ 10,8 10,6 @@ #include <unistd.h>
  #include "builtin.h"
  
- extern char **environ;
- 
  static char *expand_ps(struct mrsh_state *state, const char *ps1) {
  	struct mrsh_parser *parser = mrsh_parser_with_data(ps1, strlen(ps1));
  	struct mrsh_word *word = mrsh_parse_word(parser);


@@ 43,7 41,7 @@ return strdup("> ");
  }
  
- bool mrsh_populate_env(struct mrsh_state *state) {
+ bool mrsh_populate_env(struct mrsh_state *state, char **environ) {
  	for (size_t i = 0; environ[i] != NULL; ++i) {
  		char *eql = strchr(environ[i], '=');
  		size_t klen = eql - environ[i];