Formerly function.c.~28~

This commit is contained in:
Roland McGrath 1993-07-15 00:22:55 +00:00
parent f7f63b75b5
commit ca3b88c66a

View file

@ -324,7 +324,7 @@ expand_function (o, function, text, end)
case function_shell:
{
char **argv;
char **argv, **envp;
char *error_prefix;
int pipedes[2];
int pid;
@ -337,6 +337,9 @@ expand_function (o, function, text, end)
if (argv == 0)
break;
/* Construct the environment. */
envp = target_environment ((struct file *) 0);
/* For error messages. */
if (reading_filename != 0)
{
@ -357,18 +360,32 @@ expand_function (o, function, text, end)
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]);
@ -433,8 +450,6 @@ expand_function (o, function, text, end)
}
}
free (argv[0]);
free ((char *) argv);
free (buffer);
}