aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2006-03-29 06:35:25 +0000
committerChristopher Faylor <me@cgf.cx>2006-03-29 06:35:25 +0000
commit12b33712894f9c61732ef686d81248fc607b6766 (patch)
tree67847a11d95c794dd7d91e58c366c2b521de701d /winsup/cygwin
parentcdc2256b769c1183177bf92cb22c34311ce8e6de (diff)
downloadnewlib-12b33712894f9c61732ef686d81248fc607b6766.zip
newlib-12b33712894f9c61732ef686d81248fc607b6766.tar.gz
newlib-12b33712894f9c61732ef686d81248fc607b6766.tar.bz2
* dcrt0.cc (child_info_fork::handle_fork): Set uid/gid in myself so that it can
be used by subsequent startup functions. (dll_crt0_0): Issue a warning if DuplicateTokenEx fails and DEBUGGING. (dll_crt0_1): Move user_data->{resourcelocks,threadinterface} initialization here from dll_crt0_0. * fork.cc (frok::child): Tell wait_for_sigthread that this is fork. (frok::parent): Only initialize start_time once. Tighten time when we're "deimpersonated". * sigproc.cc (signal_fixup_after_exec): Rework (futiley) sa_buf stuff. Add debugging output. (wait_for_sigthread): Accept an argument which illustrates whether we are forked or not. (wait_sig): Avoid using myself pointer. * winsup.h ((wait_for_sigthread): Reflect change to argument.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog17
-rw-r--r--winsup/cygwin/dcrt0.cc26
-rw-r--r--winsup/cygwin/fork.cc28
-rw-r--r--winsup/cygwin/sigproc.cc17
-rw-r--r--winsup/cygwin/sigproc.h2
5 files changed, 57 insertions, 33 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 16dc01e..f3908aa 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,20 @@
+2006-03-29 Christopher Faylor <cgf@timesys.com>
+
+ * dcrt0.cc (child_info_fork::handle_fork): Set uid/gid in myself so
+ that it can be used by subsequent startup functions.
+ (dll_crt0_0): Issue a warning if DuplicateTokenEx fails and DEBUGGING.
+ (dll_crt0_1): Move user_data->{resourcelocks,threadinterface}
+ initialization here from dll_crt0_0.
+ * fork.cc (frok::child): Tell wait_for_sigthread that this is fork.
+ (frok::parent): Only initialize start_time once. Tighten time when
+ we're "deimpersonated".
+ * sigproc.cc (signal_fixup_after_exec): Rework (futiley) sa_buf stuff.
+ Add debugging output.
+ (wait_for_sigthread): Accept an argument which illustrates whether we
+ are forked or not.
+ (wait_sig): Avoid using myself pointer.
+ * winsup.h ((wait_for_sigthread): Reflect change to argument.
+
2006-03-26 Christopher Faylor <cgf@timesys.com>
* spawn.cc (spawn_guts): Close handles if we know that we will not be
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 1df274c..f65d772 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -653,6 +653,9 @@ child_info_fork::handle_fork ()
cygheap_fixup_in_child (false);
memory_init ();
set_myself (NULL);
+ myself->uid = cygheap->user.real_uid;
+ myself->gid = cygheap->user.real_gid;
+
child_copy (parent, false,
"dll data", dll_data_start, dll_data_end,
"dll bss", dll_bss_start, dll_bss_end,
@@ -750,9 +753,6 @@ dll_crt0_0 ()
}
}
- user_data->resourcelocks->Init ();
- user_data->threadinterface->Init ();
-
_cygtls::init ();
/* Initialize events */
@@ -761,10 +761,16 @@ dll_crt0_0 ()
cygheap->cwd.init ();
/* Late duplicate simplifies tweaking the process token in uinfo.cc. */
- if (wincap.has_security ())
- DuplicateTokenEx (hProcToken, MAXIMUM_ALLOWED, NULL,
- SecurityImpersonation, TokenImpersonation,
- &hProcImpToken);
+ if (wincap.has_security ()
+ && !DuplicateTokenEx (hProcToken, MAXIMUM_ALLOWED, NULL,
+ SecurityImpersonation, TokenImpersonation,
+ &hProcImpToken))
+#ifdef DEBUGGING
+ system_printf ("DuplicateTokenEx failed, %E");
+#else
+ ;
+#endif
+
debug_printf ("finished dll_crt0_0 initialization");
}
@@ -784,6 +790,8 @@ dll_crt0_1 (char *)
small_printf ("cmalloc returns %p\n", cmalloc (HEAP_STR, n));
#endif
+ user_data->resourcelocks->Init ();
+ user_data->threadinterface->Init ();
ProtectHandle (hMainProc);
ProtectHandle (hMainThread);
@@ -796,7 +804,7 @@ dll_crt0_1 (char *)
strace.microseconds ();
#endif
- create_signal_arrived ();
+ create_signal_arrived (); /* FIXME: move into wait_sig? */
/* Initialize debug muto, if DLL is built with --enable-debugging.
Need to do this before any helper threads start. */
@@ -838,7 +846,7 @@ dll_crt0_1 (char *)
set_cygwin_privileges (hProcImpToken);
if (!old_title && GetConsoleTitle (title_buf, TITLESIZE))
- old_title = title_buf;
+ old_title = title_buf;
/* Allocate cygheap->fdtab */
dtable_init ();
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 82d1b32..b60a2bc 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -178,7 +178,7 @@ frok::child (void *)
ld_preload ();
fixup_hooks_after_fork ();
_my_tls.fixup_after_fork ();
- wait_for_sigthread ();
+ wait_for_sigthread (true);
cygwin_finished_initializing = true;
return 0;
}
@@ -283,17 +283,17 @@ frok::parent (void *stack_here)
si.lpReserved2 = (LPBYTE) &ch;
si.cbReserved2 = sizeof (ch);
+ syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %p, 0, 0, %p, %p)",
+ myself->progname, myself->progname, c_flags, &si, &pi);
+ bool locked = __malloc_lock ();
+ time_t start_time = time (NULL);
+
/* Remove impersonation */
cygheap->user.deimpersonate ();
fix_impersonation = true;
- syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %p, 0, 0, %p, %p)",
- myself->progname, myself->progname, c_flags, &si, &pi);
- bool locked = __malloc_lock ();
- time_t start_time;
while (1)
{
- start_time = time (NULL);
rc = CreateProcess (myself->progname, /* image to run */
myself->progname, /* what we send in arg0 */
&sec_none_nih,
@@ -345,6 +345,10 @@ frok::parent (void *stack_here)
break;
}
+ /* Restore impersonation */
+ cygheap->user.reimpersonate ();
+ fix_impersonation = false;
+
child_pid = cygwin_pid (pi.dwProcessId);
child.init (child_pid, 1, NULL);
@@ -366,10 +370,6 @@ frok::parent (void *stack_here)
for the forkee. */
strcpy (child->progname, myself->progname);
- /* Restore impersonation */
- cygheap->user.reimpersonate ();
- fix_impersonation = false;
-
/* Fill in fields in the child's process table entry. */
child->dwProcessId = pi.dwProcessId;
child.hProcess = pi.hProcess;
@@ -396,10 +396,10 @@ frok::parent (void *stack_here)
/* CHILD IS STOPPED */
debug_printf ("child is alive (but stopped)");
- /* Initialize, in order: data, bss, heap, stack, dll data, dll bss
- Note: variables marked as NO_COPY will not be copied
- since they are placed in a protected segment. */
-
+ /* Initialize, in order: stack, dll data, dll bss.
+ data, bss, heap were done earlier (in dcrt0.cc)
+ Note: variables marked as NO_COPY will not be copied since they are
+ placed in a protected segment. */
MALLOC_CHECK;
const void *impure_beg;
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 02f5387..7d22af3 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -134,11 +134,12 @@ signal_fixup_after_exec ()
}
void __stdcall
-wait_for_sigthread ()
+wait_for_sigthread (bool forked)
{
- PSECURITY_ATTRIBUTES sa_buf = (PSECURITY_ATTRIBUTES) alloca (1024);
- if (!CreatePipe (&my_readsig, &my_sendsig, sec_user_nih (sa_buf), 0))
- api_fatal ("couldn't create signal pipe, %E");
+ char char_sa_buf[1024];
+ PSECURITY_ATTRIBUTES sa_buf = sec_user_nih ((PSECURITY_ATTRIBUTES) char_sa_buf);
+ if (!CreatePipe (&my_readsig, &my_sendsig, sa_buf, 0))
+ api_fatal ("couldn't create signal pipe%s, %E", forked ? " for forked process" : "");
ProtectHandle (my_readsig);
myself->sendsig = my_sendsig;
@@ -151,6 +152,7 @@ wait_for_sigthread ()
wait_sig_inited = NULL;
ForceCloseHandle1 (hsig_inited, wait_sig_inited);
SetEvent (sigCONT);
+ sigproc_printf ("process/signal handling enabled, state %p", myself->process_state);
}
/* Get the sync_proc_subproc muto to control access to
@@ -497,8 +499,6 @@ sigproc_init ()
hwait_sig = new cygthread (wait_sig, 0, cygself, "sig");
hwait_sig->zap_h ();
-
- sigproc_printf ("process/signal handling enabled, state %p", myself->process_state);
}
/* Called on process termination to terminate signal and process threads.
@@ -1134,13 +1134,12 @@ wait_sig (VOID *)
sigCONT = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
- sigproc_printf ("myself->dwProcessId %u", myself->dwProcessId);
SetEvent (wait_sig_inited);
_sig_tls = &_my_tls;
_sig_tls->init_threadlist_exceptions ();
- debug_printf ("entering ReadFile loop, my_readsig %p, myself->sendsig %p",
- my_readsig, myself->sendsig);
+ sigproc_printf ("entering ReadFile loop, my_readsig %p, my_sendsig %p",
+ my_readsig, my_sendsig);
sigpacket pack;
pack.si.si_signo = __SIGHOLD;
diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h
index e1230a1..4657f6d 100644
--- a/winsup/cygwin/sigproc.h
+++ b/winsup/cygwin/sigproc.h
@@ -81,7 +81,7 @@ bool __stdcall pid_exists (pid_t) __attribute__ ((regparm(1)));
int __stdcall sig_send (_pinfo *, siginfo_t&, class _cygtls *tls = NULL) __attribute__ ((regparm (3)));
int __stdcall sig_send (_pinfo *, int) __attribute__ ((regparm (2)));
void __stdcall signal_fixup_after_exec ();
-void __stdcall wait_for_sigthread ();
+void __stdcall wait_for_sigthread (bool = false);
void __stdcall sigalloc ();
void __stdcall create_signal_arrived ();