forked from Archive/PX4-Autopilot
Fix an error handling bug in the fread logic
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5511 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
e7a5090e55
commit
43e22b2b98
|
@ -105,7 +105,26 @@ distclean: clean
|
|||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
# There are no dependencies in this directory. We should are code some of
|
||||
# more important dependencies here:
|
||||
# There are no dependencies in this directory. Some of more important
|
||||
# and more obvious dependencies are hard-coded here:
|
||||
|
||||
-include Make.dep
|
||||
spawn_main.o: spawn_main.c \
|
||||
$(TOPDIR)/include/nuttx/config.h \
|
||||
$(TOPDIR)/include/nuttx/compiler.h \
|
||||
$(TOPDIR)/include/sys/mount.h \
|
||||
$(TOPDIR)/include/stdio.h \
|
||||
$(TOPDIR)/include/stdlib.h \
|
||||
$(TOPDIR)/include/unistd.h \
|
||||
$(TOPDIR)/include/string.h \
|
||||
$(TOPDIR)/include/fcntl.h \
|
||||
$(TOPDIR)/include/spawn.h \
|
||||
$(TOPDIR)/include/debug.h \
|
||||
$(TOPDIR)/include/errno.h \
|
||||
$(TOPDIR)/include/nuttx/ramdisk.h \
|
||||
$(TOPDIR)/include/nuttx/binfmt/elf.h \
|
||||
$(TOPDIR)/include/nuttx/binfmt/symtab.h \
|
||||
filesystem/romfs.h
|
||||
|
||||
symtab.o: filesystem/symtab.c \
|
||||
$(TOPDIR)/include/nuttx/compiler.h \
|
||||
$(TOPDIR)/include/nuttx/binfmt/symtab.h
|
||||
|
|
|
@ -44,7 +44,7 @@ ROMFS_HDR = $(FILESYSTEM_DIR)$(DELIM)romfs.h
|
|||
SYMTAB_SRC = $(FILESYSTEM_DIR)$(DELIM)symtab.c
|
||||
|
||||
all: $(ROMFS_HDR) $(SYMTAB_SRC)
|
||||
.PHONY: all hello redirect clean install populate
|
||||
.PHONY: all hello/hello redirect/redirect clean populate
|
||||
|
||||
# Create the romfs directory
|
||||
|
||||
|
@ -53,24 +53,20 @@ $(ROMFS_DIR):
|
|||
|
||||
# Build the hello test program
|
||||
|
||||
hello: $(ROMFS_DIR)
|
||||
hello/hello:
|
||||
$(Q) $(MAKE) -C hello hello TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)"
|
||||
|
||||
# Build the redirection test program
|
||||
|
||||
redirect: $(ROMFS_DIR)
|
||||
redirect/redirect:
|
||||
$(Q) $(MAKE) -C redirect redirect TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)"
|
||||
|
||||
# Install the test programs in the romfs directory
|
||||
|
||||
install: hello redirect testdata.txt
|
||||
$(Q) $(MAKE) -C hello install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)"
|
||||
$(Q) $(MAKE) -C redirect install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)"
|
||||
$(Q) install --mode=0644 testdata.txt $(ROMFS_DIR)/testdata.txt
|
||||
|
||||
# Create the romfs.img file from the romfs directory
|
||||
|
||||
$(ROMFS_IMG): install
|
||||
$(ROMFS_IMG): hello/hello redirect/redirect testdata.txt $(ROMFS_DIR)
|
||||
$(Q) $(MAKE) -C hello install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)"
|
||||
$(Q) $(MAKE) -C redirect install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)"
|
||||
$(Q) install --mode=0644 testdata.txt $(ROMFS_DIR)/testdata.txt
|
||||
$(Q) genromfs -f $@ -d $(ROMFS_DIR) -V "POSIXSPAWN"
|
||||
|
||||
# Create the romfs.h header file from the romfs.img file
|
||||
|
@ -80,7 +76,7 @@ $(ROMFS_HDR) : $(ROMFS_IMG)
|
|||
|
||||
# Create the exported symbol table
|
||||
|
||||
$(SYMTAB_SRC): hello/hello redirect/redirect testdata.txt
|
||||
$(SYMTAB_SRC): $(ROMFS_DIR)/hello $(ROMFS_DIR)/redirect $(ROMFS_DIR)/testdata.txt
|
||||
$(Q) $(FILESYSTEM_DIR)$(DELIM)mksymtab.sh $(ROMFS_DIR) >$@
|
||||
|
||||
# Clean each subdirectory
|
||||
|
|
|
@ -89,6 +89,15 @@
|
|||
# error "You must not disable loadable modules via CONFIG_BINFMT_DISABLE in your configuration file"
|
||||
#endif
|
||||
|
||||
/* The redirection test does not work. This is because it tries to redirect
|
||||
* file as stdin. That won't work now because (1) the file descriptors must
|
||||
* be dup'ed when the new task is created, and (2) there is no support in
|
||||
* place for dup'ing file descriptors for anything other than sockets and
|
||||
* character drivers. This is a bug!
|
||||
*/
|
||||
|
||||
#define FILE_DUP_BUG 1
|
||||
|
||||
/* Describe the ROMFS file system */
|
||||
|
||||
#define SECTORSIZE 512
|
||||
|
@ -138,7 +147,9 @@ static unsigned int g_mmstep; /* Memory Usage at beginning of test step */
|
|||
|
||||
static const char delimiter[] =
|
||||
"****************************************************************************";
|
||||
#ifndef FILE_DUP_BUG
|
||||
static const char g_redirect[] = "redirect";
|
||||
#endif
|
||||
static const char g_hello[] = "hello";
|
||||
static const char g_data[] = "testdata.txt";
|
||||
|
||||
|
@ -361,9 +372,11 @@ int spawn_main(int argc, char *argv[])
|
|||
mm_update(&g_mmstep, "after file_action/attr destruction");
|
||||
|
||||
/*************************************************************************
|
||||
* Case 2: Simple program with redirection of stdin
|
||||
* Case 2: Simple program with redirection of stdin to a file input
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef FILE_DUP_BUG
|
||||
|
||||
/* Output a seperated so that we can clearly discriminate the output of
|
||||
* this program from the others.
|
||||
*/
|
||||
|
@ -450,6 +463,7 @@ int spawn_main(int argc, char *argv[])
|
|||
posix_spawnattr_dump(&attr);
|
||||
|
||||
mm_update(&g_mmstep, "after file_action/attr destruction");
|
||||
#endif
|
||||
|
||||
/* Clean-up */
|
||||
|
||||
|
|
|
@ -3907,4 +3907,7 @@
|
|||
that can be used for testing posix_spawn().
|
||||
* arch/arm/src/stm32: Bring F1 support for general DMA and serial
|
||||
DMA in paricular up to parity with F2/F4 (from Mike Smith).
|
||||
|
||||
* libc/stdio/lib_libfread.c: Correct some error handling when
|
||||
lib_fread() was passed a bad stream. Needed to move the
|
||||
releasing of a semaphore inside of some conditional logic
|
||||
(cosmetic).
|
||||
|
|
14
nuttx/TODO
14
nuttx/TODO
|
@ -1,4 +1,4 @@
|
|||
NuttX TODO List (Last updated January 10, 2013)
|
||||
NuttX TODO List (Last updated January 11, 2013)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This file summarizes known NuttX bugs, limitations, inconsistencies with
|
||||
|
@ -15,7 +15,7 @@ nuttx/
|
|||
(17) Network (net/, drivers/net)
|
||||
(4) USB (drivers/usbdev, drivers/usbhost)
|
||||
(12) Libraries (libc/, )
|
||||
(9) File system/Generic drivers (fs/, drivers/)
|
||||
(10) File system/Generic drivers (fs/, drivers/)
|
||||
(5) Graphics subystem (graphics/)
|
||||
(1) Pascal add-on (pcode/)
|
||||
(1) Documentation (Documentation/)
|
||||
|
@ -863,6 +863,16 @@ o File system / Generic drivers (fs/, drivers/)
|
|||
Status: Open
|
||||
Priority: Medium
|
||||
|
||||
Title: dup AND dup2 WILL NOT WORK ON FILES IN A MOUNTED VOLUME
|
||||
Description: The current implementation of dup() and dup2() will only
|
||||
work with open device drivers and sockets. It will not
|
||||
work with open files in a file system.
|
||||
|
||||
A limitation that results from this is that you cannot
|
||||
redirect I/O to an from and file.
|
||||
Status: Open
|
||||
Priority: High
|
||||
|
||||
o Graphics subystem (graphics/)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@
|
|||
|
||||
void lib_sem_initialize(FAR struct file_struct *stream)
|
||||
{
|
||||
/* Initialize the LIB semaphore to one (to support one-at-
|
||||
* a-time access to private data sets.
|
||||
/* Initialize the LIB semaphore to one (to support one-at-a-time access
|
||||
* to private data sets.
|
||||
*/
|
||||
|
||||
(void)sem_init(&stream->fs_sem, 0, 1);
|
||||
|
@ -98,13 +98,13 @@ void lib_take_semaphore(FAR struct file_struct *stream)
|
|||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
while (sem_wait(&stream->fs_sem) != 0)
|
||||
{
|
||||
/* The only case that an error should occr here is if
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
{
|
||||
/* The only case that an error should occr here is if the wait
|
||||
* was awakened by a signal.
|
||||
*/
|
||||
|
||||
ASSERT(get_errno() == EINTR);
|
||||
}
|
||||
ASSERT(get_errno() == EINTR);
|
||||
}
|
||||
|
||||
/* We have it. Claim the stak and return */
|
||||
|
||||
|
|
|
@ -86,5 +86,3 @@ void stream_semgive(FAR struct streamlist *list)
|
|||
{
|
||||
sem_post(&list->sl_sem);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -301,9 +301,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||
{
|
||||
stream->fs_flags |= __FS_FLAG_EOF;
|
||||
}
|
||||
|
||||
lib_give_semaphore(stream);
|
||||
}
|
||||
|
||||
lib_give_semaphore(stream);
|
||||
return bytes_read;
|
||||
|
||||
/* Error exits */
|
||||
|
|
Loading…
Reference in New Issue