Re: [PATCH] A working implementation of fork_to_background() under Windows – please test

2004-03-23 Thread David Fritz
Herold Heiko wrote:
MSVC binary at http://xoomer.virgilio.it/hherold/ for public testing.
I performed only basic tests on NT4 sp6a, everything performed fine as
expected.
Thank you much for testing and hosting the binary.

Some ideas on this thing:
I'll respond to your points out-of-order.

In verbose mode the child should probably acknowledge in the log file the
fact it was invocated as child.
The current patch attempts to emulate the behavior of the Unix version.  AFAICT, 
this and the following suggestion apply equally well to the existing (Unix) code.

In quiet mode the parent log (child pid, "log on wget-log" or whatever)
probably should not be printed.
Also, perhaps in quiet mode the child should not automatically set a log file if 
none was specified.  IIUC, the log file would always be empty.

In debug mode the client should probably also log the name of the section
object and any information retrieved from it (currently the flag only).
Sure, I could add a number of debug prints.

A possible fix for the wgetrc race condition could be caching the content of
the whole wgetrc in the parent and transmit it in the section object to the
child, a bit messy I must admit but a possible solution if that race
condition is considered a Bad Thing.
That would work, but would require making changes to the main code and would 
require performing the child detection logic much earlier (even before we know 
if –b was specified).  We could also exploit Windows file-sharing semantics or 
file locking features to guarantee the config files can't change.  I'm unsure 
such complexity is necessary.

About the only scenario I could think
of is where you have a script creating a custom wgetrc, run wget, then
change the wgetrc: introduce -b and the script could change the wgetrc after
running wget but before the parsing on client side a rather remote but
possible scenario.
In this scenario, the script would have to wait for the parent to terminate to 
avoid a race, even with the Unix version.  With this patch the child would have 
necessarily finished reading any wgetrc files before the parent terminates.  So 
there shouldn't be a problem.

Thanks again,
David Fritz



RE: [PATCH] A working implementation of fork_to_background() under Windows – please test

2004-03-23 Thread Herold Heiko
MSVC binary at http://xoomer.virgilio.it/hherold/ for public testing.
I performed only basic tests on NT4 sp6a, everything performed fine as
expected.

Some ideas on this thing:

In verbose mode the child should probably acknowledge in the log file the
fact it was invocated as child.

In debug mode the client should probably also log the name of the section
object and any information retrieved from it (currently the flag only).

In quiet mode the parent log (child pid, "log on wget-log" or whatever)
probably should not be printed.

A possible fix for the wgetrc race condition could be caching the content of
the whole wgetrc in the parent and transmit it in the section object to the
child, a bit messy I must admit but a possible solution if that race
condition is considered a Bad Thing. About the only scenario I could think
of is where you have a script creating a custom wgetrc, run wget, then
change the wgetrc: introduce -b and the script could change the wgetrc after
running wget but before the parsing on client side a rather remote but
possible scenario.

Heiko 

-- 
-- PREVINET S.p.A. www.previnet.it
-- Heiko Herold [EMAIL PROTECTED] [EMAIL PROTECTED]
-- +39-041-5907073 ph
-- +39-041-5907472 fax

> -Original Message-
> From: David Fritz [mailto:[EMAIL PROTECTED]
> Sent: Saturday, March 20, 2004 2:37 AM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: [PATCH] A working implementation of 
> fork_to_background() under
> Windows – please test
> 
> 
> Attached is an implementation of fork_to_background() for 
> Windows that (I hope) 
> has the desired effect under both 9x and NT.
> 
> _This is a preliminary patch and needs to be tested._
> 
> The patch is dependant upon the fact that the only time 
> fork_to_background() is 
> called is on start-up when –b is specified.
> 
> Windows of course does not support the fork() call, so it 
> must be simulated. 
> This can be done by creating a new process and using some 
> form of inter-process 
> communication to transfer the state of the old process to the 
> new one.  This 
> requires the parent and child to cooperate and when done in a 
> general way (such 
> as by Cygwin) requires a lot of work.
> 
> However, with Wget since we have a priori knowledge of what 
> could have changed 
> in the parent by the time we call fork(), we could implement 
> a special purpose 
> fork() that only passes to the child the things that we know 
> could have changed. 
>   (The initialization done by the C run-time library, etc. 
> would be performed 
> anew in the child, but hold on a minute.)
> 
> The only real work done by Wget before calling fork() is the 
> reading of wgetrc 
> files and the processing of command-line arguments.  Passing 
> this information 
> directly to the child would be possible, but the 
> implementation would be complex 
> and fragile. It would need to be updated as changes are made 
> to the main code.
> 
> It would be much simpler to simply perform the initialization 
> (reading of config 
> files, processing of args, etc.) again in the child.  This 
> would have a small 
> performance impact and introduce some race-conditions, but I 
> think the 
> advantages (having –b work) outweigh the disadvantages.
> 
> The implementation is, I hope, fairly straightforward.  I 
> have attempted to 
> explain it in moderate detail in an attached README.
> 
> I'm hoping others can test it with various operating systems 
> and compilers. 
> Also, any feedback regarding the design or implementation 
> would be welcome.  Do 
> you feel this is the right way to go about this?
> 
> Cheers,
> David Fritz
> 
> 
> 2004-03-19  David Fritz  <[EMAIL PROTECTED]>
> 
>   * mswindows.c (make_section_name, fake_fork, 
> fake_fork_child): New
>   functions.
>   (fork_to_backgorund): Replace with new implementation.
> 
> 
> 
> 


RE: [PATCH] Windows console control event handling

2004-03-23 Thread Herold Heiko
Windows MSVC binary at http://xoomer.virgilio.it/hherold/
Heiko

-- 
-- PREVINET S.p.A. www.previnet.it
-- Heiko Herold [EMAIL PROTECTED] [EMAIL PROTECTED]
-- +39-041-5907073 ph
-- +39-041-5907472 fax

> -Original Message-
> From: Hrvoje Niksic [mailto:[EMAIL PROTECTED]
> Sent: Saturday, March 20, 2004 12:58 AM
> To: David Fritz
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PATCH] Windows console control event handling
> 
> 
> Thanks for looking into this.  I don't pretend to understand the logic
> behind this part of the Windows code.
> 
> I applied your patch, thanks.
>