www-apache-bugdb mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig Soules <csou...@intraactive.com>
Subject apache-api/5639: Global variables unavailable due to fork()
Date Tue, 25 Jan 2000 06:00:02 GMT

>Number:         5639
>Category:       apache-api
>Synopsis:       Global variables unavailable due to fork()
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Class:          sw-bug
>Submitter-Id:   apache
>Arrival-Date:   Mon Jan 24 22:10:00 PST 2000
>Originator:     csoules@intraactive.com
>Release:        1.3.9 (although most likely all versions)
Linux 2.2.14, egcs-2.91.66, i686
I'm not quite sure this is a bug, so much as a flaw, but I would at least like to see this
documented somewhere on your site.

The main problem is that when writing a module in C with the API, the module can have no globally
modifiable data, since the different server threads are created using standard fork() rather
than a shared fork, or pthreads.
This makes it impossible to keep any global state that can be modified on the fly (for example
a database connection cache, or site configuration information in memory)
Please, please at least document this somewhere.
Thank you for your time.

Craig Soules
Yes.  simply write a module that uses a global variable, set it to 0 in the init function,
and then have the handler set the variable to a random number and never reset it.
The numbers will be different, depending upon which server thread handles your request.
Either use pthreads, or clone() under linux, rather than fork/vfork.
 [In order for any reply to be added to the PR database, you need]
 [to include <apbugs@Apache.Org> in the Cc line and make sure the]
 [subject line starts with the report component and number, with ]
 [or without any 'Re:' prefixes (such as "general/1098:" or      ]
 ["Re: general/1098:").  If the subject doesn't match this       ]
 [pattern, your message will be misfiled and ignored.  The       ]
 ["apbugs" address is not added to the Cc line of messages from  ]
 [the database automatically because of the potential for mail   ]
 [loops.  If you do not include this Cc, your reply may be ig-   ]
 [nored unless you are responding to an explicit request from a  ]
 [developer.  Reply only with text; DO NOT SEND ATTACHMENTS!     ]

View raw message