Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-05

Apache module with fpc 2.4.x on Apache 2.2.x (64bit)

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Takashi Ishikawa

Hello, all

I'm writing apache module with fpc.

When I compile my program on fpc 2.4.4, Apache terminate immediately. But on fpc 2.2.4, Apache and my module will work fine.

Code is compiled with no problem. Apache can load module. But the running has problem.

Is there anyone who running a module compiled with fpc 2.4.x on Apache?

I tested some envirment:
- OS: CentOS 5.5 / Fedora 12
- Apache: 2.2.3 / 2.2.17
- Arch: x86_64
- FPC: 2.2.4 / 2.4.2 / 2.4.4

Test code:
-----
library lib_mod_simple;

{$ifdef fpc}
   {$mode objfpc}{$H+}
{$endif}
uses SysUtils, httpd, apr;
var
  mod_simple: module; public name 'mod_simple';
exports
   mod_simple name 'mod_simple';
function DefaultHandler(r: Prequest_rec): Integer; cdecl;
begin
   Result := DECLINED;
end;
procedure RegisterHooks(p: Papr_pool_t); cdecl;
begin
   ap_hook_handler(@DefaultHandler, nil, nil, APR_HOOK_MIDDLE);
end;
begin
   FillChar(mod_simple, SizeOf(mod_simple), 0);
   STANDARD20_MODULE_STUFF(mod_simple);
   with mod_simple do
   begin
     name := 'mod_simple.so';
     register_hooks := @RegisterHooks;
   end;
end.
-----

Compilation options:
-----
fpc -Xs -XX -fPIC -dFPCAPACHE_2_2 -omod_simple.so mod_simple.pas -----

LoadModule in httpd.conf:
-----
LoadModule mod_simple modules/mod_simple.so
-----

Test#1 with CentOS 5.5, Apache 2.2.3, FPC 2.2.4
-----
# gdb httpd
(gdb) r -X

Starting program: /usr/sbin/httpd -X
[Thread debugging using libthread_db enabled]
Detaching after fork from child process 28066.
Detaching after fork from child process 28080.

-----

Test#2 with CentOS 5.5, Apache 2.2.3, FPC 2.4.4
-----
# gdb httpd
(gdb) r -X

Starting program: /usr/sbin/httpd -X
[Thread debugging using libthread_db enabled]
Detaching after fork from child process 28119.

Program exited normally.

(gdb)
-----

Test with CentOS 5.5, Apache 2.2.3, FPC 2.4.2
Test with CentOS 5.5, Apache 2.2.3, FPC 2.4.4
Test with Fedora 12, Apache 2.2.17, FPC 2.4.4
same as Test#2

In test#1, it seemed to be success. When I access the webserver with browser, apache respond normal page.

In test#2, apache shows no error. But process terminate. And when I accessed the webserver, apache didn't respond.

It is possible to develop by using FPC 2.2.4. However, the future, I want to compile with a newer version of FPC. Is there any idea to running module with FPC 2.4.x?

