Finally managed to optimize qmail-smtpd to load control files only once using dlopen()
Manvendra Bhangui <[email protected]>
| Newsgroups | gmane.mail.qmail.general |
|---|---|
| Message-ID | <CAOqj+1PPmX20btWzf0SrVSmuy+tOGL1f4jbArO0VrAhaXaxUwA@mail.gmail.com> |
One issue with qmail-smtpd has been bugging me for past many years. Over the years the number of control files loaded by qmail-smtpd in the function setup() have kept on increasing badmailfrom, badmaipatterns, goodrcptto, badrcptto, accesslist, etc (around 36 control files in my case). These files get loaded every time qmail-smtpd gets invoked by tcpserver. This is not a issue for the unpatched qmail as it loads only 6 control files. This is something I have been working for the past few months. Initially it was just a theory, but managed to put into practice by using the dlopen() function. I did the following to achieve it 1. renamed main() function to qmail_smtpd(). in qmail-smtpd.c 2. used ifdef to conditionally compile qmail-smtpd with main() 3. use gcc -fPIC to generate qmail_smtpd.so with qmail_smtpd() function and setup() function 4. use dlopen() in tcpserver.c parent to load qmail_smtpd.so and execute setup() function 5. use dlsym() in the child to get the qmail_smtpd() function and execute it instead of using execvp() on /var/qmail/bin/qmail-smtpd Now I have a feature in tcpserver which allows you to load a .so file and execute a function named as the basename of the .so file. It allows be to load qmail_smtpd.so as well as rblsmtpd.so. e.g. my run file is exec /var/indimail/bin/softlimit -m 104857600 -o 1024 /var/indimail/bin/tcpserver \ -v -h -R -l 0 -x /var/indimail/etc/tcp.smtp.cdb \ -c /service/qmail-smtpd.25/variables/MAXDAEMONS -o -b 75 -u 555 -g 555 0 25 \ /var/indimail/plugins/rblsmtpd.so -rdnsbl-1.uceprotect.net -rzen.spamhaus.org \ /var/indimail/plugins/qmail_smtpd.so indimail.in /var/indimail/sbin/vchkpass \ /var/indimail/sbin/systpass /bin/false Just thought of sharing this in case if it of any use to anyone. In case you want to look at the git sources for indimail-mta - tcpserver.c, tcpserver_plugin.c, load_shared.c, pathexec_run.c at https://sourceforge.net/p/indimail/code/ci/master/tree/ucspi-tcp-0.88/ and qmail-smtpd.c, smtpd.c, Makefile at https://sourceforge.net/p/indimail/code/ci/master/tree/qmail-1.03/ -- Regards Manvendra - http://www.indimail.org