summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/spawn.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-10-09 04:08:05 +0000
committerChristopher Faylor <me@cgf.cx>2002-10-09 04:08:05 +0000
commit7da53596cf1385616721180b48b2159802045d1c (patch)
tree7c7c049a2429b3d778f4d8f33ede670f44fb7d58 /winsup/cygwin/spawn.cc
parentce6ac4003f2155c0f76d086673aa12193661e1c3 (diff)
downloadcygnal-7da53596cf1385616721180b48b2159802045d1c.tar.gz
cygnal-7da53596cf1385616721180b48b2159802045d1c.tar.bz2
cygnal-7da53596cf1385616721180b48b2159802045d1c.zip
* cygheap.cc (dup_now): Make fatal error a little more informative.
(cygheap_setup_for_child): Detect when default size of shared region is less than the current size and allocate that much. (_cbrk): Just return NULL on inability to allocate. (_cmalloc): Ditto. * cygheap.h (CYGHEAPSIZE): Change size to reflect newer, tinier fhandler sizes. * spawn.cc (av::error): New element, reflects potential errno from cmalloc. (av::~av): Don't free NULL pointers. (av::replace0_maybe): Detect out-of-memory conditions. (av::dup_maybe): Ditto. (av::dup_all): Ditto. (av::unshift): Ditto. (spawn_guts): Set errno and return if argv creation ran into problems. * fhandler.h (fhandler_union): Change member names to something safer. * fhandler_console.cc (fhandler_console::get_tty_stuff): Always set fhandler_console::dev_state regardless of whether shared region is initialized. * cygthread.cc (cygthread::runner): Use ExitThread rather than return (planning for future).
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r--winsup/cygwin/spawn.cc42
1 files changed, 28 insertions, 14 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 193f593bc..34927c1f0 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -254,17 +254,22 @@ class av
char **argv;
int calloced;
public:
+ int error;
int argc;
- av (int ac, const char * const *av) : calloced (0), argc (ac)
+ av (int ac, const char * const *av) : calloced (0), error (false), argc (ac)
{
argv = (char **) cmalloc (HEAP_1_ARGV, (argc + 5) * sizeof (char *));
memcpy (argv, av, (argc + 1) * sizeof (char *));
}
~av ()
{
- for (int i = 0; i < calloced; i++)
- cfree (argv[i]);
- cfree (argv);
+ if (argv)
+ {
+ for (int i = 0; i < calloced; i++)
+ if (argv[i])
+ cfree (argv[i]);
+ cfree (argv);
+ }
}
int unshift (const char *what, int conv = 0);
operator char **() {return argv;}
@@ -272,21 +277,23 @@ class av
void replace0_maybe (const char *arg0)
{
/* Note: Assumes that argv array has not yet been "unshifted" */
- if (!calloced)
- {
- argv[0] = cstrdup1 (arg0);
- calloced = 1;
- }
+ if (!calloced
+ && (argv[0] = cstrdup1 (arg0)))
+ calloced = true;
+ else
+ error = errno;
}
void dup_maybe (int i)
{
- if (i >= calloced)
- argv[i] = cstrdup1 (argv[i]);
+ if (i >= calloced
+ && !(argv[i] = cstrdup1 (argv[i])))
+ error = errno;
}
void dup_all ()
{
for (int i = calloced; i < argc; i++)
- argv[i] = cstrdup1 (argv[i]);
+ if (!(argv[i] = cstrdup1 (argv[i])))
+ error = errno;
}
};
@@ -309,7 +316,8 @@ av::unshift (const char *what, int conv)
*p = '\0';
what = buf;
}
- *argv = cstrdup1 (what);
+ if (!(*argv = cstrdup1 (what)))
+ error = errno;
argc++;
calloced++;
return 1;
@@ -338,7 +346,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
{
syscall_printf ("argv is NULL");
set_errno (EINVAL);
- return (-1);
+ return -1;
}
path_conv real_path;
@@ -561,6 +569,12 @@ spawn_guts (const char * prog_arg, const char *const *argv,
char *envblock;
newargv.all_calloced ();
+ if (newargv.error)
+ {
+ set_errno (newargv.error);
+ return -1;
+ }
+
ciresrv.moreinfo->argc = newargv.argc;
ciresrv.moreinfo->argv = newargv;
ciresrv.hexec_proc = hexec_proc;