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

Commit64f5962

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 parent8bd5a6a commit64f5962

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
@@ -170,6 +170,7 @@ static void send_message_to_server_log(ErrorData *edata);
170170
staticvoidsend_message_to_frontend(ErrorData*edata);
171171
staticchar*expand_fmt_string(constchar*fmt,ErrorData*edata);
172172
staticconstchar*useful_strerror(interrnum);
173+
staticconstchar*get_errno_symbol(interrnum);
173174
staticconstchar*error_severity(intelevel);
174175
staticvoidappend_with_tabs(StringInfobuf,constchar*str);
175176
staticboolis_log_level_output(intelevel,intlog_min_level);
@@ -2784,7 +2785,7 @@ expand_fmt_string(const char *fmt, ErrorData *edata)
27842785
staticconstchar*
27852786
useful_strerror(interrnum)
27862787
{
2787-
/* this buffer is only used iferrno has a bogus value */
2788+
/* this buffer is only used ifstrerror() and get_errno_symbol() fail */
27882789
staticcharerrorstr_buf[48];
27892790
constchar*str;
27902791

@@ -2796,10 +2797,16 @@ useful_strerror(int errnum)
27962797
str=strerror(errnum);
27972798

27982799
/*
2799-
* Some strerror()s return an empty string for out-of-range errno. This is
2800-
* ANSI C spec compliant, but not exactly useful.
2800+
* Some strerror()s return an empty string for out-of-range errno.This
2801+
* is ANSI C spec compliant, but not exactly useful. Also, we may get
2802+
* back strings of question marks if libc cannot transcode the message to
2803+
* the codeset specified by LC_CTYPE. If we get nothing useful, first try
2804+
* get_errno_symbol(), and if that fails, print the numeric errno.
28012805
*/
2802-
if (str==NULL||*str=='\0')
2806+
if (str==NULL||*str=='\0'||*str=='?')
2807+
str=get_errno_symbol(errnum);
2808+
2809+
if (str==NULL)
28032810
{
28042811
snprintf(errorstr_buf,sizeof(errorstr_buf),
28052812
/*------
@@ -2812,6 +2819,178 @@ useful_strerror(int errnum)
28122819
returnstr;
28132820
}
28142821

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

28162995
/*
28172996
* error_severity --- get localized string representing elevel

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp