* [Buildroot] Starting programs in the background at init time: stdin EOF problem
@ 2011-04-11 7:58 Thomas De Schampheleire
2011-04-11 8:55 ` Daniel Nyström
0 siblings, 1 reply; 5+ messages in thread
From: Thomas De Schampheleire @ 2011-04-11 7:58 UTC (permalink / raw)
To: buildroot
Hi,
I need to start a set of programs when the board boots. I'm using
scripts in /etc/init.d/ to accomplish this.
Since I shouldn't block the other inits, I put these programs in the
background. But, this seems to give problems for programs that read
from stdin: read immediately returns with EOF (return value 0).
For example, the following script:
/etc/init.d/S50shell
#!/bin/sh
/path/to/shell &
with the following 'shell' program:
#include <stdio.h>
#include <unistd.h>
int main (void)
{
int len;
char in[1];
while (1) {
printf("\n--> ");
len = read(0, in, 1);
write(1, in, len);
}
}
results in a continuous stream of "-->" to be printed at init time.
The read is supposed to be blocking, but returns prematurely because
end-of-file is detected on stdin.
If I do not put /path/to/shell in the background, the program works as expected.
What is the recommended way to start programs in such an embedded
environment? Besides this background problem, I also noticed problems
with using Ctrl-C depending on whether you start the program with a
init.d script (on /dev/console) or explicitly put it on a serial tty
in inittab.
Eventually, I would like to start a bunch of programs in the
background, and then present a login prompt to the user on the serial
tty.
Thanks,
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Buildroot] Starting programs in the background at init time: stdin EOF problem
2011-04-11 7:58 [Buildroot] Starting programs in the background at init time: stdin EOF problem Thomas De Schampheleire
@ 2011-04-11 8:55 ` Daniel Nyström
2011-04-11 9:53 ` Thomas De Schampheleire
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Nyström @ 2011-04-11 8:55 UTC (permalink / raw)
To: buildroot
Hi Thomas!
2011/4/11 Thomas De Schampheleire <patrickdepinguin+buildroot@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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Buildroot] Starting programs in the background at init time: stdin EOF problem
2011-04-11 8:55 ` Daniel Nyström
@ 2011-04-11 9:53 ` Thomas De Schampheleire
2011-04-11 10:25 ` Daniel Nyström
0 siblings, 1 reply; 5+ messages in thread
From: Thomas De Schampheleire @ 2011-04-11 9:53 UTC (permalink / raw)
To: buildroot
Hej Daniel!
2011/4/11 Daniel Nystr?m <daniel.nystrom@timeterminal.se>:
> Hi Thomas!
>
> 2011/4/11 Thomas De Schampheleire <patrickdepinguin+buildroot@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).
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?
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?
Thanks,
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Buildroot] Starting programs in the background at init time: stdin EOF problem
2011-04-11 9:53 ` Thomas De Schampheleire
@ 2011-04-11 10:25 ` Daniel Nyström
2011-04-14 7:29 ` Thomas De Schampheleire
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Nyström @ 2011-04-11 10:25 UTC (permalink / raw)
To: buildroot
Den 11 april 2011 11:53 skrev Thomas De Schampheleire
<patrickdepinguin+buildroot@gmail.com>:
> Hej Daniel!
>
> 2011/4/11 Daniel Nystr?m <daniel.nystrom@timeterminal.se>:
>> Hi Thomas!
>>
>> 2011/4/11 Thomas De Schampheleire <patrickdepinguin+buildroot@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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Buildroot] Starting programs in the background at init time: stdin EOF problem
2011-04-11 10:25 ` Daniel Nyström
@ 2011-04-14 7:29 ` Thomas De Schampheleire
0 siblings, 0 replies; 5+ messages in thread
From: Thomas De Schampheleire @ 2011-04-14 7:29 UTC (permalink / raw)
To: buildroot
2011/4/11 Daniel Nystr?m <daniel.nystrom@timeterminal.se>:
> Den 11 april 2011 11:53 skrev Thomas De Schampheleire
> <patrickdepinguin+buildroot@gmail.com>:
>> Hej Daniel!
>>
>> 2011/4/11 Daniel Nystr?m <daniel.nystrom@timeterminal.se>:
>>> Hi Thomas!
>>>
>>> 2011/4/11 Thomas De Schampheleire <patrickdepinguin+buildroot@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.
I agree.
>
>> 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
>
Thanks, I will keep this in mind.
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-04-14 7:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-11 7:58 [Buildroot] Starting programs in the background at init time: stdin EOF problem Thomas De Schampheleire
2011-04-11 8:55 ` Daniel Nyström
2011-04-11 9:53 ` Thomas De Schampheleire
2011-04-11 10:25 ` Daniel Nyström
2011-04-14 7:29 ` Thomas De Schampheleire
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.