[Klone-users] hooks

thomas fossati tho at koanlogic.com
Wed Sep 10 18:12:30 EDT 2008


Hi Oleg,

On Sep 10, 2008, at 10:26 PM, Oleg Kobyakovskiy wrote:
> reading  manual about hooks and see next:
> "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."
> So I tried to configure klone with --enable_hooks flag. But got this  
> error:
>
> [err] Failed command: 'enable_hooks'!

which klone version are you using ?

Could you please provide your top-level Makefile ?

> I'd like to make the connection to DB in child_init process.
> Looks like I don't connect there. How can I see is it connected or  
> not?

1) write the code that handles DB connection setup:

int your_db_init_func(void)
{
     // e.g. connect to postgres DB

     dbg_err_if (PQsetdbLogin(...) == NULL);

     dbg_err_ifm (PQstatus(...) != CONNECTION_OK,
         "connection error: %s", PQerrorMessage(...));

     info("pg (%s:%s) connected on socket %d", PQhost(...), PQport(...),
         PQsocket(...));

     return 0;
err:
     return ~0;
}

2) provide a lib with an hooks_setup() function:

void hooks_setup(void)
{
     (void) hook_child_init(your_db_init_func);
     // perhaps other hooks (e.g. db connection teardown, ...)
     return;
}

and let it link to the kloned executable by adding the path of the lib  
via WEBAPP_LDADD.

See http://www.koanlogic.com/download/klone/klapp-auth-simple-1.2.0.tar.gz 
  - expecially auth-hooks/auth_hooks.c and Makefile - as a starting  
point.

> Also in some examples I found something like dbg_err_if.
> What is it and where can I foud info about error debuging?

dbg_xxx_if comes from libu's carpal module: please see http://wiki.koanlogic.com/doku.php?id=libu_carpal 
  for an overview.

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).

(*) In your kloned.conf add something like:

log
{
     type syslog
     syslog.facility LOG_LOCAL7
}

and make sure your /etc/syslog.conf has a line like:

local7.*    /var/log/kloned.conf

Hope it helps, t.





More information about the klone-users mailing list