Subject: /usr/pkgsrc/mail/nullmailer not starting with rc.d at boot
To: None <netbsd-users@netbsd.org, tech-userlevel@netbsd.org>
From: Iain Hibbert <plunky@rya-online.net>
List: tech-userlevel
Date: 11/25/2005 20:41:15
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--0-1077427893-1132950526=:4607
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <Pine.NEB.4.63.0511252032091.165@localhost.>

Hi,
   I think this list might be better (I asked on tech-pkg, but will start
again..)

I use the nullmailer package which includes a sample /etc/rc.d script in
order to start nullmailer automatically. The script is attached.

This seemingly works. ie from a root shell, '/etc/rc.d/nullmailer start'
fires it up and my mail is sent.

However, it does not work during boot up. All file systems are mounted,
and as it requires LOGIN it is one of the last programs to be loaded. Only
mixerctl is after it and that should be irrelevant.

I *believe* the problem to be in the command_args. If I remove the
trailing & then it works but blocks the console (mixerctl then getty)

I have tried and tried and cried and cried but I just cant get this to
work, has anybody any suggestions as to how to get a program to start in
the background from rc.d during boot?

More to the point, WHY does it work from a root shell but not in the boot
sequence?  what is missing at that point?  I doesnt seem to be anything
inherited from my user login, I logged in as root directly and it starts
fine.

I tried providing a separate cmd_start function

nullmailer_start()
{
	echo "Starting ${name}."
	${command} ${nullmailer_flags} ${command_args} &
}

and that does start, but its not being run as 'nullmail' user so the stop
function does not work (nullmail is not allowed to kill root processes)

if I add a su as in

su -m {nullmailer_user} -c "sh -x -c \"${command} ${nullmailer_flags} ${command_args} &\""

then it works but only from a shell. From the boot sequence, I *do* get

Starting nullmailer.
+ /usr/pkg/libexec/nullmailer/nullmailer-send
+ logger -t nullmailer -p mail.info

but when I login and check, it is not running..

I also added 'printf("Hello World\n");' as the very first line of the
program and restarted. Starting from a shell, Hello World makes it to the
logfile, but starting from boot nothing happens.

What have I missed?

one more experiment, remove the & to outside the quotes, as in

su -m {nullmailer_user} -c "sh -x -c \"${command} ${nullmailer_flags} ${command_args}\"" &

.. now, it is working!

however, its rather ugly in the process table.

146 ttyp3- I<   0:00.02 _csh -m -c sh -x -c "/usr/pkg/libexec/nullmailer/nullmailer-send  2>&1 | /usr/bin/logger -t nullmailer -p mail.info" (csh)
820 ttyp3- I<   0:00.00 /usr/bin/logger -t nullmailer -p mail.info
854 ttyp3- I<   0:00.01 sh -x -c /usr/pkg/libexec/nullmailer/nullmailer-send  2>&1 | /usr/bin/logger -t nullmailer -p mail.info
885 ttyp3- I<   0:00.01 /usr/pkg/libexec/nullmailer/nullmailer-send

Call me fussy, but technically I dont want the su (_csh) or the sh
processes hanging around, would prefer to fork below them.

Whats different about the rc environment that it wont happen there?

anybody?
iain
--0-1077427893-1132950526=:4607
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME=nullmailer
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.NEB.4.63.0511252028460.4607@localhost.>
Content-Description: /usr/pkg/share/examples/rc.d/nullmailer
Content-Disposition: ATTACHMENT; FILENAME=nullmailer

IyEvYmluL3NoDQojDQojICROZXRCU0Q6IG51bGxtYWlsZXIuc2gsdiAxLjIg
MjAwNS8wOC8yMCAwMjoyMDo0NSBzY2htb256IEV4cCAkDQojDQojIFBST1ZJ
REU6IG1haWwNCiMgUkVRVUlSRTogTE9HSU4NCg0KaWYgWyAtZiAvZXRjL3Jj
LnN1YnIgXTsgdGhlbg0KICAgIC4gL2V0Yy9yYy5zdWJyDQpmaQ0KDQpuYW1l
PSJudWxsbWFpbGVyIg0KcmN2YXI9JHtuYW1lfQ0KcmVxdWlyZWRfZmlsZXM9
Ii91c3IvcGtnL2V0Yy9udWxsbWFpbGVyL3JlbW90ZXMiDQpyZXF1aXJlZF9m
aWxlcz0iJHtyZXF1aXJlZF9maWxlc30gL3Zhci9zcG9vbC9udWxsbWFpbGVy
L3RyaWdnZXIiDQpyZXF1aXJlZF9kaXJzPSIvdmFyL3Nwb29sL251bGxtYWls
ZXIvcXVldWUgL3Zhci9zcG9vbC9udWxsbWFpbGVyL3RtcCINCmNvbW1hbmQ9
Ii91c3IvcGtnL2xpYmV4ZWMvbnVsbG1haWxlci9udWxsbWFpbGVyLXNlbmQi
DQpjb21tYW5kX2FyZ3M9IjI+JjEgfCBsb2dnZXIgLXQgbnVsbG1haWxlciAt
cCBtYWlsLmluZm8gJiINCg0KbnVsbG1haWxlcl91c2VyPSJudWxsbWFpbCIN
Cm51bGxtYWlsZXJfZ3JvdXA9Im51bGxtYWlsIg0KDQppZiBbIC1mIC9ldGMv
cmMuc3ViciBdOyB0aGVuDQoJbG9hZF9yY19jb25maWcgJG5hbWUNCglydW5f
cmNfY29tbWFuZCAiJDEiDQplbHNlDQoJZWNobyAtbiAiICR7bmFtZX0iDQoJ
JHtjb21tYW5kfSAke251bGxtYWlsZXJfZmxhZ3N9ICR7Y29tbWFuZF9hcmdz
fQ0KZmkNCg==

--0-1077427893-1132950526=:4607--