case function_shell:
{
- char **argv;
+ char **argv, **envp;
char *error_prefix;
int pipedes[2];
int pid;
if (argv == 0)
break;
+ /* Construct the environment. */
+ envp = target_environment ((struct file *) 0);
+
/* For error messages. */
if (reading_filename != 0)
{
if (pid < 0)
perror_with_name (error_prefix, "fork");
else if (pid == 0)
- child_execute_job (0, pipedes[1], argv, environ);
+ child_execute_job (0, pipedes[1], argv, envp);
else
{
- /* We are the parent. Set up and read from the pipe. */
- char *buffer = (char *) xmalloc (201);
- unsigned int maxlen = 200;
+ /* We are the parent. */
+
+ char *buffer;
+ unsigned int maxlen;
int cc;
- /* Record the PID for child_handler. */
+ /* Free the storage only the child needed. */
+ free (argv[0]);
+ free ((char *) argv);
+ for (i = 0; envp[i] != 0; ++i)
+ free (envp[i]);
+ free ((char *) envp);
+
+ /* Record the PID for reap_children. */
shell_function_pid = pid;
shell_function_completed = 0;
+
+ /* Set up and read from the pipe. */
+
+ maxlen = 200;
+ buffer = (char *) xmalloc (maxlen + 1);
+
/* Close the write side of the pipe. */
(void) close (pipedes[1]);
}
}
- free (argv[0]);
- free ((char *) argv);
free (buffer);
}