Skip to content

Commit ed1da4a

Browse files
author
Commitfest Bot
committed
[CF 6139] v7 - Invalid primary_slot_name triggers warnings in all processes on reload
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/6139 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAHGQGwHJxhaQQ7bf_wPBYBTJO+X+rK_-znsgay_kYm2ncJYAGQ@mail.gmail.com Author(s): Fujii Masao
2 parents f33e60a + ec9e727 commit ed1da4a

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

src/backend/access/transam/xlogrecovery.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,10 +4769,16 @@ check_primary_slot_name(char **newval, void **extra, GucSource source)
47694769
!ReplicationSlotValidateNameInternal(*newval, false, &err_code,
47704770
&err_msg, &err_hint))
47714771
{
4772+
/*
4773+
* Use GUC_check_errdetail_internal() and GUC_check_errhint_internal()
4774+
* instead of GUC_check_errdetail() and GUC_check_errhint(), since the
4775+
* messages from ReplicationSlotValidateNameInternal() are already
4776+
* translated. This avoids double translation.
4777+
*/
47724778
GUC_check_errcode(err_code);
4773-
GUC_check_errdetail("%s", err_msg);
4779+
GUC_check_errdetail_internal("%s", err_msg);
47744780
if (err_hint != NULL)
4775-
GUC_check_errhint("%s", err_hint);
4781+
GUC_check_errhint_internal("%s", err_hint);
47764782
return false;
47774783
}
47784784

src/backend/utils/error/elog.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,37 @@ format_elog_string(const char *fmt,...)
16921692
return edata->message;
16931693
}
16941694

1695+
/*
1696+
* This is exactly like format_elog_string() except that strings passed to
1697+
* format_elog_string_internal are not translated, and are customarily left
1698+
* out of the internationalization message dictionary. This should be used
1699+
* when the passed strings have already been translated.
1700+
*/
1701+
char *
1702+
format_elog_string_internal(const char *fmt,...)
1703+
{
1704+
ErrorData errdata;
1705+
ErrorData *edata;
1706+
MemoryContext oldcontext;
1707+
1708+
/* Initialize a mostly-dummy error frame */
1709+
edata = &errdata;
1710+
MemSet(edata, 0, sizeof(ErrorData));
1711+
/* the default text domain is the backend's */
1712+
edata->domain = save_format_domain ? save_format_domain : PG_TEXTDOMAIN("postgres");
1713+
/* set the errno to be used to interpret %m */
1714+
edata->saved_errno = save_format_errnumber;
1715+
1716+
oldcontext = MemoryContextSwitchTo(ErrorContext);
1717+
1718+
edata->message_id = fmt;
1719+
EVALUATE_MESSAGE(edata->domain, message, false, false);
1720+
1721+
MemoryContextSwitchTo(oldcontext);
1722+
1723+
return edata->message;
1724+
}
1725+
16951726

16961727
/*
16971728
* Actual output of the top-of-stack error message

src/include/utils/elog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ extern void errsave_finish(struct Node *context,
302302

303303
extern void pre_format_elog_string(int errnumber, const char *domain);
304304
extern char *format_elog_string(const char *fmt,...) pg_attribute_printf(1, 2);
305+
extern char *format_elog_string_internal(const char *fmt,...) pg_attribute_printf(1, 2);
305306

306307

307308
/* Support for attaching context information to error reports */

src/include/utils/guc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,22 @@ extern void GUC_check_errcode(int sqlerrcode);
510510
pre_format_elog_string(errno, TEXTDOMAIN), \
511511
GUC_check_errhint_string = format_elog_string
512512

513+
/*
514+
* These are exactly like GUC_check_errmsg/errdtail/errhint except that
515+
* strings passed to them are not translated, and are customarily left
516+
* out of the internationalization message dictionary. This should be used
517+
* when the passed strings have already been translated.
518+
*/
519+
#define GUC_check_errmsg_internal \
520+
pre_format_elog_string(errno, TEXTDOMAIN), \
521+
GUC_check_errmsg_string = format_elog_string_internal
522+
523+
#define GUC_check_errdetail_internal \
524+
pre_format_elog_string(errno, TEXTDOMAIN), \
525+
GUC_check_errdetail_string = format_elog_string_internal
526+
527+
#define GUC_check_errhint_internal \
528+
pre_format_elog_string(errno, TEXTDOMAIN), \
529+
GUC_check_errhint_string = format_elog_string_internal
530+
513531
#endif /* GUC_H */

0 commit comments

Comments
 (0)