How does Sendmail know how it was invoked?

RW fbsd06 at mlists.homeunix.com
Sat Aug 4 13:13:41 PDT 2007


On Sat, 4 Aug 2007 13:23:07 -0500
Dan Nelson <dnelson at allantgroup.com> wrote:

> In the last episode (Aug 04), RW said:
> > mailwrapper checks to see how it was invoked and then looks up the
> > appropriate command in mailer.conf.  All of the entries in
> > mailer.conf point to /usr/libexec/sendmail/sendmail, so how does
> > that binary know what it's supposed to do.
> 
> The kernel passes the executable name to the running process along
> with the rest of the commandline arguments.  If you run "ls -l /tmp",
> for example, the ls binary gets "ls", "-l", and "/tmp" as its
> arguments. See around line 360 of src/contrib/sendmail/src/main.c.
>

Yes, I understand that. When you type mailq, mailwrapper's argv[0] will
contain "mailq". but then mailwrapper looks-up mailq in mailer.conf
and runs /usr/libexec/sendmail/sendmail. So when sendmail checks it's
argv[0] I was assuming that it would see "sendmail".

What I didn't get was that when a binary is executed from execve(), it's
the parent program that sets the argv[0] seen by the child, and not
the kernel.




More information about the freebsd-questions mailing list