Cygwin: fix up proc_subproc flags and matching pinfo methods

After patch 23a779bf3d
"Cygwin: pinfo: stop remember doing reattach",
PROC_ADDCHILD actually just sets up a new child, mirroring
PROC_DETACHED_CHILD.  The actual attaching of the child is
performed by action PROC_REATTACH_CHILD or pinfo::reattach
respectively.

To better reflect what's going on, rename PROC_REATTACH_CHILD
to PROC_ATTACH_CHILD and rename pinfo::reattach to pinfo::attach.
For better readability change PROC_ADDCHILD to PROC_ADD_CHILD.
Fix comments accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2020-08-27 21:38:50 +02:00
parent 49a9ffdf4b
commit 0a31ad6f4c
5 changed files with 15 additions and 14 deletions

View File

@ -509,11 +509,11 @@ frok::parent (volatile char * volatile stack_here)
/* Do not attach to the child before it has successfully initialized.
Otherwise we may wait forever, or deliver an orphan SIGCHILD. */
if (!child.reattach ())
if (!child.attach ())
{
this_errno = EAGAIN;
#ifdef DEBUGGING0
error ("child reattach failed");
error ("child attach failed");
#endif
goto cleanup;
}

View File

@ -187,18 +187,18 @@ public:
void preserve () { destroy = false; }
void allow_remove () { destroy = true; }
#ifndef SIG_BAD_MASK // kludge to ensure that sigproc.h included
// int reattach () {system_printf ("reattach is not here"); return 0;}
// int attach () {system_printf ("attach is not here"); return 0;}
// int remember (bool) {system_printf ("remember is not here"); return 0;}
#else
int reattach ()
int attach ()
{
int res = proc_subproc (PROC_REATTACH_CHILD, (uintptr_t) this);
int res = proc_subproc (PROC_ATTACH_CHILD, (uintptr_t) this);
destroy = res ? false : true;
return res;
}
int remember (bool detach)
{
int res = proc_subproc (detach ? PROC_DETACHED_CHILD : PROC_ADDCHILD,
int res = proc_subproc (detach ? PROC_DETACHED_CHILD : PROC_ADD_CHILD,
(uintptr_t) this);
destroy = res ? false : true;
return res;

View File

@ -195,7 +195,7 @@ proc_subproc (DWORD what, uintptr_t val)
/* Add a new subprocess to the children arrays.
* (usually called from the main thread)
*/
case PROC_ADDCHILD:
case PROC_ADD_CHILD:
/* Filled up process table? */
if (nprocs >= NPROCS)
{
@ -217,11 +217,12 @@ proc_subproc (DWORD what, uintptr_t val)
vchild->ctty = myself->ctty;
vchild->cygstarted = true;
vchild->process_state |= PID_INITIALIZING;
vchild->ppid = what == PROC_DETACHED_CHILD ? 1 : myself->pid; /* always set last */
vchild->ppid = what == PROC_DETACHED_CHILD
? 1 : myself->pid; /* always set last */
}
break;
case PROC_REATTACH_CHILD:
case PROC_ATTACH_CHILD:
procs[nprocs] = vchild;
rc = procs[nprocs].wait ();
if (rc)
@ -879,7 +880,7 @@ child_info_spawn::wait_for_myself ()
{
postfork (myself);
if (myself.remember (false))
myself.reattach ();
myself.attach ();
WaitForSingleObject (ev, INFINITE);
}
@ -973,7 +974,7 @@ cygheap_exec_info::reattach_children (HANDLE parent)
pinfo p (parent, children[i].p, children[i].pid);
if (!p)
debug_only_printf ("couldn't reattach child %d from previous process", children[i].pid);
else if (!p.reattach ())
else if (!p.attach ())
debug_only_printf ("attach of child process %d failed", children[i].pid);
else
debug_only_printf ("reattached pid %d<%u>, process handle %p, rd_proc_pipe %p->%p",

View File

@ -30,8 +30,8 @@ enum
enum procstuff
{
PROC_ADDCHILD = 1, // add a new subprocess to list
PROC_REATTACH_CHILD = 2, // reattach after exec
PROC_ADD_CHILD = 1, // set up a new child
PROC_ATTACH_CHILD = 2, // attach child or reattach after exec
PROC_EXEC_CLEANUP = 3, // cleanup waiting children after exec
PROC_DETACHED_CHILD = 4, // set up a detached child
PROC_CLEARWAIT = 5, // clear all waits - signal arrived

View File

@ -869,7 +869,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
postfork (child);
if (mode == _P_DETACH
? !child.remember (true)
: !(child.remember (false) && child.reattach ()))
: !(child.remember (false) && child.attach ()))
{
/* FIXME: Child in strange state now */
CloseHandle (pi.hProcess);