]> git.droids-corp.org - dpdk.git/commitdiff
trace: fix init with long file prefix
authorChengwen Feng <fengchengwen@huawei.com>
Fri, 17 Jun 2022 02:29:11 +0000 (10:29 +0800)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 21 Jun 2022 09:11:00 +0000 (11:11 +0200)
Bug scenario:
1. start testpmd:
  $ dpdk-testpmd -l 4-6 -a 0000:7d:00.0 --trace=.* \
    --file-prefix=trace_autotest -- -i
2. then observed:
  EAL: eal_trace_init():93 failed to initialize trace [File exists]
  EAL: FATAL: Cannot init trace
  EAL: Cannot init trace
  EAL: Error - exiting with code: 1

The root cause it that the offset set wrong with long file-prefix and
then lead the strftime return failed.

At the same time, trace_session_name_generate() uses errno as the return
value, but the errno was not set if strftime returned zero.
A previously set errno (EEXIST or ENOENT from call to mkdir for creating
the runtime configuration directory) was returned in this case.
This is fragile and may lead to incorrect logic if errno was set
to 0 previously.
This also resulted in inaccurate prompting.
Set errno to ENOSPC if strftime return zero.

Fixes: 321dd5f8fa62 ("trace: add internal init and fini interface")
Cc: stable@dpdk.org
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
lib/eal/common/eal_common_trace_utils.c

index 64f58fb66a1576b5c8d69e9b7d984fc7d0c49604..2b55dbec654317667ac749f16ccf17c1e0adf386 100644 (file)
@@ -104,13 +104,15 @@ trace_session_name_generate(char *trace_dir)
        rc = rte_strscpy(trace_dir, eal_get_hugefile_prefix(),
                        TRACE_PREFIX_LEN);
        if (rc == -E2BIG)
-               rc = TRACE_PREFIX_LEN;
+               rc = TRACE_PREFIX_LEN - 1;
        trace_dir[rc++] = '-';
 
        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: