Mailing List Archive

How do qmail programs get their home directory?
Ok, looking in the source code of qmail, qmail.c specifically, it has a
reference to bin/qmail-queue. An execv is used for this file path. This
of course implies somehow the qmail programs are executing in /var/qmail
or whatever the home directory is.

So.... How does qmail get there!

The reason I am asking is I have qmail running on a new OS, and, am
finding it doesn't work unless I change the code to the full absolute
path name for qmail-queue, which makes me wonder why that would be.

I don't see or understand what might be wrong, i.e., what have I not
done? Without the change, I get an unable to exec qq error.

Qmail seems to work otherwise. I don't see form any startu of
qmail-send, how it ever gets to the Qmail home directory in the first
place.

So, can anyone help me understand this? I don't want the code changes if
it an be avoided, most likely, I have done something wrong.

Steve
Re: How do qmail programs get their home directory? [ In reply to ]
+ Steve <compconsultant@yahoo.com>:

> Ok, looking in the source code of qmail, qmail.c specifically, it
> has a reference to bin/qmail-queue. An execv is used for this file
> path. This of course implies somehow the qmail programs are
> executing in /var/qmail or whatever the home directory is.
>
> So.... How does qmail get there!

By chdir(), presumably. Did you try running "grep chdir *" in the
qmail source directory? You will find a bunch of hits, most of them
in the form chdir(auto_qmail), where auto_qmail is usually
"/var/qmail" (set in conf-qmail).

> The reason I am asking is I have qmail running on a new OS, and, am
> finding it doesn't work unless I change the code to the full
> absolute path name for qmail-queue, which makes me wonder why that
> would be.

Which part of qmail doesn't work unless you do this? Are you using an
unpatched qmail or netqmail?

- Harald
Re: How do qmail programs get their home directory? [ In reply to ]
On Jan 26, 2008 5:17 AM, Steve <compconsultant@yahoo.com> wrote:

> The reason I am asking is I have qmail running on a new OS, and, am
> finding it doesn't work unless I change the code to the full absolute
> path name for qmail-queue, which makes me wonder why that would be.

Is it OS X leopard on a mac? I ask because I have been seeing this
error with netqmail-1.06 on local forwards on a leopard system; e.g.
user tom has 'george' in his ~/.qmail file and a test message
addressed to tom results in the

Unable_to_forward_message:_unable_to_exec_qq_(#4.3.0)./

in /var/mail/mail.log. I'm using launchd to run /var/qmail/rc whenever
something shows up in /var/qmail/todo. I have patched qmail-send.c to
exit when it would otherwise be sleeping in the select() call. The
idea is to replace postfix on a client system. Perhaps launchd is the
real culprit here. I just patched qmail.c:

/* hard-code the path in - fix unable to exec qq error */
static char *binqqargs[2] = { "/var/qmail/bin/qmail-queue", 0 } ;

and the local forwards are working now. I backed out the QMAILQUEUE
patch, too. Thanks for the tip!

Direct local delivery has been working fine with a pristine install.
E.g., george has ./Maildir/ in his ~/.qmail. Mail addressed to george
shows up immediately, as one expects.

--
In mathematics you don't understand things. You just get used to them.
-- Johann von Neumann
Re: How do qmail programs get their home directory? [ In reply to ]
> Is it OS X leopard on a mac? I ask because I have been seeing this
> error with netqmail-1.06 on local forwards on a leopard system; e.g.
> user tom has 'george' in his ~/.qmail file and a test message
> addressed to tom results in the
>
> Unable_to_forward_message:_unable_to_exec_qq_(#4.3.0)./
>

Yes, it is in fact Leopard. I have qmail (spamcontrol version) on 5
production Macs under Tiger, and, they work fine. Have for many years,
high volume too. So, I do get some unable to exec qq with at least
bounces, and ezmlm-idx. But, mails that are from the outside to a local
virtual user work fine. So, I started poking through the code. I do see
some chdir in qmail-send (which handles bounces) as asked by another
user, but, right after it, is a chdir to another directory, so, I am
wanting to understand what code actually makes the default code work. I
just don't see it. So I conclude it is not chdir that does this (at
least the one in qmail-send, which is what runs qmail-queue for
bounces), but, some other mechanism. If I can understand the mechanism,
perhaps the root cause can be found.

I am making a "macport" for qmail-spamcontrol and many other related
packages.

if (chdir(auto_qmail) == -1)
{ log1("alert: cannot start: unable to switch to home directory\n");
_exit(111); }
if (!getcontrols())
{ log1("alert: cannot start: unable to read controls\n"); _exit(111); }
if (chdir("queue") == -1)
{ log1("alert: cannot start: unable to switch to queue directory\n");
_exit(111); }

>
> /* hard-code the path in - fix unable to exec qq error */
> static char *binqqargs[2] = { "/var/qmail/bin/qmail-queue", 0 } ;
>
> and the local forwards are working now. I backed out the QMAILQUEUE
> patch, too. Thanks for the tip!
>
> Direct local delivery has been working fine with a pristine install.
> E.g., george has ./Maildir/ in his ~/.qmail. Mail addressed to george
> shows up immediately, as one expects.
>
>
So, did you just change qmail-send, nothing else? I would expect other
programs to not work, but, so far, they do.

I would greatly prefer to have someone explain how it SHOULD work though
as coded without the change, I don't see WHY it would work, normally,
with only the bin/qmail-queue path!

Yes, I did change conf-qmail to my new local path before compiling. Just
like our other 5 Macs running Tiger. Which of course is mostly freeBSD.

Anyone know how it works normally?

Steve
Re: How do qmail programs get their home directory? [ In reply to ]
On Saturday, January 26 at 02:10 PM, quoth Steve:
> So, I do get some unable to exec qq with at least bounces, and
> ezmlm-idx. But, mails that are from the outside to a local virtual
> user work fine. So, I started poking through the code.

Qmail invokes qmail-queue by calling the qmail_open() function, in
qmail.c, on line 12. This function calls vfork() on line 21, and then
the child calls execv() on line 32. If you'll notice line 31, there's
the chdir(auto_qmail) call.

> Anyone know how it works normally?

Now you know! :)

