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 <zyxeeker@gmail.com>
  • Loading branch information
zyxeeker committed Nov 2, 2024
1 parent b47a765 commit 9d34cc8
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cmds/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,16 +942,24 @@ 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]);
/* check the root is existed (due to some embed devices maybe not have it) */
if (access(uftrace_shmem_root(), F_OK) == 0) {
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]);
}

free(shmem_bufs);
}
else {
pr_dbg2("access %s failed, err: %s\n", uftrace_shmem_root(),
strerror(errno));
}

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

0 comments on commit 9d34cc8

Please sign in to comment.