You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by David Wortham <dj...@gmail.com> on 2006/11/02 20:07:31 UTC

Data Structure Serialization

I'd like to know if anyone developing modules has run across a
struct-serialization function/library (in C, preferrably well tested with
the APR and multiple (file|operating) systems).  I am attempting to share
data across child processes, but I have a few bugs in my serialization
code.  I'm really just looking for code that creates a buffer string from a
struct and vice versa, but if it writes/reads to a file - all the better!  I
looked into the APR Shared Memory funtions, but it seems that developers can
not agree that the shared memory library is well supported, hence my desire
to write my own workaround.

Also, I am having problems opening a new file.  Perhaps there is a limit to
the number of files allowed to be opened from the same pool or the same
process?
I have one file that opens in a given function.  I need to open another file
and close it about the same time: just before the end of the same function.
I copy-pasted the code that correctly opens the first file but I am not
seeing the second file open (it is never created, whereas the first file is
created every time).  The purpose of the files are to (1) trace the
processing path and write to file the results of each conditional to file 1
and (2) dump the entire contents of the in-memory data structure to file 2.
I am having a hard time reconsiling what child process has what requesting
IP addresses stored in a recent-hit cache and these files seem like the only
way to debug this.

Any ideas for serialization or opening another file?  Or even just debugging
tips in general?  Apache seems like a difficult environment to debug in
seeing that my module is only deciding which requests to allow and which to
deny (it is similar to mod_(dos_)evasive, but will allow the child processes
to share cache data).

Thanks,
Dave

Re: Data Structure Serialization - debugging

Posted by Joachim Zobel <jz...@heute-morgen.de>.
Am Donnerstag, den 02.11.2006, 12:07 -0700 schrieb David Wortham:
> Any ideas for serialization or opening another file?  Or even just
> debugging
> tips in general?  Apache seems like a difficult environment to debug
> in

Just write a good trace log (with log level APR_DEBUG). If that is of
reasonable quality you can leave it in the code to serve you for
troubleshooting later.

The usual attitude to errors during development is to get rid of them as
fast as possible. This is wrong. Every error is a chance to test and
improve error handling.  

Sincerely,
Joachim



Re: Data Structure Serialization

Posted by Joachim Zobel <jz...@heute-morgen.de>.
Am Donnerstag, den 02.11.2006, 12:07 -0700 schrieb David Wortham:
> I have one file that opens in a given function.  I need to open
> another file
> and close it about the same time: just before the end of the same
> function.
> I copy-pasted the code that correctly opens the first file but I am
> not
> seeing the second file open (it is never created, whereas the first
> file is
> created every time).  The purpose of the files are to (1) trace the
> processing path and write to file the results of each conditional to
> file 1
> and (2) dump the entire contents of the in-memory data structure to
> file 2.
> I am having a hard time reconsiling what child process has what
> requesting
> IP addresses stored in a recent-hit cache and these files seem like
> the only
> way to debug this.

To alternatives come to my mind. 
1. You could write all data to the error log with ap_log_rerror. 
2. You could write your data into notes with the notes api and the log
these note with %{notename}n together with the pid and other interesting
data in a special custom log.

http://httpd.apache.org/docs/2.0/mod/mod_log_config.html#formats

To learn about notes read about ap_register_request_note,
ap_get_request_note in http_core.h. I have used them once, see
http://www.heute-morgen.de/modules/mod_delay/mod_delay.c for a simple
example.

Hth,
Joachim