~Kyle
--
Necessity is the plea for every infringement of human freedom. It is
the argument of tyrants; it is the creed of slaves.
-- William Pitt the Younger
Re: How do qmail programs get their home directory? [ In reply to ]
On Jan 26, 2008 2:10 PM, Steve <compconsultant@yahoo.com> wrote:
>
>> Is it OS X leopard on a mac? ...
>
> Yes, it is in fact Leopard. I have qmail (spamcontrol version) on 5
> production Macs under Tiger, and, they work fine. Have for many years,
> high volume too. ...
> So, did you just change qmail-send, nothing else? I would expect other
> programs to not work, but, so far, they do.

Yes, just qmail-send.c was patched to exit if sleeping in the select()
call in main(). There's no need to leave it running on a client.
Launchd restarts qmail if there is work to do. I have written a
launchd.plist file that takes care of starting qmail. /var/qmail/rc is
not used.

I realized, after I sent the previous message, that I could banish the
unable to exec qq error with a pristine netqmail-1.06 and the
QMAILQUEUE environment variable pointing at
/var/qmail/bin/qmail-queue, since the hard-coded 'bin/qmail-queue'
exec in qmail.c was failing. This works.

--
In mathematics you don't understand things. You just get used to them.
-- Johann von Neumann
Re: How do qmail programs get their home directory? [ In reply to ]
John Palkovic wrote:
> Yes, just qmail-send.c was patched to exit if sleeping in the select()
> call in main(). There's no need to leave it running on a client.
> Launchd restarts qmail if there is work to do. I have written a
> launchd.plist file that takes care of starting qmail. /var/qmail/rc is
> not used.
>
> I realized, after I sent the previous message, that I could banish the
> unable to exec qq error with a pristine netqmail-1.06 and the
> QMAILQUEUE environment variable pointing at
> /var/qmail/bin/qmail-queue, since the hard-coded 'bin/qmail-queue'
> exec in qmail.c was failing. This works.
>
Yes, the bug should affect not only qmail-send (qmailqueue will work as
you say), but, qmail-local and sendmail as they all use execv in the
same manner.

I added some debugging code to qmail.c, the call to chdir works, execv
returns errno 2,which means file not found. Since autoqmail does contain
the correct path to chdir to, I sort of conclude the error is in execv
on Leopard.

I am going to report this on the Leopard developer forum and see where
it goes.

Meanwhile, I would suggest you look at the other 2 programs I mention.

Steve
Re: How do qmail programs get their home directory? [ In reply to ]
> Try changing vfork() to fork() (throughout qmail, actually).
>
>
>
This actually does make the problem go away. vfork is only used in 4
programs near as I can tell.

I will keep playing with it, but my tests show this works.

Thanks!

Steve