summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/dcrt0.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-10-16 23:55:58 +0000
committerChristopher Faylor <me@cgf.cx>2000-10-16 23:55:58 +0000
commit166b2571ce446b4085d4c2067b0d0d36c608f131 (patch)
tree097f18452160a8058924634fa52d5e454e8dfe9e /winsup/cygwin/dcrt0.cc
parentd9d9b707185277db9c0be4eaa2ee5dba9df71fd7 (diff)
downloadcygnal-166b2571ce446b4085d4c2067b0d0d36c608f131.tar.gz
cygnal-166b2571ce446b4085d4c2067b0d0d36c608f131.tar.bz2
cygnal-166b2571ce446b4085d4c2067b0d0d36c608f131.zip
* Makefile.in: Remove some obsolete stuff.
* dcrt0.cc (dll_crt0_1): Call signal_fixup_after_exec where appropriate. Set myself->uid from parent version. Just use ThreadItem Init method. Close or store hexec_proc as appropriate. (_dll_crt0): Store user_data->forkee here so that proper tests can be made subsequently. (do_exit): Remove hExeced stuff. * environ.cc (environ_init): Accept environ count as well as environ pointer. * environ.h: Reflect above change. * pinfo.cc (pinfo_init): Ditto. Accept environ count. (fixup_in_spawned_child): Remove. * spawn.cc (spawn_guts): Move signal code to dll_crt0_1. Don't suspend execing process since it is no longer necessary. Store envc. * exceptions.cc (signal_fixup_after_exec): New function. (call_handler): Remove hExeced test. * child_info.h (cygheap_exec_info): Store envc as well as envp. (child_info_spawn): Store hexec_proc so that it can be closed in child. * path.cc (normalize_posix_path): Avoid intermediate use of temporary cwd buf. (normalize_win32_path): Ditto. (cwdstuff::get_initial): Always set lock. * sigproc.h: Remove hExeced. * strace.cc (strace::vsprntf): Modify to accomodate for lack of hExeced. * thread.cc (MTinterface::Init): Merge Init1 and ClearReent into this method. (MTinterface::Init1): Eliminate. (MTinterface::ClearReent): Eliminate. * thread.h: Reflect above changes. * include/sys/strace.h (strace): Make microseconds() public. Make various functions 'regparm', throughout. * pinfo.h (_pinfo): Inline simple signal manipulation functions. Requires inclusion of thread.h which was removed from .cc files, where appropriate. throughout. * pinfo.cc: Eliminate signal manipulation functions. (_pinfo::exit): Calculate total rusage for exiting process here. * cygheap.cc (size2bucket): Eliminate. (init_buckets): Ditto. (_cmalloc): Calculate size and bits in a loop rather than going through a function call. (_crealloc): Use stored array index to calculate allocated size. * spawn.cc (spawn_guts): Use _pinfo exit method to exit, calculating cpu usage.
Diffstat (limited to 'winsup/cygwin/dcrt0.cc')
-rw-r--r--winsup/cygwin/dcrt0.cc74
1 files changed, 40 insertions, 34 deletions
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 5adf59478..117cb75c6 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -15,6 +15,7 @@ details. */
#include "exceptions.h"
#include "autoload.h"
#include <ctype.h>
+#include <limits.h>
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
@@ -27,7 +28,6 @@ details. */
#include "perthread.h"
#include "path.h"
#include "dtable.h"
-#include "thread.h"
#include "shared_info.h"
#include "cygwin_version.h"
#include "perprocess.h"
@@ -650,7 +650,7 @@ dll_crt0_1 ()
_impure_ptr = &reent_data;
user_data->resourcelocks->Init ();
- user_data->threadinterface->Init0 ();
+ user_data->threadinterface->Init (user_data->forkee);
threadname_init ();
debug_init ();
@@ -658,6 +658,7 @@ dll_crt0_1 ()
regthread ("main", GetCurrentThreadId ());
+ int envc = 0;
char **envp = NULL;
if (child_proc_info)
@@ -671,14 +672,17 @@ dll_crt0_1 ()
cygheap_fixup_in_child (child_proc_info->parent, 0);
alloc_stack (fork_info);
set_myself (mypid);
- user_data->forkee = child_proc_info->cygpid;
user_data->heaptop = child_proc_info->heaptop;
user_data->heapbase = child_proc_info->heapbase;
user_data->heapptr = child_proc_info->heapptr;
ProtectHandle (child_proc_info->forker_finished);
break;
- case PROC_EXEC:
case PROC_SPAWN:
+ CloseHandle (spawn_info->hexec_proc);
+ goto around;
+ case PROC_EXEC:
+ hexec_proc = spawn_info->hexec_proc;
+ around:
HANDLE h;
cygheap_fixup_in_child (spawn_info->parent, 1);
if (!spawn_info->moreinfo->myself_pinfo ||
@@ -689,12 +693,14 @@ dll_crt0_1 ()
set_myself (mypid, h);
__argc = spawn_info->moreinfo->argc;
__argv = spawn_info->moreinfo->argv;
- envp = spawn_info->moreinfo->environ;
+ envp = spawn_info->moreinfo->envp;
+ envc = spawn_info->moreinfo->envc;
cygcwd.fixup_after_exec (spawn_info->moreinfo->cwd_win32,
spawn_info->moreinfo->cwd_posix,
spawn_info->moreinfo->cwd_hash);
fdtab.fixup_after_exec (spawn_info->parent, spawn_info->moreinfo->nfds,
spawn_info->moreinfo->fds);
+ signal_fixup_after_exec (child_proc_info->type == PROC_SPAWN);
CloseHandle (spawn_info->parent);
if (spawn_info->moreinfo->old_title)
{
@@ -702,6 +708,9 @@ dll_crt0_1 ()
cfree (spawn_info->moreinfo->old_title);
}
ProtectHandle (child_proc_info->subproc_ready);
+ myself->uid = spawn_info->moreinfo->uid;
+ if (myself->uid == USHRT_MAX)
+ myself->use_psid = 0;
break;
}
}
@@ -730,6 +739,8 @@ dll_crt0_1 ()
instead of each time a file is opened. */
set_process_privileges ();
+ cygbench ("pre-forkee");
+
if (user_data->forkee)
{
/* If we've played with the stack, stacksize != 0. That means that
@@ -751,24 +762,11 @@ dll_crt0_1 ()
cygcwd.init ();
/* Initialize our process table entry. */
- pinfo_init (envp);
+ pinfo_init (envp, envc);
if (!old_title && GetConsoleTitle (title_buf, TITLESIZE))
old_title = title_buf;
- /* Nasty static stuff needed by newlib - initialize it.
- Note that impure_ptr has already been set up to point to this above
- NB. This *MUST* be done here, just after the forkee code as some
- of the calls below (eg. uinfo_init) do stdio calls - this area must
- be set to zero before then. */
-
- user_data->threadinterface->ClearReent();
- user_data->threadinterface->Init1();
-
- char *line = GetCommandLineA ();
-
- line = strcpy ((char *) alloca (strlen (line) + 1), line);
-
/* Allocate fdtab */
dtable_init ();
@@ -786,6 +784,9 @@ dll_crt0_1 ()
if (!__argc)
{
+ char *line = GetCommandLineA ();
+ line = strcpy ((char *) alloca (strlen (line) + 1), line);
+
/* Scan the command line and build argv. Expand wildcards if not
called from another cygwin process. */
build_argv (line, __argv, __argc,
@@ -848,6 +849,7 @@ dll_crt0_1 ()
set_errno (0);
MALLOC_CHECK;
+ cygbench (__progname);
if (user_data->main)
exit (user_data->main (__argc, __argv, *user_data->envptr));
}
@@ -862,6 +864,9 @@ extern "C" void __stdcall
_dll_crt0 ()
{
char zeros[sizeof (fork_info->zero)] = {0};
+#ifdef DEBUGGING
+ strace.microseconds ();
+#endif
/* Set the os_being_run global. */
set_os_type ();
@@ -893,10 +898,11 @@ _dll_crt0 ()
{
switch (fork_info->type)
{
- case PROC_EXEC:
- case PROC_SPAWN:
case PROC_FORK:
case PROC_FORK1:
+ user_data->forkee = fork_info->cygpid;
+ case PROC_EXEC:
+ case PROC_SPAWN:
{
child_proc_info = fork_info;
mypid = child_proc_info->cygpid;
@@ -997,9 +1003,7 @@ do_exit (int status)
}
}
- if ((hExeced && hExeced != INVALID_HANDLE_VALUE) || (n & EXIT_NOCLOSEALL))
- n &= ~EXIT_NOCLOSEALL;
- else if (exit_state < ES_CLOSEALL)
+ if (exit_state < ES_CLOSEALL)
{
exit_state = ES_CLOSEALL;
close_all_files ();
@@ -1024,6 +1028,8 @@ do_exit (int status)
/* Kill orphaned children on group leader exit */
if (myself->pid == myself->pgid)
{
+ system_printf ("%d == pgrp %d, send SIG{HUP,CONT} to stopped children",
+ myself->pid, myself->pgid);
sigproc_printf ("%d == pgrp %d, send SIG{HUP,CONT} to stopped children",
myself->pid, myself->pgid);
kill_pgrp (myself->pgid, -SIGHUP);
@@ -1044,17 +1050,7 @@ do_exit (int status)
}
window_terminate ();
- fill_rusage (&myself->rusage_self, hMainProc);
-
events_terminate ();
-
- if (hExeced && hExeced != INVALID_HANDLE_VALUE)
- {
- debug_printf ("Killing(%d) non-cygwin process, handle %p", n, hExeced);
- TerminateProcess (hExeced, n);
- ForceCloseHandle1 (hExeced, childhProc);
- }
-
shared_terminate ();
minimal_printf ("winpid %d, exit %d", GetCurrentProcessId (), n);
@@ -1101,6 +1097,16 @@ __api_fatal (const char *fmt, ...)
myself->exit (1);
}
+#ifdef DEBUGGING
+void __stdcall
+cygbench (const char *s)
+{
+ char buf[1024];
+ if (GetEnvironmentVariable ("CYGWIN_BENCH", buf, sizeof (buf)))
+ small_printf ("%05d ***** %s : %10d\n", GetCurrentProcessId (), s, strace.microseconds ());
+}
+#endif
+
extern "C" {
/* This struct is unused, but it illustrates the layout of a DLL