Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record: Fix crash when the root is not existed #1979

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = (char *)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