[Buildroot] Starting programs in the background at init time: stdin EOF problem

Daniel Nyström daniel.nystrom at timeterminal.se
Mon Apr 11 10:25:39 UTC 2011


Den 11 april 2011 11:53 skrev Thomas De Schampheleire
<patrickdepinguin+buildroot at gmail.com>:
> Hej Daniel!
>
> 2011/4/11 Daniel Nyström <daniel.nystrom at timeterminal.se>:
>> Hi Thomas!
>>
>> 2011/4/11 Thomas De Schampheleire <patrickdepinguin+buildroot at gmail.com>:
>>> What is the recommended way to start programs in such an embedded
>>> environment?
>>
>> I'm using start-stop-daemon to perform similar tasks. Have you given
>> it a try? It can "daemonize" even non-daemons which is pretty nice for
>> e.g. GUI softwares.
>
> Thanks for the hint.
> I just gave it a try as follows:
> # start-stop-daemon  -S -x ./shell  --background
>
> Unfortunately, it seems to have the same problem. By daemonizing, the
> file descriptor stdin seems to be closed, so my test program loops
> forever (which I was able to visualize with strace).

When your program is daemonized, it per se looses it's stdin/stdout.
It sounds like a faulty design relying on those.

> I may need to adapt my program to not use stdio, but rather other
> filedescriptors. I suppose that they will not be impacted be
> foreground/background issues?

Fixing this design issue will probably help for future headaches as well.

> Where do you start start-stop-daemon from? Directly from inittab or
> from scripts in /etc/init.d?
> How do you start other programs automatically?

I'm starting them from /etc/init.d/. This is an example where it also
handles the PID file writing as well:

/sbin/start-stop-daemon --start --background --make-pidfile \
            --pidfile /var/run/myprogram.pid --exec /usr/bin/myprogram

And this will kill it the fair way:

/sbin/start-stop-daemon --stop --oknodo --pidfile /var/run/myprogram.pid



More information about the buildroot mailing list