Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8cfd4c6

Browse files
committed
Be more robust when strerror() doesn't give a useful result.
Back-patch commits8e68816 and8dace66 into the stable branches.Buildfarm testing revealed no great portability surprises, and itseems useful to have this robustness improvement in all branches.
1 parent6e2c762 commit8cfd4c6

File tree

1 file changed

+183
-4
lines changed

1 file changed

+183
-4
lines changed

‎src/backend/utils/error/elog.c‎

Lines changed: 183 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static void send_message_to_server_log(ErrorData *edata);
160160
staticvoidsend_message_to_frontend(ErrorData*edata);
161161
staticchar*expand_fmt_string(constchar*fmt,ErrorData*edata);
162162
staticconstchar*useful_strerror(interrnum);
163+
staticconstchar*get_errno_symbol(interrnum);
163164
staticconstchar*error_severity(intelevel);
164165
staticvoidappend_with_tabs(StringInfobuf,constchar*str);
165166
staticboolis_log_level_output(intelevel,intlog_min_level);
@@ -2748,7 +2749,7 @@ expand_fmt_string(const char *fmt, ErrorData *edata)
27482749
staticconstchar*
27492750
useful_strerror(interrnum)
27502751
{
2751-
/* this buffer is only used iferrno has a bogus value */
2752+
/* this buffer is only used ifstrerror() and get_errno_symbol() fail */
27522753
staticcharerrorstr_buf[48];
27532754
constchar*str;
27542755

@@ -2760,10 +2761,16 @@ useful_strerror(int errnum)
27602761
str=strerror(errnum);
27612762

27622763
/*
2763-
* Some strerror()s return an empty string for out-of-range errno. This is
2764-
* ANSI C spec compliant, but not exactly useful.
2764+
* Some strerror()s return an empty string for out-of-range errno.This
2765+
* is ANSI C spec compliant, but not exactly useful. Also, we may get
2766+
* back strings of question marks if libc cannot transcode the message to
2767+
* the codeset specified by LC_CTYPE. If we get nothing useful, first try
2768+
* get_errno_symbol(), and if that fails, print the numeric errno.
27652769
*/
2766-
if (str==NULL||*str=='\0')
2770+
if (str==NULL||*str=='\0'||*str=='?')
2771+
str=get_errno_symbol(errnum);
2772+
2773+
if (str==NULL)
27672774
{
27682775
snprintf(errorstr_buf,sizeof(errorstr_buf),
27692776
/*------
@@ -2776,6 +2783,178 @@ useful_strerror(int errnum)
27762783
returnstr;
27772784
}
27782785

2786+
/*
2787+
* Returns a symbol (e.g. "ENOENT") for an errno code.
2788+
* Returns NULL if the code is unrecognized.
2789+
*/
2790+
staticconstchar*
2791+
get_errno_symbol(interrnum)
2792+
{
2793+
switch (errnum)
2794+
{
2795+
caseE2BIG:
2796+
return"E2BIG";
2797+
caseEACCES:
2798+
return"EACCES";
2799+
#ifdefEADDRINUSE
2800+
caseEADDRINUSE:
2801+
return"EADDRINUSE";
2802+
#endif
2803+
#ifdefEADDRNOTAVAIL
2804+
caseEADDRNOTAVAIL:
2805+
return"EADDRNOTAVAIL";
2806+
#endif
2807+
caseEAFNOSUPPORT:
2808+
return"EAFNOSUPPORT";
2809+
#ifdefEAGAIN
2810+
caseEAGAIN:
2811+
return"EAGAIN";
2812+
#endif
2813+
#ifdefEALREADY
2814+
caseEALREADY:
2815+
return"EALREADY";
2816+
#endif
2817+
caseEBADF:
2818+
return"EBADF";
2819+
#ifdefEBADMSG
2820+
caseEBADMSG:
2821+
return"EBADMSG";
2822+
#endif
2823+
caseEBUSY:
2824+
return"EBUSY";
2825+
caseECHILD:
2826+
return"ECHILD";
2827+
#ifdefECONNABORTED
2828+
caseECONNABORTED:
2829+
return"ECONNABORTED";
2830+
#endif
2831+
caseECONNREFUSED:
2832+
return"ECONNREFUSED";
2833+
#ifdefECONNRESET
2834+
caseECONNRESET:
2835+
return"ECONNRESET";
2836+
#endif
2837+
caseEDEADLK:
2838+
return"EDEADLK";
2839+
caseEDOM:
2840+
return"EDOM";
2841+
caseEEXIST:
2842+
return"EEXIST";
2843+
caseEFAULT:
2844+
return"EFAULT";
2845+
caseEFBIG:
2846+
return"EFBIG";
2847+
#ifdefEHOSTUNREACH
2848+
caseEHOSTUNREACH:
2849+
return"EHOSTUNREACH";
2850+
#endif
2851+
caseEIDRM:
2852+
return"EIDRM";
2853+
caseEINPROGRESS:
2854+
return"EINPROGRESS";
2855+
caseEINTR:
2856+
return"EINTR";
2857+
caseEINVAL:
2858+
return"EINVAL";
2859+
caseEIO:
2860+
return"EIO";
2861+
#ifdefEISCONN
2862+
caseEISCONN:
2863+
return"EISCONN";
2864+
#endif
2865+
caseEISDIR:
2866+
return"EISDIR";
2867+
#ifdefELOOP
2868+
caseELOOP:
2869+
return"ELOOP";
2870+
#endif
2871+
caseEMFILE:
2872+
return"EMFILE";
2873+
caseEMLINK:
2874+
return"EMLINK";
2875+
caseEMSGSIZE:
2876+
return"EMSGSIZE";
2877+
caseENAMETOOLONG:
2878+
return"ENAMETOOLONG";
2879+
caseENFILE:
2880+
return"ENFILE";
2881+
caseENOBUFS:
2882+
return"ENOBUFS";
2883+
caseENODEV:
2884+
return"ENODEV";
2885+
caseENOENT:
2886+
return"ENOENT";
2887+
caseENOEXEC:
2888+
return"ENOEXEC";
2889+
caseENOMEM:
2890+
return"ENOMEM";
2891+
caseENOSPC:
2892+
return"ENOSPC";
2893+
caseENOSYS:
2894+
return"ENOSYS";
2895+
#ifdefENOTCONN
2896+
caseENOTCONN:
2897+
return"ENOTCONN";
2898+
#endif
2899+
caseENOTDIR:
2900+
return"ENOTDIR";
2901+
#if defined(ENOTEMPTY)&& (ENOTEMPTY!=EEXIST)/* same code on AIX */
2902+
caseENOTEMPTY:
2903+
return"ENOTEMPTY";
2904+
#endif
2905+
#ifdefENOTSOCK
2906+
caseENOTSOCK:
2907+
return"ENOTSOCK";
2908+
#endif
2909+
#ifdefENOTSUP
2910+
caseENOTSUP:
2911+
return"ENOTSUP";
2912+
#endif
2913+
caseENOTTY:
2914+
return"ENOTTY";
2915+
caseENXIO:
2916+
return"ENXIO";
2917+
#if defined(EOPNOTSUPP)&& (!defined(ENOTSUP)|| (EOPNOTSUPP!=ENOTSUP))
2918+
caseEOPNOTSUPP:
2919+
return"EOPNOTSUPP";
2920+
#endif
2921+
#ifdefEOVERFLOW
2922+
caseEOVERFLOW:
2923+
return"EOVERFLOW";
2924+
#endif
2925+
caseEPERM:
2926+
return"EPERM";
2927+
caseEPIPE:
2928+
return"EPIPE";
2929+
caseEPROTONOSUPPORT:
2930+
return"EPROTONOSUPPORT";
2931+
caseERANGE:
2932+
return"ERANGE";
2933+
#ifdefEROFS
2934+
caseEROFS:
2935+
return"EROFS";
2936+
#endif
2937+
caseESRCH:
2938+
return"ESRCH";
2939+
#ifdefETIMEDOUT
2940+
caseETIMEDOUT:
2941+
return"ETIMEDOUT";
2942+
#endif
2943+
#ifdefETXTBSY
2944+
caseETXTBSY:
2945+
return"ETXTBSY";
2946+
#endif
2947+
#if defined(EWOULDBLOCK)&& (!defined(EAGAIN)|| (EWOULDBLOCK!=EAGAIN))
2948+
caseEWOULDBLOCK:
2949+
return"EWOULDBLOCK";
2950+
#endif
2951+
caseEXDEV:
2952+
return"EXDEV";
2953+
}
2954+
2955+
returnNULL;
2956+
}
2957+
27792958

27802959
/*
27812960
* error_severity --- get localized string representing elevel

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp