summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-11-06 01:57:50 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-11-06 01:57:50 +0000
commitdafb91b46c651eba17a63457a81917b53217c2b7 (patch)
tree5b8eca34e83e4986092cdb774324281ee61ace8c
parentc8b97025f82ef4850e25c70a13b5ccba22d7475d (diff)
downloadnuttx-dafb91b46c651eba17a63457a81917b53217c2b7.tar.gz
nuttx-dafb91b46c651eba17a63457a81917b53217c2b7.tar.bz2
nuttx-dafb91b46c651eba17a63457a81917b53217c2b7.zip
Fix errors when there is no console device
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3077 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/lib/lib_fopen.c19
-rw-r--r--nuttx/sched/sched_setupidlefiles.c33
-rw-r--r--nuttx/sched/sched_setupstreams.c2
-rw-r--r--nuttx/sched/sched_setuptaskfiles.c8
4 files changed, 45 insertions, 17 deletions
diff --git a/nuttx/lib/lib_fopen.c b/nuttx/lib/lib_fopen.c
index 672fb5bbe..0bfb275b8 100644
--- a/nuttx/lib/lib_fopen.c
+++ b/nuttx/lib/lib_fopen.c
@@ -1,7 +1,7 @@
/****************************************************************************
* lib/lib_fopen.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -137,18 +137,33 @@ FAR struct file_struct *lib_fdopen(int fd, FAR const char *mode,
FAR struct filelist *flist,
FAR struct streamlist *slist)
{
- FAR struct inode *inode = flist->fl_files[fd].f_inode;
+ FAR struct inode *inode = flist;
FAR FILE *stream;
int oflags = lib_mode2oflags(mode);
int err = OK;
int i;
+ /* Check input parameters */
+
if (fd < 0 || !flist || !slist)
{
err = EBADF;
goto errout;
}
+ /* Get the inode associated with the file descriptor. This should
+ * normally be the case if fd >= 0. But not in the case where the
+ * called attempts to explictly stdin with fdopen(0) but stdin has
+ * been closed.
+ */
+
+ inode = flist->fl_files[fd].f_inode;
+ if (!inode)
+ {
+ err = ENOENT;
+ goto errout;
+ }
+
/* Make sure that the inode supports the requested access. In
* the case of fdopen, we are not actually creating the file -- in
* particular w and w+ do not truncate the file and any files have
diff --git a/nuttx/sched/sched_setupidlefiles.c b/nuttx/sched/sched_setupidlefiles.c
index e88d75e12..683a00c7a 100644
--- a/nuttx/sched/sched_setupidlefiles.c
+++ b/nuttx/sched/sched_setupidlefiles.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched_setupidlefiles.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
#include <fcntl.h>
#include <sched.h>
#include <errno.h>
+#include <debug.h>
#include <nuttx/fs.h>
#include <nuttx/net.h>
@@ -88,8 +89,7 @@ int sched_setupidlefiles(FAR _TCB *tcb)
tcb->filelist = files_alloclist();
if (!tcb->filelist)
{
- *get_errno_ptr() = ENOMEM;
- return ERROR;
+ return -ENOMEM;
}
#endif /* CONFIG_NFILE_DESCRIPTORS */
@@ -99,25 +99,40 @@ int sched_setupidlefiles(FAR _TCB *tcb)
tcb->sockets = net_alloclist();
if (!tcb->sockets)
{
- *get_errno_ptr() = ENOMEM;
- return ERROR;
+ return -ENOMEM;
}
#endif /* CONFIG_NSOCKET_DESCRIPTORS */
#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE)
- /* Open stdin, dup to get stdout and stderr. */
+ /* Open stdin, dup to get stdout and stderr. This should always
+ * be the first file opened and, hence, should always get file
+ * descriptor 0.
+ */
fd = open("/dev/console", O_RDWR);
if (fd == 0)
{
+ /* Successfully opened /dev/console as stdin (fd == 0) */
+
(void)file_dup2(0, 1);
(void)file_dup2(0, 2);
}
else
{
- (void)close(fd);
- *get_errno_ptr() = ENFILE;
- return ERROR;
+ /* We failed to open /dev/console OR for some reason, we opened
+ * it and got some file descriptor other than 0.
+ */
+
+ if (fd >- 0)
+ {
+ slldbg("Open /dev/console fd: %d\n", fd);
+ (void)close(fd);
+ }
+ else
+ {
+ slldbg("Failed to open /dev/console: %d\n", errno);
+ }
+ return -ENFILE;
}
#if CONFIG_NFILE_STREAMS > 0
diff --git a/nuttx/sched/sched_setupstreams.c b/nuttx/sched/sched_setupstreams.c
index 88d0b09c4..28b824f26 100644
--- a/nuttx/sched/sched_setupstreams.c
+++ b/nuttx/sched/sched_setupstreams.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched_setupstreams.c
*
- * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2008, 2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c
index 23a820a96..95c571b47 100644
--- a/nuttx/sched/sched_setuptaskfiles.c
+++ b/nuttx/sched/sched_setuptaskfiles.c
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched_setuptaskfiles.c
*
- * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2008, 2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -105,8 +105,7 @@ int sched_setuptaskfiles(FAR _TCB *tcb)
tcb->filelist = files_alloclist();
if (!tcb->filelist)
{
- *get_errno_ptr() = ENOMEM;
- return ERROR;
+ return -ENOMEM;
}
#endif /* CONFIG_NFILE_DESCRIPTORS */
@@ -118,8 +117,7 @@ int sched_setuptaskfiles(FAR _TCB *tcb)
tcb->sockets = net_alloclist();
if (!tcb->sockets)
{
- *get_errno_ptr() = ENOMEM;
- return ERROR;
+ return -ENOMEM;
}
#endif /* CONFIG_NSOCKET_DESCRIPTORS */