Thanks,
Takashi

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Takashi Ishikawa SimpleWay Corporation
ABorka
to Takashi Ishikawa
Takashi Ishikawa wrote 116 lines
Hello, all I'm writing apache module with fpc. When I compile my program on fpc 2.4.4, Apache terminate immediately. But on fpc 2.2.4, Apache and my module will work fine. Code is compiled with no problem. Apache can load module. But the running has problem. Is there anyone who running a module compiled with fpc 2.4.x on Apache? I tested some envirment: - OS: CentOS 5.5 / Fedora 12 - Apache: 2.2.3 / 2.2.17 - Arch: x86_64 - FPC: 2.2.4 / 2.4.2 / 2.4.4 Test code: ----- library lib_mod_simple; {$ifdef fpc} {$mode objfpc}{$H+} {$endif} uses SysUtils, httpd, apr; var mod_simple: module; public name 'mod_simple'; exports mod_simple name 'mod_simple'; function DefaultHandler(r: Prequest_rec): Integer; cdecl; begin Result := DECLINED; end; procedure RegisterHooks(p: Papr_pool_t); cdecl; begin ap_hook_handler(@DefaultHandler, nil, nil, APR_HOOK_MIDDLE); end; begin FillChar(mod_simple, SizeOf(mod_simple), 0); STANDARD20_MODULE_STUFF(mod_simple); with mod_simple do begin name := 'mod_simple.so'; register_hooks := @RegisterHooks; end; end. ----- Compilation options: ----- fpc -Xs -XX -fPIC -dFPCAPACHE_2_2 -omod_simple.so mod_simple.pas ----- LoadModule in httpd.conf: ----- LoadModule mod_simple modules/mod_simple.so ----- Test#1 with CentOS 5.5, Apache 2.2.3, FPC 2.2.4 ----- # gdb httpd (gdb) r -X Starting program: /usr/sbin/httpd -X [Thread debugging using libthread_db enabled] Detaching after fork from child process 28066. Detaching after fork from child process 28080. ----- Test#2 with CentOS 5.5, Apache 2.2.3, FPC 2.4.4 ----- # gdb httpd (gdb) r -X Starting program: /usr/sbin/httpd -X [Thread debugging using libthread_db enabled] Detaching after fork from child process 28119. Program exited normally. (gdb) ----- Test with CentOS 5.5, Apache 2.2.3, FPC 2.4.2 Test with CentOS 5.5, Apache 2.2.3, FPC 2.4.4 Test with Fedora 12, Apache 2.2.17, FPC 2.4.4 same as Test#2 In test#1, it seemed to be success. When I access the webserver with browser, apache respond normal page. In test#2, apache shows no error. But process terminate. And when I accessed the webserver, apache didn't respond. It is possible to develop by using FPC 2.2.4. However, the future, I want to compile with a newer version of FPC. Is there any idea to running module with FPC 2.4.x? Thanks, Takashi

There were problems with apache modules that were fixed in the latest FPC SVN (bug report 19184).
If you do not want to use the SVN versions of FPC/Lazarus, you can just download the latest packages/fcl-web/src/base/ files from SVN into your project directory and recompile your project.

Also, make sure you compile with the httpd22 directory and that FPC/Lazarus is not accidentally uses httpd13 or httpd20 . The best if you just delete these two directories from your fpc units directory.

AB

Takashi Ishikawa
to ABorka

Thanks for telling me a ticket.

In fact, I had already read the code of 'fpapache' unit.

According to the patch of ticket, registration of the hook seems to have been fixed.

By the way, in the test code does not use TCustomApacheApplication. The code which register hook is also written. (And my program is not using fpWeb)

The error that exists in the ticket is not displayed. Seemingly, start of httpd seems to success. However, the process terminate immediately.

Is there another possible cause?

Takashi

