summaryrefslogtreecommitdiff
path: root/function.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>1993-07-15 00:22:55 +0000
committerRoland McGrath <roland@redhat.com>1993-07-15 00:22:55 +0000
commitca3b88c66a6be3cbb34fd81271ed39908d6bedfc (patch)
treefe6921ba64930ab960a04878b48701efbf168eab /function.c
parentf7f63b75b55856c61f21006a5dacc6c093c1e5ef (diff)
downloadmake-ca3b88c66a6be3cbb34fd81271ed39908d6bedfc.tar.gz
Formerly function.c.~28~
Diffstat (limited to 'function.c')
-rw-r--r--function.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/function.c b/function.c
index 5109203..c918ec9 100644
--- a/function.c
+++ b/function.c
@@ -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);
}