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

Commite348043

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 parentdf5d5f1 commite348043

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
@@ -172,6 +172,7 @@ static void send_message_to_server_log(ErrorData *edata);
172172
staticvoidsend_message_to_frontend(ErrorData*edata);
173173
staticchar*expand_fmt_string(constchar*fmt,ErrorData*edata);
174174
staticconstchar*useful_strerror(interrnum);
175+
staticconstchar*get_errno_symbol(interrnum);
175176
staticconstchar*error_severity(intelevel);
176177
staticvoidappend_with_tabs(StringInfobuf,constchar*str);
177178
staticboolis_log_level_output(intelevel,intlog_min_level);
@@ -2928,7 +2929,7 @@ expand_fmt_string(const char *fmt, ErrorData *edata)
29282929
staticconstchar*
29292930
useful_strerror(interrnum)
29302931
{
2931-
/* this buffer is only used iferrno has a bogus value */
2932+
/* this buffer is only used ifstrerror() and get_errno_symbol() fail */
29322933
staticcharerrorstr_buf[48];
29332934
constchar*str;
29342935

@@ -2940,10 +2941,16 @@ useful_strerror(int errnum)
29402941
str=strerror(errnum);
29412942

29422943
/*
2943-
* Some strerror()s return an empty string for out-of-range errno. This is
2944-
* ANSI C spec compliant, but not exactly useful.
2944+
* Some strerror()s return an empty string for out-of-range errno.This
2945+
* is ANSI C spec compliant, but not exactly useful. Also, we may get
2946+
* back strings of question marks if libc cannot transcode the message to
2947+
* the codeset specified by LC_CTYPE. If we get nothing useful, first try
2948+
* get_errno_symbol(), and if that fails, print the numeric errno.
29452949
*/
2946-
if (str==NULL||*str=='\0')
2950+
if (str==NULL||*str=='\0'||*str=='?')
2951+
str=get_errno_symbol(errnum);
2952+
2953+
if (str==NULL)
29472954
{
29482955
snprintf(errorstr_buf,sizeof(errorstr_buf),
29492956
/*------
@@ -2956,6 +2963,178 @@ useful_strerror(int errnum)
29562963
returnstr;
29572964
}
29582965

2966+
/*
2967+
* Returns a symbol (e.g. "ENOENT") for an errno code.
2968+
* Returns NULL if the code is unrecognized.
2969+
*/
2970+
staticconstchar*
2971+
get_errno_symbol(interrnum)
2972+
{
2973+
switch (errnum)
2974+
{
2975+
caseE2BIG:
2976+
return"E2BIG";
2977+
caseEACCES:
2978+
return"EACCES";
2979+
#ifdefEADDRINUSE
2980+
caseEADDRINUSE:
2981+
return"EADDRINUSE";
2982+
#endif
2983+
#ifdefEADDRNOTAVAIL
2984+
caseEADDRNOTAVAIL:
2985+
return"EADDRNOTAVAIL";
2986+
#endif
2987+
caseEAFNOSUPPORT:
2988+
return"EAFNOSUPPORT";
2989+
#ifdefEAGAIN
2990+
caseEAGAIN:
2991+
return"EAGAIN";
2992+
#endif
2993+
#ifdefEALREADY
2994+
caseEALREADY:
2995+
return"EALREADY";
2996+
#endif
2997+
caseEBADF:
2998+
return"EBADF";
2999+
#ifdefEBADMSG
3000+
caseEBADMSG:
3001+
return"EBADMSG";
3002+
#endif
3003+
caseEBUSY:
3004+
return"EBUSY";
3005+
caseECHILD:
3006+
return"ECHILD";
3007+
#ifdefECONNABORTED
3008+
caseECONNABORTED:
3009+
return"ECONNABORTED";
3010+
#endif
3011+
caseECONNREFUSED:
3012+
return"ECONNREFUSED";
3013+
#ifdefECONNRESET
3014+
caseECONNRESET:
3015+
return"ECONNRESET";
3016+
#endif
3017+
caseEDEADLK:
3018+
return"EDEADLK";
3019+
caseEDOM:
3020+
return"EDOM";
3021+
caseEEXIST:
3022+
return"EEXIST";
3023+
caseEFAULT:
3024+
return"EFAULT";
3025+
caseEFBIG:
3026+
return"EFBIG";
3027+
#ifdefEHOSTUNREACH
3028+
caseEHOSTUNREACH:
3029+
return"EHOSTUNREACH";
3030+
#endif
3031+
caseEIDRM:
3032+
return"EIDRM";
3033+
caseEINPROGRESS:
3034+
return"EINPROGRESS";
3035+
caseEINTR:
3036+
return"EINTR";
3037+
caseEINVAL:
3038+
return"EINVAL";
3039+
caseEIO:
3040+
return"EIO";
3041+
#ifdefEISCONN
3042+
caseEISCONN:
3043+
return"EISCONN";
3044+
#endif
3045+
caseEISDIR:
3046+
return"EISDIR";
3047+
#ifdefELOOP
3048+
caseELOOP:
3049+
return"ELOOP";
3050+
#endif
3051+
caseEMFILE:
3052+
return"EMFILE";
3053+
caseEMLINK:
3054+
return"EMLINK";
3055+
caseEMSGSIZE:
3056+
return"EMSGSIZE";
3057+
caseENAMETOOLONG:
3058+
return"ENAMETOOLONG";
3059+
caseENFILE:
3060+
return"ENFILE";
3061+
caseENOBUFS:
3062+
return"ENOBUFS";
3063+
caseENODEV:
3064+
return"ENODEV";
3065+
caseENOENT:
3066+
return"ENOENT";
3067+
caseENOEXEC:
3068+
return"ENOEXEC";
3069+
caseENOMEM:
3070+
return"ENOMEM";
3071+
caseENOSPC:
3072+
return"ENOSPC";
3073+
caseENOSYS:
3074+
return"ENOSYS";
3075+
#ifdefENOTCONN
3076+
caseENOTCONN:
3077+
return"ENOTCONN";
3078+
#endif
3079+
caseENOTDIR:
3080+
return"ENOTDIR";
3081+
#if defined(ENOTEMPTY)&& (ENOTEMPTY!=EEXIST)/* same code on AIX */
3082+
caseENOTEMPTY:
3083+
return"ENOTEMPTY";
3084+
#endif
3085+
#ifdefENOTSOCK
3086+
caseENOTSOCK:
3087+
return"ENOTSOCK";
3088+
#endif
3089+
#ifdefENOTSUP
3090+
caseENOTSUP:
3091+
return"ENOTSUP";
3092+
#endif
3093+
caseENOTTY:
3094+
return"ENOTTY";
3095+
caseENXIO:
3096+
return"ENXIO";
3097+
#if defined(EOPNOTSUPP)&& (!defined(ENOTSUP)|| (EOPNOTSUPP!=ENOTSUP))
3098+
caseEOPNOTSUPP:
3099+
return"EOPNOTSUPP";
3100+
#endif
3101+
#ifdefEOVERFLOW
3102+
caseEOVERFLOW:
3103+
return"EOVERFLOW";
3104+
#endif
3105+
caseEPERM:
3106+
return"EPERM";
3107+
caseEPIPE:
3108+
return"EPIPE";
3109+
caseEPROTONOSUPPORT:
3110+
return"EPROTONOSUPPORT";
3111+
caseERANGE:
3112+
return"ERANGE";
3113+
#ifdefEROFS
3114+
caseEROFS:
3115+
return"EROFS";
3116+
#endif
3117+
caseESRCH:
3118+
return"ESRCH";
3119+
#ifdefETIMEDOUT
3120+
caseETIMEDOUT:
3121+
return"ETIMEDOUT";
3122+
#endif
3123+
#ifdefETXTBSY
3124+
caseETXTBSY:
3125+
return"ETXTBSY";
3126+
#endif
3127+
#if defined(EWOULDBLOCK)&& (!defined(EAGAIN)|| (EWOULDBLOCK!=EAGAIN))
3128+
caseEWOULDBLOCK:
3129+
return"EWOULDBLOCK";
3130+
#endif
3131+
caseEXDEV:
3132+
return"EXDEV";
3133+
}
3134+
3135+
returnNULL;
3136+
}
3137+
29593138

29603139
/*
29613140
* error_severity --- get localized string representing elevel

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp