Commit 16d93070 authored by Alessandro Rubini's avatar Alessandro Rubini

boot procedure: use non-blocking write to /dev/ttyGS0

If the usb cable is disconnected, any write to /dev/ttyGS0 goes to a
buffer until it fills. Then, any further write will block. This means
the messages towards the user ("uncompressing filesystem... done" etc)
caused the update procedure to stop.

This fixes the problem by using non-blocking write for the messages:
if nobody`s reading the messages are just discarded by the kernel.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent acc26834
...@@ -108,6 +108,9 @@ mv $TMPFS/usr/sbin/ubi* $TMPFS/sbin ...@@ -108,6 +108,9 @@ mv $TMPFS/usr/sbin/ubi* $TMPFS/sbin
# copy /etc to /usr/etc, where it can be edited (boot sequence copies back) # copy /etc to /usr/etc, where it can be edited (boot sequence copies back)
cp -a $TMPFS/etc $TMPFS/usr/etc cp -a $TMPFS/etc $TMPFS/usr/etc
# copy non-blocking tee to /bin where it is used during boot
cp $TMPFS/wr/bin/nbtee $TMPFS/bin
(cd "$TMPFS" && tar cz . > $ROOTFS_IMAGE_TGZ) (cd "$TMPFS" && tar cz . > $ROOTFS_IMAGE_TGZ)
(cd "$TMPFS/usr" && tar cz . > $ROOTFS_USR_TGZ) (cd "$TMPFS/usr" && tar cz . > $ROOTFS_USR_TGZ)
# include /usr but nothing within usr # include /usr but nothing within usr
......
...@@ -59,7 +59,7 @@ mkdev_sh () { ...@@ -59,7 +59,7 @@ mkdev_sh () {
mkdev_sh "/sys/devices/virtual/misc/ubi_ctrl" mkdev_sh "/sys/devices/virtual/misc/ubi_ctrl"
TEE="busybox tee"; # often used. TEE="/bin/nbtee"; # often used. And non-blocking, in case ttyGS0 is unplugged
# Installing is like updating, but there are more steps to do initially # Installing is like updating, but there are more steps to do initially
if $install; then if $install; then
......
...@@ -16,3 +16,4 @@ tru_mon ...@@ -16,3 +16,4 @@ tru_mon
wrs_pstats wrs_pstats
wrs_vlans wrs_vlans
sdb-read sdb-read
nbtee
\ No newline at end of file
...@@ -3,6 +3,7 @@ TOOLS += mapper wmapper ...@@ -3,6 +3,7 @@ TOOLS += mapper wmapper
TOOLS += wrs_version wr_date wr_management lm32-vuart wrs_pstats TOOLS += wrs_version wr_date wr_management lm32-vuart wrs_pstats
TOOLS += wrs_vlans TOOLS += wrs_vlans
TOOLS += sdb-read TOOLS += sdb-read
TOOLS += nbtee
# # Standard stanza for cross-compilation (courtesy of the linux makefile) # # Standard stanza for cross-compilation (courtesy of the linux makefile)
......
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#define BSIZE 4096
char buffer[BSIZE];
int main(int argc, char **argv)
{
int fd[argc]; /* in place 0 we put stdout */
int i, n, err = 0;
if (argc > 1 && argv[1][0] == '-') {
/* --help, -h, whatever */
fprintf(stderr, "%s: copies stdin to stdout and arguments,\n"
" using non-blocking open and non-blocking write\n",
argv[0]);
exit(0);
}
signal(SIGPIPE, SIG_IGN); /* we don't care about closed output pipes */
fcntl(STDOUT_FILENO, F_SETFL, fcntl(1,F_GETFL) | O_NONBLOCK);
fd[0] = STDOUT_FILENO;
/* open them all */
for (i = 1; i < argc; i++) {
fd[i] = open(argv[i], O_WRONLY | O_NONBLOCK);
/* A special case to be able to open fifos: see "man 7 fifo" */
if ((fd[i] < 0) && (errno == ENXIO))
fd[i] = open(argv[i], O_RDWR | O_NONBLOCK);
if (fd[i] < 0) {
fprintf(stderr, "%s: open(%s): %s\n", argv[0], argv[i],
strerror(errno));
err++;
}
}
if (err)
exit(1);
while (1) {
n = read(0, buffer, sizeof(buffer)); /* this is blocking: ok */
if (n < 0 && errno == EAGAIN)
continue;
if (n == 0)
exit(0); /* EOF */
for (i = 0; i < argc; i++)
write(fd[i], buffer, n); /* ignore errors here */
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment