[svlug] Give an environment to a daemon called by init

Tim tim at tetro.net
Mon Apr 21 18:44:41 PDT 2003


On Mon, Apr 21, 2003 at 06:14:54PM -0700, Akbar Ahmed wrote:
> I have written a daemon that uses system()/fork() exec() in several
> places to call external binaries and scripts. 
> 
> The daemon works at 100% when I logon (via ssh or a tty) and start the
> daemon via its init script. 
> 
> However, all calls to system() fail when I start my daemon via my init
> script (during boot). Please note that all functionality within my
> daemon still works except calls to system(). The biggest problem is
> when I try to use system() to call another daemon's init script, such
> as mysqld or network. The other binary's init script returns success
> but does not actually start or stop the deamon.
> 
> The only differnce I see between starting my daemon from init (during
> boot) and from the command line is the environment. I have tried
> setting an environment for my daemon in its init script, but this is
> not helping. 
> 
> I am totally confused as to how to correct this problem.
> 
> 1. How do I give my daemon the same environment whether it is called
> via its init script (during boot) or from the command line.

Does it work from the command line if you run it like this (with an
empty environment)?:

  env - /etc/init.d/mydaemon start

Maybe put this in your init script, and run it both from the shell and
from init, and do a diff between both results to see what exactly is
different:

  /usr/bin/env > /tmp/env.log

> 2. What are the other possible causes of this problem?

I can't think of any.  Can you post the contents of
/etc/init.d/mydaemon?  And also, the calls to system() and exec() in
your program.  I don't know that that would help, though.

   - Tim



More information about the svlug mailing list