You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Roy T. Fielding" <fi...@kiwi.ICS.UCI.EDU> on 2000/05/18 07:34:57 UTC
pid or proc
I started to fix a bug in mpmt_pthread.c where a pid variable is being
printed as an int even though it is actually a pointer to a proc which
points to an incomplete struct type that contains a pid. Unfortunately,
the easy fix wouldn't work because you can't just dereference an
incomplete type to get the pid from the proc. Bummer. Then I noticed
that there are several cases where a pid variable is used and defined as
an int, even though it should always be defined as a pid_t. Well, that
sucks. So I continued on to see if I should change the pid type of the
first pid to be complete so that I can access it directly, or define an
access function like
long ap_pid_long(ap_proc_t *pid);
which just seemed to go one pid further than was worth piddling over.
Of course, I'd prefer that it just return pid_t, but that would require
adding another formatting variable to snprintf in order to avoid that
other warning on Solaris (which, after all, doesn't have int pids).
But that got me thinking... why the heck do we have this other ap_proc_t
type anyway when the only useful thing we do with it is store a pid?
Onward to the code in apr/threadproc, which unfortunately lacks any
overview comments that would explain why this thing might be useful,
it would seem that ap_proc_t is being used for process-local storage,
or at least that's my best guess. At least in some places it is.
There are also some places there where pid is defined as an int
and proc just doesn't even enter the picture.
So, I am stumped. To fill out the documentation, I have a few Qs:
1) define ap_proc_t as an abstract data type:
-- what is its purpose;
-- what does it contain, and why;
-- what is the expected lifetime of an instance (i.e., is there
some expectations regarding its creation/destruction that I
need to know before I go fiddling with it) especially in
regard to its pool;
-- how is it likely to differ across platforms.
2) pid_t is the only reasonable way to identify a process, even on
platforms that have no pid_t, so the user is going to need access
to this component regardless of how ap_proc_t is implemented.
What is the right way to grant that access?
....Roy
Re: pid or proc
Posted by Manoj Kasichainula <ma...@io.com>.
On Thu, May 18, 2000 at 06:46:11AM -0400, Jeff Trawick wrote:
> If somebody will tell me where to put common code for Unix MPMs I'll
> start moving code there.
src/os/unix. Probably unixd.c.
Re: pid or proc
Posted by rb...@covalent.net.
> Another disturbing aspect of this problem is the duplication of it
> across the Unix MPMs. I should have fixed the pointer-as-int problem
> when I fixed it in prefork (assuming we're talking about the same
> one), but for one reason or another it didn't occur to me to look; I
> was just reacting to the compile warning that was in front of me.
This is the second stage of my duplication cleanup, which starts today. I
am moving all of the common MPM code out of the individual MPM
directories. Either into main, or the os/foo, or into the modules/mpm
directory, as appropriate.
Before anybody yells at me for not putting this in the STATUS file, I
decided to do this Tuesday night after some of Roy's comments, I made it
clear on the list, and then I started doing the work yesterday.
Ryan
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------
Re: pid or proc
Posted by Jeff Trawick <tr...@bellsouth.net>.
> Mailing-List: contact new-httpd-help@apache.org; run by ezmlm
> Precedence: bulk
> X-No-Archive: yes
> Reply-To: new-httpd@apache.org
> list-help: <ma...@apache.org>
> list-unsubscribe: <ma...@apache.org>
> list-post: <ma...@apache.org>
> Date: Wed, 17 May 2000 22:34:57 -0700
> From: "Roy T. Fielding" <fi...@kiwi.ICS.UCI.EDU>
> X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N
> X-UIDL: f32525db53d0604290c155d144b3a130
>
> I started to fix a bug in mpmt_pthread.c where a pid variable is being
> printed as an int even though it is actually a pointer to a proc which
> points to an incomplete struct type that contains a pid.
I fixed the same bug in prefork.c recently (assuming that we're
talking about the same one), and I noticed yesterday that it needs to
be fixed in dexter.c. I didn't realize that it was in mpmt_pthread.c
too.
See
http://www.apache.org/websrc/viewcvs.cgi/apache-2.0/src/modules/mpm/prefork/prefork.c.diff?r1=1.82&r2=1.83
> Unfortunately,
> the easy fix wouldn't work because you can't just dereference an
> incomplete type to get the pid from the proc. Bummer.
Note that there is an ap_get_os_proc() function to get the
platform-specific process id from an ap_proc_t.
> Then I noticed
> that there are several cases where a pid variable is used and defined as
> an int, even though it should always be defined as a pid_t. Well, that
> sucks. So I continued on to see if I should change the pid type of the
> first pid to be complete so that I can access it directly, or define an
> access function like
>
> long ap_pid_long(ap_proc_t *pid);
>
> which just seemed to go one pid further than was worth piddling over.
> Of course, I'd prefer that it just return pid_t, but that would require
> adding another formatting variable to snprintf in order to avoid that
> other warning on Solaris (which, after all, doesn't have int pids).
>
One could define AP_PID_FMT to "%d" or something else as appropriate.
Another disturbing aspect of this problem is the duplication of it
across the Unix MPMs. I should have fixed the pointer-as-int problem
when I fixed it in prefork (assuming we're talking about the same
one), but for one reason or another it didn't occur to me to look; I
was just reacting to the compile warning that was in front of me.
If somebody will tell me where to put common code for Unix MPMs I'll
start moving code there. I made some changes last night spread across
the three, and I need to do some more today to get rid of a storage
leak in the use of ap_proc_t with ap_wait_all_procs().
I'd be happy to have a .c and a .h for common code in
modules/mpm/mpmt_pthread/ and have those referenced directly from
dexter and prefork. Alternatively, we could have modules/mpm/mpm_util
with a module and a header file in there.
--
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
http://www.geocities.com/SiliconValley/Park/9289/
Born in Roswell... married an alien...
Re: pid or proc
Posted by rb...@covalent.net.
> long ap_pid_long(ap_proc_t *pid);
>
> which just seemed to go one pid further than was worth piddling over.
> Of course, I'd prefer that it just return pid_t, but that would require
> adding another formatting variable to snprintf in order to avoid that
> other warning on Solaris (which, after all, doesn't have int pids).
This has already been implemented. Try looking at the
ap_get_os_proc() call in apr_portable.h
> But that got me thinking... why the heck do we have this other ap_proc_t
> type anyway when the only useful thing we do with it is store a pid?
> Onward to the code in apr/threadproc, which unfortunately lacks any
> overview comments that would explain why this thing might be useful,
The comments were there at one point, and for the most part, the overview
comments and why this thing is useful are all in the API docs, which have
been moved to apr_threadproc.h
Now, as far as the only useful thing being to store a pid. This is just
plain wrong. Yes, on Unix the only useful thing is to store a pid,
because the programmer can handle the rest themselves. On other
platforms, like say... Windows, where the programmer can't do anything
between the fork and exec, there is a lot of useful stuff that can be
stored in an ap_proc_t. The goal of APR is NOT to make every platform
look like Unix, because you can't do that, I tried for the first
month. The goal of APR is to make all platforms look alike, and to have
the resemble POSIX where _possible_. When it comes to processes, that's
just not possible.
To see what other useful stuff can be in the ap_proc_t variables, take a
look at the pipes that are associated with a proc_attr, which is in turn
associated with the proc. Or, how about the directory to switch to after
forking?
> it would seem that ap_proc_t is being used for process-local storage,
> or at least that's my best guess. At least in some places it is.
> There are also some places there where pid is defined as an int
> and proc just doesn't even enter the picture.
Those are bugs.
> So, I am stumped. To fill out the documentation, I have a few Qs:
>
> 1) define ap_proc_t as an abstract data type:
> -- what is its purpose;
> -- what does it contain, and why;
See above, and the code, and the docs which have been placed in
apr_threadproc.h.
> -- what is the expected lifetime of an instance (i.e., is there
> some expectations regarding its creation/destruction that I
> need to know before I go fiddling with it) especially in
> regard to its pool;
A process lives as long as it's pool. When the pool's cleanups are
called, the process should be killed. This may not currently be
happening, I have forgotten.
> -- how is it likely to differ across platforms.
In all sorts of ways, but the biggest differences are implementation
details. On Unix the ap_proc_t's have a pid, on BeOS, it is called a pid,
but it is really a thread_id, On Windows the ap_proc_t has a
PROCESS_INFORMATION pointer, which I assume has a pid internally.
This BTW, is why we are using incomplete types. It is a whole lot easier
to just tell people they can't have access to a certain type then to try
to figure out how that type maps to each platform's individual types.
> 2) pid_t is the only reasonable way to identify a process, even on
> platforms that have no pid_t, so the user is going to need access
> to this component regardless of how ap_proc_t is implemented.
> What is the right way to grant that access?
Please tell MS and BeOS that they are idiots then, because they seem to
disagree with you.
Ryan
_______________________________________________________________________________
Ryan Bloom rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------