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-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
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,
}
}
- user_data->resourcelocks->Init ();
- user_data->threadinterface->Init ();
-
_cygtls::init ();
/* Initialize events */
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");
}
small_printf ("cmalloc returns %p\n", cmalloc (HEAP_STR, n));
#endif
+ user_data->resourcelocks->Init ();
+ user_data->threadinterface->Init ();
ProtectHandle (hMainProc);
ProtectHandle (hMainThread);
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. */
set_cygwin_privileges (hProcImpToken);
if (!old_title && GetConsoleTitle (title_buf, TITLESIZE))
- old_title = title_buf;
+ old_title = title_buf;
/* Allocate cygheap->fdtab */
dtable_init ();
ld_preload ();
fixup_hooks_after_fork ();
_my_tls.fixup_after_fork ();
- wait_for_sigthread ();
+ wait_for_sigthread (true);
cygwin_finished_initializing = true;
return 0;
}
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,
break;
}
+ /* Restore impersonation */
+ cygheap->user.reimpersonate ();
+ fix_impersonation = false;
+
child_pid = cygwin_pid (pi.dwProcessId);
child.init (child_pid, 1, NULL);
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;
/* 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;
}
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;
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
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.
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;
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 ();