This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Protect fork() against dll- and exe-updates.


Hi Corinna,

have reworked the hardlink-creation from scratch as discussed before,
now using /var/run/cygfork/ as the top-level hardlinks directory.

* At process start and during LoadLibrary, handles to all the loaded
  dlls (including cygwin1.dll) and the main executable are opened.

* At fork(), immediately before that CreateProcessW, all the dlls
  registered above are checked by filesystem if they still are
  identical as loaded in the current process - as long as the
  /var/run/ directory is on NTFS and the cygfork directory exists.

* If they are not identical (any more), hardlinks to these dlls are
  created in subdirectories into /var/run/cygfork/<sid>/.
  
* The name of that subdirs is mangled using the /path/to.exe and the
  most recent ftLastWriteTime found in the list of loaded dlls.
  This is necessary to allow for one dll to be used by concurrent
  processes when started before and after that dll's update.

* The creation and removal of these directories and hardlinks is
  synchronized via some mutex, which's name contains the same names as
  the directories created.

* The removal is done by iterating over all the directories found in
  /var/run/cygfork/, recreating the mutex-names along these directory
  names, and removing them only if the named mutex does not exist any
  more. This ensures to clean up even in case of power-loss or similar.

* For debugging purpose, if the /var/run/cygfork/.needed file does
  exist, the hardlinks are created even if the dlls were up-to-date.

* For inheriting the open file handles and the mutex handle during fork
  only, their inheritance flag is set before that fork's CreateProcessW,
  and reset afterwards both in parent and child.

* For the timing: Building cygwin-2.4.0-0.2 three times, the duration
  difference is in the range of measuring fault - almost identical for
  each possible variant vanilla,disabled,enabled,forced.

More thoughts?
More to discuss?

Thanks!
/haubi/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]