[v3,2/4] eal: fix errno not set if strftime return zero
Checks
Commit Message
The trace_session_name_generate() takes errno as the return value, but
the errno was not set if strftime return zero, the previously set errno
is returned in this case, this will result in inaccurate prompting.
This patch sets errno to ENOSPC if strftime return zero to fix it.
Fixes: 321dd5f8fa62 ("trace: add internal init and fini interface")
Cc: stable@dpdk.org
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/eal/common/eal_common_trace_utils.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Comments
On Fri, Jun 17, 2022 at 4:35 AM Chengwen Feng <fengchengwen@huawei.com> wrote:
>
> The trace_session_name_generate() takes errno as the return value, but
> the errno was not set if strftime return zero, the previously set errno
> is returned in this case, this will result in inaccurate prompting.
>
> This patch sets errno to ENOSPC if strftime return zero to fix it.
>
> Fixes: 321dd5f8fa62 ("trace: add internal init and fini interface")
> Cc: stable@dpdk.org
>
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Good catch.
With the next fix, the error condition (on trace_dir being too short
to accomodate with formatted date) cannot be reached anymore.
I squashed those two patches together.
I also updated the commitlog to give some details why we were getting
a EEXIST (or ENOENT) errno.
@@ -109,8 +109,10 @@ trace_session_name_generate(char *trace_dir)
rc = strftime(trace_dir + rc, TRACE_DIR_STR_LEN - rc,
"%Y-%m-%d-%p-%I-%M-%S", tm_result);
- if (rc == 0)
+ if (rc == 0) {
+ errno = ENOSPC;
goto fail;
+ }
return rc;
fail: