Date: Fri, 23 Oct 2020 23:56:00 +0000 (UTC) From: Warner Losh <imp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366982 - head/lib/libc/gen Message-ID: <202010232356.09NNu0Iw087335@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: imp Date: Fri Oct 23 23:56:00 2020 New Revision: 366982 URL: https://svnweb.freebsd.org/changeset/base/366982 Log: warnx: Save errno across calls that might change it. When warn() family of functions is being used after err_set_file() has been set to, for example, /dev/null, errno is being clobbered, rendering it unreliable after, for example, procstat_getpathname() when it is supposed to emit a warning. Then the errno is changed to Inappropriate ioctl for device, destroying the original value (via calls to fprintf()functions). Submitted by: Juraj Lutter Differential Revision: https://reviews.freebsd.org/D26871 Modified: head/lib/libc/gen/err.c Modified: head/lib/libc/gen/err.c ============================================================================== --- head/lib/libc/gen/err.c Fri Oct 23 22:27:45 2020 (r366981) +++ head/lib/libc/gen/err.c Fri Oct 23 23:56:00 2020 (r366982) @@ -161,6 +161,9 @@ warnc(int code, const char *fmt, ...) void vwarnc(int code, const char *fmt, va_list ap) { + static int saved_errno; + + saved_errno = errno; if (err_file == NULL) err_set_file(NULL); fprintf(err_file, "%s: ", _getprogname()); @@ -169,6 +172,7 @@ vwarnc(int code, const char *fmt, va_list ap) fprintf(err_file, ": "); } fprintf(err_file, "%s\n", strerror(code)); + errno = saved_errno; } void @@ -183,10 +187,14 @@ warnx(const char *fmt, ...) void vwarnx(const char *fmt, va_list ap) { + static int saved_errno; + + saved_errno = errno; if (err_file == NULL) err_set_file(NULL); fprintf(err_file, "%s: ", _getprogname()); if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); + errno = saved_errno; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202010232356.09NNu0Iw087335>