public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: gs-cygwin.com@gluelogic.com
To: Bruno Haible <bruno@clisp.org>, cygwin@cygwin.com
Subject: Re: posix_spawn facility
Date: Thu, 20 Apr 2023 14:04:01 -0400	[thread overview]
Message-ID: <ZEF+kVZZ/l6IWJqb@xps13> (raw)
In-Reply-To: <ZEFO9ELNzIliSGPv@calimero.vinschen.de>

On Thu, Apr 20, 2023 at 04:40:52PM +0200, Corinna Vinschen via Cygwin wrote:
> On Apr 20 16:21, Corinna Vinschen via Cygwin wrote:
> > On Apr 20 12:18, Bruno Haible via Cygwin wrote:
> > >      The "inheritable handles" is a data structure that allows for the
> > >      arbitrary reshuffling of file descriptors required by posix_spawn
> > >      (the addopen, adddup2, addclose actions), i.e. which does the book-
> > >      keeping which HANDLE must in the end be open in the parent and which
> > >      must in the end be open in the child, and at which position.
> > 
> > Hmm.  Your code uses lpReserved2 for that, but the functionality is
> > one implemented in MSVCRT.  For obvious reasons, Cygwin executables
> > are not linked against msvcrt.dll and we're using lpReserved2 for our
> > own purposes.
> 
> Oh, btw., did you know that there's a newer mechanism for defining
> specific inheritable handles to CreateProcess, which is implemented
> in kernel32.dll, so it does not depend on MSVCRT?
> 
> There's a STARTUPINFOEX structure which allows to specify the 
> additional handles.  See
> 
> https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-startupinfoexa
> 
> and the PROC_THREAD_ATTRIBUTE_HANDLE_LIST argument described in
> 
> https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute

An example using these to run CGI programs in lighttpd on Windows
using native _WIN32 code can be seen on my dev branch (intended for
lighttpd 1.4.70).

https://git.lighttpd.net/lighttpd/lighttpd1.4/src/branch/personal/gstrauss/master/src/fdevent_win32.c#L539
(lighttpd is BSD-3-Clause)

The aim is to securely manage which handles are inherited by child CGI
processes.  Elsewhere, lighttpd clears HANDLE_FLAG_INHERIT on handles
lighttpd creates, and uses WSA_FLAG_NO_HANDLE_INHERIT in calls to
WSASocket() func family.  Also in that file, I have an (expensive)
socketpair() implementation, since lighttpd uses sockets instead of
pipes to connect to CGI programs, so that events can be received using
WSAPoll() or select().

To get things working in native _WIN32 lighttpd, which has a test
framework that runs under Cygwin, I had to detect and perform some path
translation between native Windows and Cygwin paths.  While my solution
is specific to lighttpd's use, I hope that this may give you some ideas.

Cheers, Glenn

  parent reply	other threads:[~2023-04-20 18:04 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-16 11:46 Bruno Haible
2023-04-17  9:18 ` Corinna Vinschen
2023-04-17 18:44   ` Bruno Haible
2023-04-18  9:25     ` Corinna Vinschen
2023-04-18 20:49       ` Eric Blake
2023-04-18 21:00         ` Corinna Vinschen
2023-04-18 22:10         ` Bruno Haible
2023-04-19  2:39           ` Eric Blake
2023-04-19  8:19             ` Corinna Vinschen
2023-04-19 11:56             ` Bruno Haible
2023-04-20  6:52               ` Csaba Raduly
2023-07-31 18:58         ` Eric Blake
2023-07-31 19:12           ` Corinna Vinschen
2023-04-19  8:24     ` Corinna Vinschen
2023-04-19 11:24       ` posix_spawn_file_actions_add[f]chdir_np Bruno Haible
2023-04-19 15:05         ` posix_spawn_file_actions_add[f]chdir_np Corinna Vinschen
2023-04-19 19:13           ` posix_spawn_file_actions_add[f]chdir_np Corinna Vinschen
2023-04-19 21:33             ` posix_spawn_file_actions_add[f]chdir_np Eliot Moss
2023-04-20 10:27             ` posix_spawn_file_actions_add[f]chdir_np Bruno Haible
2023-04-19 10:48     ` posix_spawn facility Bruno Haible
2023-04-20  7:14     ` gs-cygwin.com
2023-04-20  8:35       ` Corinna Vinschen
2023-04-20 10:18         ` Bruno Haible
2023-04-20 14:21           ` Corinna Vinschen
2023-04-20 14:40             ` Corinna Vinschen
2023-04-20 14:58               ` Bruno Haible
2023-04-20 15:40                 ` Corinna Vinschen
2023-04-20 18:46                   ` gs-cygwin.com
2023-04-20 18:40                 ` gs-cygwin.com
2023-04-20 19:31                   ` Bruno Haible
2023-04-20 20:00                     ` gs-cygwin.com
2023-05-10  9:15                       ` gs-cygwin.com
2023-04-20 18:04               ` gs-cygwin.com [this message]
2023-05-10  8:59       ` gs-cygwin.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZEF+kVZZ/l6IWJqb@xps13 \
    --to=gs-cygwin.com@gluelogic.com \
    --cc=bruno@clisp.org \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).