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

dbg: mutex should be unlocked while calling print handler #1113

Merged
merged 3 commits into from
Apr 30, 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
29 changes: 14 additions & 15 deletions src/dbg/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ void dbg_close(void)
*/
void dbg_handler_set(dbg_print_h *ph, void *arg)
{
dbg_lock();
dbg.ph = ph;
dbg.arg = arg;
dbg_unlock();
}


Expand Down Expand Up @@ -151,27 +153,24 @@ static void dbg_vprintf(int level, const char *fmt, va_list ap)
static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
{
char buf[256];
int len;

dbg_lock();
int dbg_level = dbg.level;
dbg_print_h *ph = dbg.ph;
void *arg = dbg.arg;
dbg_unlock();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would does this locking protect?

Copy link
Collaborator

@cspiel1 cspiel1 Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be an additional lock in dbg_handler_set()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mutex should protect all members of the struct.


if (level > dbg.level)
goto out;

if (!dbg.ph)
goto out;

len = re_vsnprintf(buf, sizeof(buf), fmt, ap);
if (len <= 0)
goto out;
if (level > dbg_level)
return;

/* Print handler? */
if (dbg.ph) {
dbg.ph(level, buf, len, dbg.arg);
}
if (ph) {
int len = re_vsnprintf(buf, sizeof(buf), fmt, ap);
if (len <= 0)
return;

out:
dbg_unlock();
ph(level, buf, len, arg);
}
}


Expand Down
Loading