On Tue, 06 Feb 2007 17:22:55 -0700 JT Moree <[EMAIL PROTECTED]> wrote:
> I have hacked the whitelist_soft plugin into a new one that uses > database backends. I need some help on database issues. > > The plugin works fine for the first run but then the database connection > goes away. (MySQL) I suspect I'm making the connection in the wrong > place. It's currently in register. The documentation I have been > reading doesn't address this issue. I'll keep digging. Yes, it's the wrong place for creating connections to a DB. Maybe you haven't seen it yet, this is from my (upcoming) plugin doc (http://ankh-morp.org/~vetinari/tmp/plugins.pdf -> chapter 2.1) The register() method is called last. It receives the same arguments as init(). There is no restriction, what you can do in register(), but creating database connections and reuse them later in the process may not be a good idea. This initialisation happens before any fork() is done. Therefore the file handle will be shared by all qpsmtpd processes and the database will probably be confused if several different queries arrive on the same file handle at the same time (and you may get the wrong answer, if any). This is also true for qpsmtpd-async and the pperl flavours, but not for qpsmtpd started by (x) inetd or tcpserver. In short: don’t do it if you want to write portable plugins. Preparing the connection in register() is ok, but connecting to the DB should be done after fork()ing, probably in hook_connect() for your plugin. Hanno