Skip to content

Commit

Permalink
syslog: Don't allow blocking when in signal handler
Browse files Browse the repository at this point in the history
Blocking while running a signal handler is not advisable, instead write
the log string character by character.

There is also a potential for a deadlock, as discussed in apache#6618

Note: querying for rtcb->sigdeliver is not 100% ideal, as it only tells
_if_ a signal handler has been queued, not if it is running. However, it
makes syslog safe / usable which is a debug feature anyhow.
  • Loading branch information
pussuw committed Oct 22, 2024
1 parent b4a6d45 commit 00e9a16
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion drivers/syslog/syslog_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,39 @@
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: syslog_safe_to_block
*
* Description:
* Check if it is safe to block for write. If not, the write defaults to a
* non-blocking method.
*
* Input Parameters:
* None.
*
* Returned Value:
* true if it is safe to block; false otherwise.
*
****************************************************************************/

static bool syslog_safe_to_block(void)
{
FAR const struct tcb_s* rtcb;

if (up_interrupt_context() || sched_idletask())
{
return false;
}

rtcb = nxsched_self();
if (rtcb->sigdeliver != NULL)
{
return false;
}

return true;
}

/****************************************************************************
* Name: syslog_default_write
*
Expand All @@ -59,7 +92,7 @@ static ssize_t syslog_default_write(FAR const char *buffer, size_t buflen)
{
size_t nwritten;

if (up_interrupt_context() || sched_idletask())
if (!syslog_safe_to_block())
{
#ifdef CONFIG_SYSLOG_INTBUFFER
if (up_interrupt_context())
Expand Down

0 comments on commit 00e9a16

Please sign in to comment.