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
This commit is contained in:
parent
6c12d52e7a
commit
8691e7cc40
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user