You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dirk-Willem van Gulik <di...@webweaving.org> on 2000/03/13 19:53:08 UTC
Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
We use tempnam(3) in
src/lib/apr/file_io/unix/pipe.c
and I am tempted to put in an #ifdef for mktemp(3) on those platforms
which have it. But.. from the BSD man page
These interfaces are provided for System V and ANSI compatibility only.
The mkstemp(3) interface is strongly preferred.
There are four important problems with these interfaces (as well as with
the historic mktemp(3) interface). First, there is an obvious race be-
tween file name selection and file creation and deletion. Second, most
historic implementations provide only a limited number of possible tempo-
rary file names (usually 26) before file names will start being recycled.
Third, the System V implementations of these functions (and of mktemp(3))
use the access(2) function to determine whether or not the temporary
file may be created. This has obvious ramifications for setuid or setgid
programs, complicating the portable use of these interfaces in such pro-
grams. Finally, there is no specification of the permissions with which
the temporary files are created.
This implementation does not have these flaws, but portable
software can-
not depend on that. In particular, the tmpfile() interface should
not be
used in software expected to be used on other systems if there is any
possibility that the user does not wish the temporary file to be publicly
readable and writable.
One can conclude that for BSD it is not needed to do an #ifdef as its implementation
is fixed. Any comments as to what to do ?
Dw
NT Async CGI
Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> From: Bill Stoddard [mailto:stoddard@raleigh.ibm.com]
> Sent: Tuesday, March 14, 2000 9:06 AM
>
> PIPE_NOWAIT ==> Nonblocking mode is enabled. [...] should
> not be used to achieve asynchronous input and output
> (I/O) with named pipes.
>
> Would be interesting to try this, but should we rely on it?
> I've not been able to find a way to do async I/O (using the
> async I/O APIs) on an "anonymous" NT pipe.
>
> Bill
Couple thoughts... first was to play the standard CGI game,
spawn the child, pump the request in, then write it all out.
The caviat would be two params, something like
CGIAsynchHoldTimeout .25
CGIAsynchHoldBytes 8192
When we hit the HoldTimeout or HoldBytes, a second Apache
thread would be borrowed to queue the output to the client.
This eliminates second threads for all but the most onerous
scripts, since the short transmission or queued fast response
processes just don't require two threads. It also implies
the pipes could be blocking, if they are timed out.
The real questions involve implementing I/O completion
routines, multiple event blocking or single event blocking
with PeekNamedPipe tests. Note single event blocking _can_
use a named pipe handle as the event if there is only
one event being watched. Again from the API...
In some circumstances, you can also use a file, named pipe, or
communications device as a synchronization object; however, their use for
this purpose is discouraged. Instead, use asynchronous I/O and wait on the
event object set in the OVERLAPPED structure. It is safer to use the event
object because of the confusion that can occur when multiple simultaneous
overlapped operations are performed on the same file, named pipe, or
communications device. In this situation, there is no way to know which
operation caused the object's state to be signaled.
I'm not positive that PeekNamedPipe can watch our write end
of the CGI's stdin pipe, the documentation contradicts that,
although it makes no sense on NT/2000. I don't believe we
want to hang on to a copy of the read end, from what I've
read. I'm picturing a simple test to determine if we will
flood the remaining space on our write pipe to kick off that
second thread.
This would all impact would be long processes (where the poor
user has *NO* idea that the server is doing anything) when
provided a fairly sizeable multipart form. It should NOT
impact the usual cases, since we don't want the resources
wasted.
Sorry if this is so sketchy... I will attack it once I get
an ACK or NAK on changing the #includes for precompiled
headers (this will involve a WHOLE LOT of recompiles and
debugging!)
Bill
Re: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> > Let me clarify this - a nameless pipe in Windows NT/2000 (NOT on 95/98)
> > _IS_A_NAMED_PIPE_! It is, in fact, a randomly named pipe.
>
> That may be so, but we searched at IBM for a couple of days to find the
> correct API's to make unnamed pipes non-blocking. We couldn't do it.
> Now, maybe we just missed the right function, but we couldn't do it. If
> you can find the API's to implement non-blocking I/O with unnamed pipes,
> send a patch. Regardless, we can always just have Apache generate the
> name itself.
>From MSDN CreatePipe() doc:
Windows NT/2000: Anonymous pipes are implemented using a named pipe with a
unique name. Therefore, you can often pass a handle to an anonymous pipe to
a function that requires a handle to a named pipe.
Presumably, one could use SetNamedPipeHandleState() to set the pipe
non-blocking by setting the mode to PIPE_NOWAIT. From the doc:
PIPE_NOWAIT ==> Nonblocking mode is enabled. In this mode, ReadFile,
WriteFile, and ConnectNamedPipe always return immediately. Note that
nonblocking mode is supported for compatibility with Microsoft® LAN Manager
version 2.0 and should not be used to achieve asynchronous input and output
(I/O) with named pipes.
Would be interesting to try this, but should we rely on it? I've not been
able to find a way to do async I/O (using the async I/O APIs) on an
"anonymous" NT pipe.
Bill
Re: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by rb...@apache.org.
> > If you look at
> > misc/win32, there is a function ap_get_oslevel. This function returns the
> > version of the operating system for windows.
>
> This will work and lends itself to extending generally across APR. Save the
> result in a static variable and you get around the performance hit as well.
The result is already stored in a static variable, so there is no
performance hit. I am still not convinced this is a good idea across all
platforms. I think if you want take advantage of 4.3.2 functions, we
sould be compiling for 4.3.2.
Ryan
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> This type of variable doesn't make any sense on a platform that figures
> out what version of the OS we are on at compile time.
I can envision cases where this could be useful on Unix platforms as well.
For instance, a binary compiled on AIX 4.2.1 will run on 4.3.2. However,
there are functions available on 4.3.2 (or fixed in 4.3.2) that are broken
or not available in 4.2.1. Your next comment satisfies me though.
> If you look at
> misc/win32, there is a function ap_get_oslevel. This function returns the
> version of the operating system for windows.
This will work and lends itself to extending generally across APR. Save the
result in a static variable and you get around the performance hit as well.
Bill
Re: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by rb...@apache.org.
This type of variable doesn't make any sense on a platform that figures
out what version of the OS we are on at compile time. If you look at
misc/win32, there is a function ap_get_oslevel. This function returns the
version of the operating system for windows. On any other platform that
does it's versioning at run-time, the function is portable. It happens to
be an apr specific function currently, which means the function can't be
called from outside of APR. However, if this function is necessary, we
can move it out of APR at any time.
Ryan
> This is something I wanted to discuss with Ryan at the conference just
> didn't get around to it. It would be nice to have a global variable defined
> in APR to identify the operating system and level. I'd prefer the global be
> as general as possible and not limited to Windows. The global would be
> initialized during APR init and should be available to the application at
> runtime. This is useful under Windows where we have one executable that can
> be run under Windows 95,98,NT and 2000. There are functions available under
> NT/2000 that are not available under 95/98 (e.g., TransmitFile, AcceptEx,
> GetQueuedCompletionStatus, et. al.) and we need a runtime check to determine
> if these functions are available before attempting to use them. It is easy
> enough to scatter around the code as needed, but it is a performance hit if
> we do it on the request path for each request.
>
> Bill
>
>
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> I'd rather not muck with our own uniquified names unless we are running on
> 95/98. If it's not there already I can throw together a version detection
> patch to share a ap_win32_is_nt flag.
This is something I wanted to discuss with Ryan at the conference just
didn't get around to it. It would be nice to have a global variable defined
in APR to identify the operating system and level. I'd prefer the global be
as general as possible and not limited to Windows. The global would be
initialized during APR init and should be available to the application at
runtime. This is useful under Windows where we have one executable that can
be run under Windows 95,98,NT and 2000. There are functions available under
NT/2000 that are not available under 95/98 (e.g., TransmitFile, AcceptEx,
GetQueuedCompletionStatus, et. al.) and we need a runtime check to determine
if these functions are available before attempting to use them. It is easy
enough to scatter around the code as needed, but it is a performance hit if
we do it on the request path for each request.
Bill
RE: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
Straight from the SDK;
Anonymous Pipes
[...]
Windows NT/2000: Anonymous pipes are implemented using a named pipe with a
unique name. Therefore, you can often pass a handle to an anonymous pipe to
a function that requires a handle to a named pipe.
ergo, SetNamedPipeHandleState does accept a handle returned from CreatePipe.
I hope this is what you were looking for.
I will be looking at a fully async CGI implementation shortly (at least
under NT), if noone else beats me to it. I'm not clear if the Linux port is
async, but it didn't appear to be, and seemed to lock also at 64KB
read+written.
I'd rather not muck with our own uniquified names unless we are running on
95/98. If it's not there already I can throw together a version detection
patch to share a ap_win32_is_nt flag.
Bill
> -----Original Message-----
> From: rbb@shell.ntrnet.net [mailto:rbb@shell.ntrnet.net]On Behalf Of
> rbb@apache.org
> Sent: Tuesday, March 14, 2000 8:37 AM
> To: new-httpd@apache.org
> Subject: RE: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
>
>
>
> > Let me clarify this - a nameless pipe in Windows NT/2000
> (NOT on 95/98)
> > _IS_A_NAMED_PIPE_! It is, in fact, a randomly named pipe.
>
> That may be so, but we searched at IBM for a couple of days
> to find the
> correct API's to make unnamed pipes non-blocking. We couldn't do it.
> Now, maybe we just missed the right function, but we couldn't
> do it. If
> you can find the API's to implement non-blocking I/O with
> unnamed pipes,
> send a patch. Regardless, we can always just have Apache generate the
> name itself.
>
> Ryan
>
>
> ______________________________________________________________
> _________________
> Ryan Bloom rbb@apache.org
> 406 29th St.
> San Francisco, CA 94131
> --------------------------------------------------------------
> -----------------
>
RE: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by rb...@apache.org.
> Let me clarify this - a nameless pipe in Windows NT/2000 (NOT on 95/98)
> _IS_A_NAMED_PIPE_! It is, in fact, a randomly named pipe.
That may be so, but we searched at IBM for a couple of days to find the
correct API's to make unnamed pipes non-blocking. We couldn't do it.
Now, maybe we just missed the right function, but we couldn't do it. If
you can find the API's to implement non-blocking I/O with unnamed pipes,
send a patch. Regardless, we can always just have Apache generate the
name itself.
Ryan
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
RE: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> From: rbb@shell.ntrnet.net [mailto:rbb@shell.ntrnet.net]On Behalf Of
> rbb@apache.org
> Sent: Monday, March 13, 2000 6:19 PM
> Can't get rid of the whole function, because Windows only supports
> non-blocking I/O on named pipes. This means that the CGI's
> communication
> must be over named pipes. We can always have the user
> specify a name, if
> that is what you want to do. I made it the way it was,
> because I wanted
> to be flexible. I have no problem always spcifying a name.
> I'll make the
> change ASAP.
>
> Ryan
>
Let me clarify this - a nameless pipe in Windows NT/2000 (NOT on 95/98)
_IS_A_NAMED_PIPE_! It is, in fact, a randomly named pipe.
Which leaves only the Q. of 95/98 and whatever other obscure implementation.
What about a locked, shared global long, and use it and a tick count for
process 'unique' handles (prepend the pid)?
I don't want to see us continue to waste the calls to randomize and pull a
named pipe out of a hat for NT, which can handle it just fine.
Bill
Re: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by rb...@apache.org.
Can't get rid of the whole function, because Windows only supports
non-blocking I/O on named pipes. This means that the CGI's communication
must be over named pipes. We can always have the user specify a name, if
that is what you want to do. I made it the way it was, because I wanted
to be flexible. I have no problem always spcifying a name. I'll make the
change ASAP.
Ryan
> > We use tempnam(3) in
> >
> > src/lib/apr/file_io/unix/pipe.c
>
> it's used only by ap_create_namedpipe()... the only implementations i see
> of named pipes use the random temp name functions... why isn't the caller
> specifying a name? i'd think that specifying a directory is about as
> non-portable as specifying a name is.
>
> maybe we can just delete this unused apr entry point and punt on the
> issue?
>
> Dean
>
>
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: Tempnam(3), Tempfile(3) vs mktemp(3) on BSD
Posted by Dean Gaudet <dg...@arctic.org>.
On Mon, 13 Mar 2000, Dirk-Willem van Gulik wrote:
> We use tempnam(3) in
>
> src/lib/apr/file_io/unix/pipe.c
it's used only by ap_create_namedpipe()... the only implementations i see
of named pipes use the random temp name functions... why isn't the caller
specifying a name? i'd think that specifying a directory is about as
non-portable as specifying a name is.
maybe we can just delete this unused apr entry point and punt on the
issue?
Dean