I'm currently reading the book "The Apache Modules Book" to learn writing Apache2 modules. I tried some examples from the book and in one case I get a segmentation fault, even if I completely copy&paste the source file from the author's website.
The example is an output filter that works on a request for a *.txt file, adds a html header and footer with the html-escaped content of the requested txt file in between.
The sourcecode is available under: http://apache.webthing.com/mod_txt/
The error in apache's log file is the following:
[Thu Jan 12 20:38:01 2012] [notice] child pid 3500 exit signal Segmentation fault (11)
I installed the module using the following commands:
apxs2 -c mod_txt.c
sudo apxs2 -i mod_txt.la
sudo service apache2 restart
There are no compile-errors when using apxs2.
I added the Filter in the httpd.conf file as follows:
LoadModule txt_module /usr/lib/apache2/modules/mod_txt.so
AddOutputFilter text-filter .txt
AddType text/html .txt
TextHeader /home/robert/header.txt
TextFooter /home/robert/footer.txt
Is there anything wrong with the code or am I doing something wrong with comiling/installing/configuring the filter?
My System: Ubuntu Lucid Lynx 10.04.3 with Apache 2.2.14 installed from the default Ubuntu repository.
I'd really appreciate any hint on this!
Thanks in advance!
Best regards, Robert
[Edit] Some additional information:
I used gdb to get some more info on where the segfault happens. Is there any way I can get the exact line number?
This is the output:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xab472b70 (LWP 4041)]
0xb7d3fb9b in txt_filter () from /usr/lib/apache2/modules/mod_txt.so
(gdb) bt
#0 0xb7d3fb9b in txt_filter () from /usr/lib/apache2/modules/mod_txt.so
#1 0x00154150 in ap_pass_brigade (next=0x2e3198, bb=0xb7f4fff4)
at /build/buildd/apache2-2.2.14/server/util_filter.c:526
#2 0x00141147 in default_handler (r=0x2e4ea8)
at /build/buildd/apache2-2.2.14/server/core.c:3757
#3 0x00148321 in ap_run_handler (r=0x2e4ea8)
at /build/buildd/apache2-2.2.14/server/config.c:159
#4 0x0014c107 in ap_invoke_handler (r=0x2e4ea8)
at /build/buildd/apache2-2.2.14/server/config.c:373
#5 0x0015b6b8 in ap_process_request (r=0x2e4ea8)
at /build/buildd/apache2-2.2.14/modules/http/http_request.c:282
#6 0x001581e8 in ap_process_http_connection (c=0x2defd0)
at /build/buildd/apache2-2.2.14/modules/http/http_core.c:190
#7 0x00150b91 in ap_run_process_connection (c=0x2defd0)
at /build/buildd/apache2-2.2.14/server/connection.c:43
#8 0x0016249b in process_socket (thd=0x2a7958, dummy=0x2dda00)
at /build/buildd/apache2-2.2.14/server/mpm/worker/worker.c:544
#9 worker_thread (thd=0x2a7958, dummy=0x2dda00)
at /build/buildd/apache2-2.2.14/server/mpm/worker/worker.c:894
#10 0xb7f781e1 in ?? () from /usr/lib/libapr-1.so.0
#11 0xb7f3f96e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#12 0xb7eada4e in clone () from /lib/tls/i686/cmov/libc.so.6
More specialized debugging tutorial for apache modules may be found in the book you're reading (Chapter 12).
Currently I'm running the same hardware/software configuration (apache 2.2.14) on Ubuntu Lucid Lynx and successfully compiled/run the module.
In the folder /var/www/ I've put an HTML document but only changed it's extension to .txt and access it through my browser (localhost/some-html.txt) and the output (depending on the tags you've put in header and footer files) was successfully represented (as preformated text because I've used
<pre>
and</pre>
tags in my header and footer files respectively.)