standards/72394: [PATCH] syslog is not thread-safe

Dan Nelson dnelson at allantgroup.com
Wed Oct 6 23:01:01 PDT 2004


The following reply was made to PR standards/72394; it has been noted by GNATS.

From: Dan Nelson <dnelson at allantgroup.com>
To: FreeBSD-gnats-submit at FreeBSD.org
Cc:  
Subject: Re: standards/72394: [PATCH] syslog is not thread-safe
Date: Thu, 7 Oct 2004 00:58:43 -0500

 Update: if errno isn't valid, strerror() isn't thread-safe, so here's
 an addon patch that uses strerror_r instead:
 
 --- syslog.c~	Thu Oct  7 00:39:44 2004
 +++ syslog.c	Thu Oct  7 00:49:06 2004
 @@ -139,7 +139,7 @@ vsyslog(pri, fmt, ap)
  	char ch, *p;
  	time_t now;
  	int fd, saved_errno;
 -	char *stdp, tbuf[2048], fmt_cpy[1024], timbuf[26];
 +	char *stdp, tbuf[2048], fmt_cpy[1024], timbuf[26], errstr[64];
  	FILE *fp, *fmt_fp;
  	struct bufcookie tbuf_cookie;
  	struct bufcookie fmt_cookie;
 @@ -215,7 +215,8 @@ vsyslog(pri, fmt, ap)
  		for ( ; (ch = *fmt); ++fmt) {
  			if (ch == '%' && fmt[1] == 'm') {
  				++fmt;
 -				fputs(strerror(saved_errno), fmt_fp);
 +				strerror_r(saved_errno, errstr, sizeof(errstr));
 +				fputs(errstr, fmt_fp);
  			} else if (ch == '%' && fmt[1] == '%') {
  				++fmt;
  				fputc(ch, fmt_fp);
 
 


More information about the freebsd-standards mailing list