diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-11-06 01:57:50 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-11-06 01:57:50 +0000 |
commit | dafb91b46c651eba17a63457a81917b53217c2b7 (patch) | |
tree | 5b8eca34e83e4986092cdb774324281ee61ace8c /nuttx/sched | |
parent | c8b97025f82ef4850e25c70a13b5ccba22d7475d (diff) | |
download | px4-nuttx-dafb91b46c651eba17a63457a81917b53217c2b7.tar.gz px4-nuttx-dafb91b46c651eba17a63457a81917b53217c2b7.tar.bz2 px4-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
Diffstat (limited to 'nuttx/sched')
-rw-r--r-- | nuttx/sched/sched_setupidlefiles.c | 33 | ||||
-rw-r--r-- | nuttx/sched/sched_setupstreams.c | 2 | ||||
-rw-r--r-- | nuttx/sched/sched_setuptaskfiles.c | 8 |
3 files changed, 28 insertions, 15 deletions
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 */ |