[Melbourne-pm] Testing fork
Joshua Goodall
joshua at roughtrade.net
Tue Aug 24 18:18:24 CDT 2004
On Tue, Aug 24, 2004 at 07:56:58PM +1000, David Dick wrote:
> 2) The horrifying mutations that this code can be subjected to. For
> example, i'm writing the code as a cgi script to maximise portability.
> For speed, the code be run using Apache::Registry. Which, among other
> things silently overrides the exit statement, unless you fully qualify
> as CORE::exit. I'm damned if i know how, even if i know and expect the
> weird environmental conditions, that i can test that my code is correct
> in an environment such as Apache::Registry;
>
> 3) probably a whole lot of other issues that i'm not aware of yet.
I'm used to Apache killing off children that run for too long.
Why don't you write a real daemon instead? Your CGI can then just connect
to it, give it the appropriate parameters, then leave it to work. Give
it a couple of methods more for retrieving status/results, and then the
CGIs are just presentation wrappers for the API your daemon presents.
I suggest having it listen on a UNIX socket in /var/run/<packagename>
Three advantages:
i) The daemon can manage the workload queues e.g. a separate processing
thread/child process per CPU,
ii) You've decoupled the logic from the interface, so you can use it from
more than just a CGI (e.g. you can monitor current workload from
a command-line tool)
iii) You've separated the permissions between the presentation layer
and the logic layer. This is excellent for sidestepping a whole
raft of security issues.
Don't forget; to properly daemonise, reopen file descriptors 0,1,2
to /dev/null (don't just close them - it can cause problems if you
exec subprocesses that expect them to be stdin/out/err), call setsid
(to create a new session, a new process group, and remove references
to any controlling terminal), and talk to syslog. There's a wrapper
in CPAN for all that, but I forget the name.
J
--
Joshua Goodall "as modern as tomorrow afternoon"
joshua at roughtrade.net - FW109
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/melbourne-pm/attachments/20040825/a7fa92fb/attachment.bin
More information about the Melbourne-pm
mailing list