forked from pgaudit/set_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeprecated_gucs.h
84 lines (75 loc) · 2.32 KB
/
deprecated_gucs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -------------------------------------------------------------------------
*
* deprecated_gucs.h
*
* Definitions for deprecated set_user GUCs.
*
* Copyright (c) 2010-2021, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
#ifndef DEPRECATED_GUCS_H
#define DEPRECATED_GUCS_H
/*
* PostgreSQL GUC variable deprecation handling.
*/
#include "miscadmin.h"
#include "utils/guc.h"
static bool
check_set_user_list(char **newval, void **extra, GucSource source,
const char *depname, const char *newname, bool *notice)
{
/*
* Notify on the first non-default change for the Postmaster PID only.
*/
if (MyProcPid == PostmasterPid && source != PGC_S_DEFAULT && *notice)
{
ereport(NOTICE, (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
errmsg("deprecated GUC: set_user.%s", depname),
errhint("Use set_user.%s instead.", newname)));
*notice = false;
}
/*
* If the deprecated value is being set, allocate some memory to copy
* it to the new GUC, so they remain in sync. Do not free previous
* allocated value here, as set_string_field will handle that. A call
* to free here would only result in an invalid free in set_string_field.
*/
if (*newval)
{
*extra = strdup(*newval);
if (*extra == NULL)
{
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
}
return true;
}
#define DefineDeprecatedStringVariable(deprecated_name, new_name, old_value, new_value) \
DefineCustomStringVariable("set_user." #deprecated_name, \
"Deprecated: see \"set_user." #new_name "\"", \
NULL, &old_value, ALLOWLIST_WILDCARD, PGC_SIGHUP, GUC_NO_SHOW_ALL, \
check_ ##deprecated_name, assign_ ##deprecated_name, show_ ##deprecated_name)
#define DEPRECATED_GUC(deprecated_name, new_name, old_value, new_value) \
static char * old_value; \
static bool notice_ ##old_value = true; \
static bool \
check_ ##deprecated_name(char **newval, void **extra, GucSource source) \
{ \
return check_set_user_list(newval, extra, source, #deprecated_name, #new_name, ¬ice_ ##old_value); \
} \
static void \
assign_ ##deprecated_name (const char *newval, void *extra) \
{ \
if (extra) \
{ \
new_value = extra; \
} \
} \
static const char *show_ ##deprecated_name (void) \
{ \
return new_value; \
}
#endif /* DEPRECATED_GUCS_H */