From b4e59bac4e2d8b039a2365ddc219ac9a3caf0f77 Mon Sep 17 00:00:00 2001 From: yangfasheng Date: Tue, 20 Jun 2023 23:09:58 +0800 Subject: [PATCH] =?UTF-8?q?dfs=20v2=20=E4=BF=AE=E6=94=B9=20fd=5Fnew=20?= =?UTF-8?q?=E7=9A=84=20startfd=20=E8=B5=B7=E5=A7=8B=E5=80=BC=E4=B8=BA=200?= =?UTF-8?q?=20=EF=BC=9B=E4=BF=AE=E5=A4=8D=20futex=5Fwait=20=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=97=B6=E9=97=B4=E6=8D=A2=E7=AE=97=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=9B=20(#7705)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfasheng --- components/dfs/dfs_v2/src/dfs.c | 2 +- components/libc/posix/io/stdio/libc.c | 31 +++++++++++++++++++++------ components/lwp/lwp_futex.c | 7 +++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/components/dfs/dfs_v2/src/dfs.c b/components/dfs/dfs_v2/src/dfs.c index c181930fcc..9b25985409 100644 --- a/components/dfs/dfs_v2/src/dfs.c +++ b/components/dfs/dfs_v2/src/dfs.c @@ -197,7 +197,7 @@ int fdt_fd_new(struct dfs_fdtable *fdt) dfs_file_lock(); /* find an empty fd entry */ - idx = fd_alloc(fdt, DFS_STDIO_OFFSET); + idx = fd_alloc(fdt, 0); /* can't find an empty fd entry */ if (idx < 0) { diff --git a/components/libc/posix/io/stdio/libc.c b/components/libc/posix/io/stdio/libc.c index a5bee3f448..9c7d28fefd 100644 --- a/components/libc/posix/io/stdio/libc.c +++ b/components/libc/posix/io/stdio/libc.c @@ -30,15 +30,34 @@ int libc_system_init(void) dev_console = rt_console_get_device(); if (dev_console) { - int fd = libc_stdio_set_console(dev_console->parent.name, O_RDWR); - if (fd < 0) + int fd, ret; + char name[STDIO_DEVICE_NAME_MAX]; + + rt_snprintf(name, sizeof(name) - 1, "/dev/%s", dev_console->parent.name); + name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; + + fd = open(name, O_RDWR); + if (fd >= 0) + { + /* set fd (0, 1, 2) */ + ret = sys_dup2(fd, 0); + if (ret != fd) + { + close(fd); + } + sys_dup2(ret, 1); + sys_dup2(ret, 2); + + ret = libc_stdio_set_console(dev_console->parent.name, O_RDWR); + if (ret < 0) + { + return -1; + } + } + else { return -1; } - /* set fd (0, 1, 2) */ - sys_dup2(fd, 0); - sys_dup2(fd, 1); - sys_dup2(fd, 2); } #endif /* RT_USING_POSIX_STDIO */ return 0; diff --git a/components/lwp/lwp_futex.c b/components/lwp/lwp_futex.c index 49fe13861c..3d0fda0af6 100644 --- a/components/lwp/lwp_futex.c +++ b/components/lwp/lwp_futex.c @@ -124,7 +124,12 @@ int futex_wait(struct rt_futex *futex, int value, const struct timespec *timeout /* with timeout */ if (timeout) { - rt_int32_t time = rt_timespec_to_tick(timeout); + rt_int32_t time = timeout->tv_sec * RT_TICK_PER_SECOND + timeout->tv_nsec * RT_TICK_PER_SECOND / NANOSECOND_PER_SECOND; + + if (time < 0) + { + time = 0; + } /* start the timer of thread */ rt_timer_control(&(thread->thread_timer),