Bug 8656 - Flood of syslog() calls temporarily blocks process
Summary: Flood of syslog() calls temporarily blocks process
Status: NEW
Alias: None
Product: uClibc
Classification: Unclassified
Component: Other (show other bugs)
Version: 0.9.33.2
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-05 12:51 UTC by Martin Lottermoser
Modified: 2016-02-05 12:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Lottermoser 2016-02-05 12:51:21 UTC
On an AMD-Elan-based system with Linux 2.6.32 and uClibc 0.9.33.2, a flood of syslog() calls in a real-time process led to the process freezing up for about two seconds.

This was caused by the following code in libc/misc/syslog/sylog.c, vsyslog():

 write_err:
	/*
	 * Output the message to the console; don't worry about blocking,
	 * if console blocks everything will.  Make sure the error reported
	 * is the one from the syslogd failure.
	 */
	/* should mode be O_WRONLY | O_NOCTTY? -- Uli */
	/* yes, but in Linux "/dev/console" never becomes ctty anyway -- vda */
	if ((LogStat & LOG_CONS) &&
	    (fd = open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY)) >= 0) {
		p = strchr(tbuf, '>') + 1;
		last_chr[0] = '\r';
		last_chr[1] = '\n';
		(void)write(fd, p, last_chr - p + 2);
		(void)close(fd);
	}

The system in question had a serial console, configured for 19.2 kb/s with 8N1. The kernel's internal buffer for that console has a size of UART_XMIT_SIZE, i.e., 4096 bytes. Transmitting 4096 bytes at 19.2 kb/s with 8N1 requires 2.1 seconds.

Adding O_NONBLOCK to the open() call above fixed the problem, i.e., the comment a few lines above that call seems unnecessarily optimistic.