bug-regex21 bug-regex22 bug-regex23 bug-regex24 \
bug-regex25 bug-regex26 tst-nice tst-nanosleep tst-regex2 \
transbug tst-rxspencer tst-pcre tst-boost \
- bug-ga1 tst-vfork1 tst-vfork2 tst-waitid \
+ bug-ga1 tst-vfork1 tst-vfork2 tst-vfork3 tst-waitid \
tst-getaddrinfo2 bug-glob1 bug-glob2 tst-sysconf \
tst-execvp1 tst-execvp2 tst-execlp1 tst-execlp2 \
tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
bug-regex21-mem bug-regex21.mtrace \
tst-rxspencer-mem tst-rxspencer.mtrace tst-getconf.out \
tst-pcre-mem tst-pcre.mtrace tst-boost-mem tst-boost.mtrace \
- bug-ga2.mtrace bug-ga2-mem bug-glob2.mtrace bug-glob2-mem
+ bug-ga2.mtrace bug-ga2-mem bug-glob2.mtrace bug-glob2-mem \
+ tst-vfork3-mem tst-vfork3.mtrace
include ../Rules
tst-spawn-ARGS = -- $(built-program-cmd)
tst-dir-ARGS = `pwd` `cd $(common-objdir)/$(subdir); pwd` `cd $(common-objdir); pwd` $(objpfx)tst-dir
tst-chmod-ARGS = `pwd`
+tst-vfork3-ARGS = --test-dir=$(objpfx)
tst-fnmatch-ENV = LOCPATH=$(common-objpfx)localedata
tst-regexloc-ENV = LOCPATH=$(common-objpfx)localedata
tests: $(objpfx)bug-regex2-mem $(objpfx)bug-regex14-mem \
$(objpfx)bug-regex21-mem $(objpfx)tst-rxspencer-mem \
$(objpfx)tst-pcre-mem $(objpfx)tst-boost-mem $(objpfx)tst-getconf.out \
- $(objpfx)bug-glob2-mem
+ $(objpfx)bug-glob2-mem $(objpfx)tst-vfork3-mem
xtests: $(objpfx)bug-ga2-mem
endif
$(objpfx)bug-regex21-mem: $(objpfx)bug-regex21.out
$(common-objpfx)malloc/mtrace $(objpfx)bug-regex21.mtrace > $@
+tst-vfork3-ENV = MALLOC_TRACE=$(objpfx)tst-vfork3.mtrace
+
+$(objpfx)tst-vfork3-mem: $(objpfx)tst-vfork3.out
+ $(common-objpfx)malloc/mtrace $(objpfx)tst-vfork3.mtrace > $@
+
# tst-rxspencer.mtrace is generated only when run without --utf8
# option, since otherwise the file has almost 100M and takes very long
# time to process.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <alloca.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdbool.h>
/* The file is accessible but it is not an executable file. Invoke
the shell to interpret it as a script. */
-static char **
+static void
internal_function
-allocate_scripts_argv (const char *file, char *const argv[])
+scripts_argv (const char *file, char *const argv[], int argc, char **new_argv)
{
- /* Count the arguments. */
- int argc = 0;
- while (argv[argc++])
- ;
-
/* Construct an argument list for the shell. */
- char **new_argv = (char **) malloc ((argc + 1) * sizeof (char *));
- if (new_argv != NULL)
+ new_argv[0] = (char *) _PATH_BSHELL;
+ new_argv[1] = (char *) file;
+ while (argc > 1)
{
- new_argv[0] = (char *) _PATH_BSHELL;
- new_argv[1] = (char *) file;
- while (argc > 1)
- {
- new_argv[argc] = argv[argc - 1];
- --argc;
- }
+ new_argv[argc] = argv[argc - 1];
+ --argc;
}
-
- return new_argv;
}
return -1;
}
- char **script_argv = NULL;
-
if (strchr (file, '/') != NULL)
{
/* Don't search when it contains a slash. */
if (errno == ENOEXEC)
{
- script_argv = allocate_scripts_argv (file, argv);
+ /* Count the arguments. */
+ int argc = 0;
+ while (argv[argc++])
+ ;
+ size_t len = (argc + 1) * sizeof (char *);
+ char **script_argv;
+ void *ptr = NULL;
+ if (__libc_use_alloca (len))
+ script_argv = alloca (len);
+ else
+ script_argv = ptr = malloc (len);
+
if (script_argv != NULL)
{
+ scripts_argv (file, argv, argc, script_argv);
__execve (script_argv[0], script_argv, __environ);
- free (script_argv);
+ free (ptr);
}
}
}
else
{
+ size_t pathlen;
+ size_t alloclen = 0;
char *path = getenv ("PATH");
+ if (path == NULL)
+ {
+ pathlen = confstr (_CS_PATH, (char *) NULL, 0);
+ alloclen = pathlen + 1;
+ }
+ else
+ pathlen = strlen (path);
+
+ size_t len = strlen (file) + 1;
+ alloclen += pathlen + len + 1;
+
+ char *name;
char *path_malloc = NULL;
+ if (__libc_use_alloca (alloclen))
+ name = alloca (alloclen);
+ else
+ {
+ path_malloc = name = malloc (alloclen);
+ if (name == NULL)
+ return -1;
+ }
+
if (path == NULL)
{
/* There is no `PATH' in the environment.
The default search path is the current directory
followed by the path `confstr' returns for `_CS_PATH'. */
- size_t len = confstr (_CS_PATH, (char *) NULL, 0);
- path = (char *) malloc (1 + len);
- if (path == NULL)
- return -1;
+ path = name + pathlen + len + 1;
path[0] = ':';
- (void) confstr (_CS_PATH, path + 1, len);
- path_malloc = path;
+ (void) confstr (_CS_PATH, path + 1, pathlen);
}
- size_t len = strlen (file) + 1;
- size_t pathlen = strlen (path);
- char *name = malloc (pathlen + len + 1);
- if (name == NULL)
- {
- free (path_malloc);
- return -1;
- }
/* Copy the file name at the top. */
name = (char *) memcpy (name + pathlen + 1, file, len);
/* And add the slash. */
*--name = '/';
+ char **script_argv = NULL;
+ void *script_argv_malloc = NULL;
bool got_eacces = false;
char *p = path;
do
{
if (script_argv == NULL)
{
- script_argv = allocate_scripts_argv (startp, argv);
+ /* Count the arguments. */
+ int argc = 0;
+ while (argv[argc++])
+ ;
+ size_t arglen = (argc + 1) * sizeof (char *);
+ if (__libc_use_alloca (alloclen + arglen))
+ script_argv = alloca (arglen);
+ else
+ script_argv = script_argv_malloc = malloc (arglen);
if (script_argv == NULL)
{
/* A possible EACCES error is not as important as
got_eacces = false;
break;
}
+ scripts_argv (startp, argv, argc, script_argv);
}
__execve (script_argv[0], script_argv, __environ);
/* We tried every element and none of them worked. */
if (got_eacces)
/* At least one failure was due to permissions, so report that
- error. */
+ error. */
__set_errno (EACCES);
- free (script_argv);
- free (name - pathlen);
+ free (script_argv_malloc);
free (path_malloc);
}