ABorka wrote 133 lines
On 5/26/2011 13:36, Takashi Ishikawa wrote: > Hello, all > > I'm writing apache module with fpc. > > When I compile my program on fpc 2.4.4, Apache terminate immediately. > But on fpc 2.2.4, Apache and my module will work fine. > > Code is compiled with no problem. Apache can load module. But the > running has problem. > > Is there anyone who running a module compiled with fpc 2.4.x on Apache? > > > I tested some envirment: > - OS: CentOS 5.5 / Fedora 12 > - Apache: 2.2.3 / 2.2.17 > - Arch: x86_64 > - FPC: 2.2.4 / 2.4.2 / 2.4.4 > > > Test code: > ----- > library lib_mod_simple; > > {$ifdef fpc} > {$mode objfpc}{$H+} > {$endif} > > uses SysUtils, httpd, apr; > > var > mod_simple: module; public name 'mod_simple'; > > exports > mod_simple name 'mod_simple'; > > function DefaultHandler(r: Prequest_rec): Integer; cdecl; > begin > Result := DECLINED; > end; > > procedure RegisterHooks(p: Papr_pool_t); cdecl; > begin > ap_hook_handler(@DefaultHandler, nil, nil, APR_HOOK_MIDDLE); > end; > > begin > FillChar(mod_simple, SizeOf(mod_simple), 0); > STANDARD20_MODULE_STUFF(mod_simple); > with mod_simple do > begin > name := 'mod_simple.so'; > register_hooks := @RegisterHooks; > end; > end. > ----- > > > Compilation options: > ----- > fpc -Xs -XX -fPIC -dFPCAPACHE_2_2 -omod_simple.so mod_simple.pas > ----- > > > LoadModule in httpd.conf: > ----- > LoadModule mod_simple modules/mod_simple.so > ----- > > > Test#1 with CentOS 5.5, Apache 2.2.3, FPC 2.2.4 > ----- > # gdb httpd > (gdb) r -X > > Starting program: /usr/sbin/httpd -X > [Thread debugging using libthread_db enabled] > Detaching after fork from child process 28066. > Detaching after fork from child process 28080. > > ----- > > > Test#2 with CentOS 5.5, Apache 2.2.3, FPC 2.4.4 > ----- > # gdb httpd > (gdb) r -X > > Starting program: /usr/sbin/httpd -X > [Thread debugging using libthread_db enabled] > Detaching after fork from child process 28119. > > Program exited normally. > > (gdb) > ----- > > Test with CentOS 5.5, Apache 2.2.3, FPC 2.4.2 > Test with CentOS 5.5, Apache 2.2.3, FPC 2.4.4 > Test with Fedora 12, Apache 2.2.17, FPC 2.4.4 > same as Test#2 > > > In test#1, it seemed to be success. When I access the webserver with > browser, apache respond normal page. > > In test#2, apache shows no error. But process terminate. And when I > accessed the webserver, apache didn't respond. > > > It is possible to develop by using FPC 2.2.4. However, the future, I > want to compile with a newer version of FPC. Is there any idea to > running module with FPC 2.4.x? > > Thanks, > Takashi There were problems with apache modules that were fixed in the latest FPC SVN (bug report 19184). If you do not want to use the SVN versions of FPC/Lazarus, you can just download the latest packages/fcl-web/src/base/ files from SVN into your project directory and recompile your project. Also, make sure you compile with the httpd22 directory and that FPC/Lazarus is not accidentally uses httpd13 or httpd20 . The best if you just delete these two directories from your fpc units directory. AB _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
ABorka
to Takashi Ishikawa

...<snip>...

Show quoted text 6 lines
The error that exists in the ticket is not displayed. Seemingly, start of httpd seems to success. However, the process terminate immediately. Is there another possible cause? Takashi

If you compile with the proper HTTPD directory (httpd22 in this case), it should work.
No error message in the apache error.log? Apache always says something when the startup is not successful.

Your small example library code is working here (Ubuntu 10.10, FPC 2.5.1 SVN), httpd13 and httpd20 directories are deleted. Compiled with: fpc -Xs -XX -fPIC -omod_simple.so mod_simple.pas Apache starts, runs, pages are served properly with the mod_simple.so loaded .

AB

Takashi Ishikawa
to ABorka

Thanks for checking code.

If you compile with the proper HTTPD directory (httpd22 in this case),

Yes, I used httpd22, too. httpd20 and httpd13 was deleted.

No error message in the apache error.log? Apache always says something when the startup is not successful.

Apache doesn't say any errors in both test#1 and test#2. But startup messages are shorter than usual in test#2.

