mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-12-28 16:15:02 +01:00
24148: attempt to use strerror_r() to make errors in signal handle safer
This commit is contained in:
parent
9794b45477
commit
61320c44c1
3 changed files with 41 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
2007-12-03 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
||||
* 24148: configure.ac, Src/utils.c: attempt to use strerror_r()
|
||||
to make error messages in signal handle safer.
|
||||
|
||||
2007-12-03 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 24143: Etc/zsh-development-guide, Util/.distfiles: Remove
|
||||
|
|
37
Src/utils.c
37
Src/utils.c
|
@ -255,6 +255,12 @@ zerrmsg(FILE *file, const char *fmt, va_list ap)
|
|||
{
|
||||
const char *str;
|
||||
int num;
|
||||
#ifdef HAVE_STRERROR_R
|
||||
#define ERRBUFSIZE (80)
|
||||
int olderrno;
|
||||
char errbuf[ERRBUFSIZE];
|
||||
#endif
|
||||
char *errmsg;
|
||||
|
||||
if ((unset(SHINSTDIN) || locallevel) && lineno)
|
||||
fprintf(file, "%ld: ", (long)lineno);
|
||||
|
@ -304,12 +310,39 @@ zerrmsg(FILE *file, const char *fmt, va_list ap)
|
|||
errflag = 1;
|
||||
return;
|
||||
}
|
||||
#ifdef HAVE_STRERROR_R
|
||||
/*
|
||||
* There are two incompatible strerror_r()s floating round.
|
||||
* The GNU extension refuses to copy the message into the
|
||||
* buffer if it can return a constant string. To suppress it
|
||||
* we need to define _XOPEN_SOURCE to 600. I don't dare do
|
||||
* this because we're already depending on _GNU_SOURCE. So
|
||||
* try to handle both by looking for errno being set (for the
|
||||
* standard version failing) or errbuf being left untouched
|
||||
* (for the GNU version). One presumes that if strerror_r()
|
||||
* didn't copy anything to errbuf, then it's safe to
|
||||
* call strerror() to get the string.
|
||||
*
|
||||
* This is a mess, but it's about a decade and half
|
||||
* too late to shirk from messes in the source.
|
||||
*/
|
||||
olderrno = errno;
|
||||
errno = 0;
|
||||
errbuf[0] = '\0';
|
||||
strerror_r(num, errbuf, ERRBUFSIZE);
|
||||
if (errno || errbuf[0] == '\0')
|
||||
errmsg = strerror(num);
|
||||
else
|
||||
errmsg = errbuf;
|
||||
errno = olderrno;
|
||||
#else
|
||||
errmsg = strerror(num);
|
||||
#endif
|
||||
/* If the message is not about I/O problems, it looks better *
|
||||
* if we uncapitalize the first letter of the message */
|
||||
if (num == EIO)
|
||||
fputs(strerror(num), file);
|
||||
fputs(errmsg, file);
|
||||
else {
|
||||
char *errmsg = strerror(num);
|
||||
fputc(tulower(errmsg[0]), file);
|
||||
fputs(errmsg + 1, file);
|
||||
}
|
||||
|
|
|
@ -1157,7 +1157,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
|
|||
getlogin getpwent getpwnam getpwuid getgrgid getgrnam \
|
||||
initgroups nis_list \
|
||||
setuid seteuid setreuid setresuid setsid \
|
||||
memcpy memmove strstr strerror \
|
||||
memcpy memmove strstr strerror strerror_r \
|
||||
getrlimit getrusage \
|
||||
setlocale \
|
||||
uname \
|
||||
|
|
Loading…
Reference in a new issue