forkables: On fork failure, retry with hardlinks.

To support in-cygwin package managers, the fork() implementation must
not rely on .exe and .dll files to stay in their original location, as
the package manager's job is to replace these files.  Instead, when the
first fork try fails, and we have NTFS, we use hardlinks to the original
binaries in /var/run/cygfork/ to create the child process during the
second fork try, along the main.exe.local file to enable the "DotLocal
Dll Redirection" feature for the dlls.

The (probably few) users that need an update-safe fork manually have to
create the /var/run/cygfork/ directory for now, using:
mkdir --mode=a=rwxt /var/run/cygfork

	* child_info.h: Bump CURR_CHILD_INFO_MAGIC.
	(enum child_status): Add _CI_SILENTFAIL flag.
	(struct child_info): Add silentfail setter and getter.
	* winsup.h (child_copy): Add bool silentfail parameter.
	* cygheap.cc: Pass silentfail parameter to child_copy.
	* dcrt0.cc: Ditto.
	* dll_init.h (struct dll): Define public inline method forkedntname.
	(struct dll_list): Declare private method find_by_forkedntname.
	* dll_init.cc (struct dll_list): Implement find_by_forkedntname.
	(dll_list::alloc): Use find_by_forkedntname when in load after fork.
	(dll_list::load_after_fork_impl): Load dlls using dll::forkedntname.
	* fork.cc (frok::parent): Set silentfail child info flag.  Pass
	silentfail parameter to child_copy.  Use forkedntname of
	dlls.main_executable.
	(fork): When first dofork run failed and did not use forkables,
	run dofork again with_forkables set to true.
	(child_copy): Use debug_printf if silentfail is true,
	system_printf otherwise.
This commit is contained in:
Michael Haubenwallner
2016-12-07 11:58:28 +01:00
committed by Corinna Vinschen
parent 8ddb1f60c8
commit ece7282f32
8 changed files with 85 additions and 33 deletions

View File

@@ -21,7 +21,8 @@ enum child_status
{
_CI_STRACED = 0x01,
_CI_ISCYGWIN = 0x02,
_CI_SAW_CTRL_C = 0x04
_CI_SAW_CTRL_C = 0x04,
_CI_SILENTFAIL = 0x08
};
#define OPROC_MAGIC_MASK 0xff00ff00
@@ -36,7 +37,7 @@ enum child_status
#define EXEC_MAGIC_SIZE sizeof(child_info)
/* Change this value if you get a message indicating that it is out-of-sync. */
#define CURR_CHILD_INFO_MAGIC 0xc96f5e9U
#define CURR_CHILD_INFO_MAGIC 0x3ee00652U
#define NPROCS 256
@@ -82,6 +83,7 @@ public:
bool isstraced () const {return !!(flag & _CI_STRACED);}
bool iscygwin () const {return !!(flag & _CI_ISCYGWIN);}
bool saw_ctrl_c () const {return !!(flag & _CI_SAW_CTRL_C);}
bool silentfail () const {return !!(flag & _CI_SILENTFAIL);}
void prefork (bool = false);
void cleanup ();
void postfork (pinfo& child)
@@ -91,6 +93,13 @@ public:
child.set_rd_proc_pipe (rd_proc_pipe);
rd_proc_pipe = NULL;
}
void silentfail (bool f)
{
if (f)
flag |= _CI_SILENTFAIL;
else
flag &= ~_CI_SILENTFAIL;
}
};
class mount_info;