test#1
-----
[notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [notice] Digest: generating secret for digest authentication ... [notice] Digest: done
-----

test#2
-----
[notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) -----

After them I checked httpd log in debug mode.
-----
# httpd -e debug
-----

Apache output below:
-----
[notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [debug] mod_so.c(246): loaded module auth_basic_module : (Apache standard modules)
[debug] mod_so.c(246): loaded module mod_simple
-----

Apache terminate after 'loaded module mod_simple'.

I just tried on CentOS 32bit, but the result was same.

Hmm... I wonder if there are some problem in my environment.

I use CentOS to compile. The test was performed at Fedora, but the module was compiled on CentOS.

So, I have to try compiling on Fedora. And I will also try on Ubuntu and FPC 2.5.x.

Takashi

ABorka wrote 24 lines
...<snip>... >The error that exists in the ticket is not displayed. Seemingly, start > of httpd seems to success. However, the process terminate immediately. > > Is there another possible cause? > > Takashi If you compile with the proper HTTPD directory (httpd22 in this case), it should work. No error message in the apache error.log? Apache always says something when the startup is not successful. Your small example library code is working here (Ubuntu 10.10, FPC 2.5.1 SVN), httpd13 and httpd20 directories are deleted. Compiled with: fpc -Xs -XX -fPIC -omod_simple.so mod_simple.pas Apache starts, runs, pages are served properly with the mod_simple.so loaded . AB _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marco van de Voort
to ABorka: ...<snip>... If you compile with the proper HTTPD directory (httpd22 in this case), it…

In our previous episode, ABorka said:

Show quoted text 15 lines
> > Is there another possible cause? > > Takashi If you compile with the proper HTTPD directory (httpd22 in this case), it should work. No error message in the apache error.log? Apache always says something when the startup is not successful. Your small example library code is working here (Ubuntu 10.10, FPC 2.5.1 SVN), httpd13 and httpd20 directories are deleted. Compiled with: fpc -Xs -XX -fPIC -omod_simple.so mod_simple.pas Apache starts, runs, pages are served properly with the mod_simple.so loaded .

(Since it was a minimal change I merged that fix to 2.4.5 in case sb wants to stay with stable. But the 2.4 branch roughly reflects the state of March 1st, so other "web" related patches are not (yet) in it)

Takashi Ishikawa
to Takashi Ishikawa: Thanks for checking code. Yes, I used httpd22, too. httpd20 and httpd13 was deleted.…

The problem was solved.

I tried FPC 2.5.x, and the module worked fine!

I used 'Daily Source Snapshot' on 2011/05/27. I tried with only changing FPC version, other conditions(OS, apache and code) are not changed.

Thanks a lot!

Takashi

Takashi Ishikawa wrote 84 lines
Thanks for checking code. > If you compile with the proper HTTPD directory (httpd22 in this case), Yes, I used httpd22, too. httpd20 and httpd13 was deleted. > No error message in the apache error.log? Apache always says something > when the startup is not successful. Apache doesn't say any errors in both test#1 and test#2. But startup messages are shorter than usual in test#2. test#1 ----- [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [notice] Digest: generating secret for digest authentication ... [notice] Digest: done ----- test#2 ----- [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) ----- After them I checked httpd log in debug mode. ----- # httpd -e debug ----- Apache output below: ----- [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [debug] mod_so.c(246): loaded module auth_basic_module : (Apache standard modules) [debug] mod_so.c(246): loaded module mod_simple ----- Apache terminate after 'loaded module mod_simple'. I just tried on CentOS 32bit, but the result was same. Hmm... I wonder if there are some problem in my environment. I use CentOS to compile. The test was performed at Fedora, but the module was compiled on CentOS. So, I have to try compiling on Fedora. And I will also try on Ubuntu and FPC 2.5.x. Takashi On Fri, 27 May 2011 08:44:59 +0900, ABorka wrote: > ...<snip>... > >The error that exists in the ticket is not displayed. Seemingly, start > > of httpd seems to success. However, the process terminate > immediately. > > > > Is there another possible cause? > > > > Takashi > > If you compile with the proper HTTPD directory (httpd22 in this case), > it should work. > No error message in the apache error.log? Apache always says something > when the startup is not successful. > > Your small example library code is working here (Ubuntu 10.10, FPC > 2.5.1 SVN), httpd13 and httpd20 directories are deleted. > Compiled with: fpc -Xs -XX -fPIC -omod_simple.so mod_simple.pas > Apache starts, runs, pages are served properly with the mod_simple.so > loaded . > > AB > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal