<div dir="ltr">Hello Tomas,<br><br>thank you very much for help, but still not working.<br>I put hooks function into .kl1 file.<br>Got your code for connection to DB (using PostgreSQL).<br>I'm using Klone <a href="http://2.1.0.">2.1.0.</a><br>
My top-level Makefile is:<br>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br>-include Makefile.conf<br>KLONE_VERSION ?= 2.1.0<br>KLONE_CONF_ARGS ?= \<br> --prefix=$(DESTDIR) \<br> --enable_hooks \<br> --libs=$(DESTDIR) <br>
WEBAPP_CFLAGS ?= -I$(KLONE_APP_TOP) -I$(KLONE_SRC) <br>WEBAPP_LDADD ?= <br>WEBAPP_LDFLAGS ?= -lpq<br>-include build/mk/<a href="http://klone-app.mk">klone-app.mk</a><br>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br>
As you can see I've added enable_hooks key to Makefile (I did it for configure step before and have error).<br>Also I've changed your code for PQsetdbLogin as:<br>dbg_err_ifm ((pg_conn = PQsetdbLogin(...))) == NULL,"connection error: setdbLogin");<br>
And didn't see the message in logs,<br>Then I've added 2 rows in .kl1 to see if this function run:<br><br> info ("Before login");<br> dbg_err_ifm (1,"Before login");<br><br>But see nothing like this in logs.<br>
Only what I see in logs is:<br>Sep 11 13:17:25 ok : [wrn][13597:broker.c:105:broker_create] CGI support disabled, use --enable_cgi to enable it <br>Sep 11 13:17:25 ok : [wrn][13597:broker.c:112:broker_create] File system support disabled, use --enable_fs to enable it<br>
<br>So I think hooks are not wokring for me. Somewhere I'm wrong, but I don not know where.<br><br>My .kl1 file is:<br>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br><%!<br>#include <klone/klone.h><br>#include <postgresql/libpq-fe.h><br>
#include <u/libu.h><br><br>PGconn *pg_conn;<br>PGresult *res;<br><br>int pg_connect(void) {<br> // e.g. connect to postgres DB<br><br> info ("Before login");<br> dbg_err_ifm (1,"Before login");<br>
dbg_err_ifm ((pg_conn = PQsetdbLogin(...)) == NULL,"connection error: setdbLogin");<br><br> dbg_err_ifm (PQstatus(pg_conn) != CONNECTION_OK,<br> "connection error: %s", PQerrorMessage(pg_conn));<br>
<br> info("pg (%s:%s) connected on socket %d", PQhost(pg_conn), PQport(pg_conn),<br> PQsocket(pg_conn));<br><br> return 0;<br>err:<br> return ~0;<br>}<br><br>int child_init(void)<br>{<br> /* a new child has been forked, tear-up the always on DB connection */<br>
pg_connect();<br> return 0;<br>}<br><br>int child_term(void) {<br> PQfinish(pg_conn);<br> return 0;<br>}<br><br>void hooks_setup(void)<br>{<br> /* set hooks */<br> hook_child_init( child_init );<br>
hook_child_term( child_term );<br>}<br>%><br>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br>
And it's placed in webapp/www/<br><br>Any ideas?<br><br>Thanks a lot,<br>Oleg.<br><br><br><div class="gmail_quote">On Thu, Sep 11, 2008 at 1:12 AM, thomas fossati <span dir="ltr"><<a href="mailto:tho@koanlogic.com">tho@koanlogic.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Oleg,<div class="Ih2E3d"><br>
<br>
On Sep 10, 2008, at 10:26 PM, Oleg Kobyakovskiy wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
reading manual about hooks and see next:<br>
"Developers can let Klone call their own functions on interesting events (see below). To enable this functionality Klone must be configured with –enable_hooks. When compiled this way Klone will call hooks_setup() to gived the user the opportunity to register his hooks."<br>
So I tried to configure klone with --enable_hooks flag. But got this error:<br>
<br>
[err] Failed command: 'enable_hooks'!<br>
</blockquote>
<br></div>
which klone version are you using ?<br>
<br>
Could you please provide your top-level Makefile ?<div class="Ih2E3d"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'd like to make the connection to DB in child_init process.<br>
Looks like I don't connect there. How can I see is it connected or not?<br>
</blockquote>
<br></div>
1) write the code that handles DB connection setup:<br>
<br>
int your_db_init_func(void)<br>
{<br>
// e.g. connect to postgres DB<br>
<br>
dbg_err_if (PQsetdbLogin(...) == NULL);<br>
<br>
dbg_err_ifm (PQstatus(...) != CONNECTION_OK,<br>
"connection error: %s", PQerrorMessage(...));<br>
<br>
info("pg (%s:%s) connected on socket %d", PQhost(...), PQport(...),<br>
PQsocket(...));<br>
<br>
return 0;<br>
err:<br>
return ~0;<br>
}<br>
<br>
2) provide a lib with an hooks_setup() function:<br>
<br>
void hooks_setup(void)<br>
{<br>
(void) hook_child_init(your_db_init_func);<br>
// perhaps other hooks (e.g. db connection teardown, ...)<br>
return;<br>
}<br>
<br>
and let it link to the kloned executable by adding the path of the lib via WEBAPP_LDADD.<br>
<br>
See <a href="http://www.koanlogic.com/download/klone/klapp-auth-simple-1.2.0.tar.gz" target="_blank">http://www.koanlogic.com/download/klone/klapp-auth-simple-1.2.0.tar.gz</a> - expecially auth-hooks/auth_hooks.c and Makefile - as a starting point.<div class="Ih2E3d">
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Also in some examples I found something like dbg_err_if.<br>
What is it and where can I foud info about error debuging?<br>
</blockquote>
<br></div>
dbg_xxx_if comes from libu's carpal module: please see <a href="http://wiki.koanlogic.com/doku.php?id=libu_carpal" target="_blank">http://wiki.koanlogic.com/doku.php?id=libu_carpal</a> for an overview.<br>
<br>
Basically when you configure your klapp with --enable_debug, a log message with priority DEBUG is routed through syslog (*) in case a dbg_xxx_if assertion fails. Note that "carpals" with log level > debug are always logged (even if --enable_debug is not specified).<br>
<br>
(*) In your kloned.conf add something like:<br>
<br>
log<br>
{<br>
type syslog<br>
syslog.facility LOG_LOCAL7<br>
}<br>
<br>
and make sure your /etc/syslog.conf has a line like:<br>
<br>
local7.* /var/log/kloned.conf<br>
<br>
Hope it helps, t.<br>
<br>
<br>
_______________________________________________<br>
Klone-users mailing list<br>
<a href="mailto:Klone-users@koanlogic.com" target="_blank">Klone-users@koanlogic.com</a><br>
<a href="http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users" target="_blank">http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users</a><br>
</blockquote></div><br></div>