Skip to content

Commit

Permalink
record: Fix crash when the root is not existed
Browse files Browse the repository at this point in the history
This patch to fix crash when the root is not existed, due to some embed
devices maybe not have it

Signed-off-by: zyxeeker <[email protected]>
  • Loading branch information
zyxeeker committed Nov 11, 2024
1 parent b47a765 commit 9e41628
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions cmds/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,13 @@ static int filter_shmem(const struct dirent *de)
static void unlink_shmem_list(void)
{
struct shmem_list *sl, *tmp;
char *shmem_root = uftrace_shmem_root();

/* check the root is existed (due to some embed devices maybe not have it) */
if (access(shmem_root, F_OK) != 0) {
shmem_root = NULL;
pr_warn("access shmem root failed and will ignore it, err: %s\n", strerror(errno));
}

/* unlink shmem list (not used anymore) */
list_for_each_entry_safe(sl, tmp, &shmem_need_unlink, list) {
Expand All @@ -942,16 +949,17 @@ static void unlink_shmem_list(void)
sscanf(sl->id, "/uftrace-%[^-]-%*d-%*d", shmem_session);
pr_dbg2("unlink for session: %s\n", shmem_session);

num = scandir(uftrace_shmem_root(), &shmem_bufs, filter_shmem, alphasort);
for (i = 0; i < num; i++) {
sid[0] = '/';
memcpy(&sid[1], shmem_bufs[i]->d_name, MSG_ID_SIZE);
pr_dbg3("unlink %s\n", sid);
uftrace_shmem_unlink(sid);
free(shmem_bufs[i]);
if (shmem_root) {
num = scandir(shmem_root, &shmem_bufs, filter_shmem, alphasort);
for (i = 0; i < num; i++) {
sid[0] = '/';
memcpy(&sid[1], shmem_bufs[i]->d_name, MSG_ID_SIZE);
pr_dbg3("unlink %s\n", sid);
uftrace_shmem_unlink(sid);
free(shmem_bufs[i]);
}
free(shmem_bufs);
}

free(shmem_bufs);
free(sl);
}
}
Expand Down

0 comments on commit 9e41628

Please sign in to comment.