Skip to content

Commit

Permalink
pg15 support
Browse files Browse the repository at this point in the history
  • Loading branch information
munakoiso committed Sep 2, 2022
1 parent 0eabc82 commit eb11ad6
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions logerrors.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void _PG_init(void);
void _PG_fini(void);

/* Shared memory init */
static void pgss_shmem_startup(void);
static void logerrors_shmem_startup(void);

/* Signal handling */
static volatile sig_atomic_t got_sigterm = false;
Expand All @@ -49,6 +49,10 @@ static char *worker_name = "logerrors";

static emit_log_hook_type prev_emit_log_hook = NULL;
static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
#if (PG_VERSION_NUM >= 150000)
static shmem_request_hook_type prev_shmem_request_hook = NULL;
static void logerrors_shmem_request(void);
#endif

char* excluded_errcodes_str= NULL;

Expand Down Expand Up @@ -387,10 +391,15 @@ _PG_init(void)
return;
}
prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = pgss_shmem_startup;
shmem_startup_hook = logerrors_shmem_startup;
prev_emit_log_hook = emit_log_hook;
emit_log_hook = logerrors_emit_log_hook;
#if (PG_VERSION_NUM >= 150000)
prev_shmem_request_hook = shmem_request_hook;
shmem_request_hook = logerrors_shmem_request;
#else
RequestAddinShmemSpace((sizeof(ErrorCode) + sizeof(ErrorName)) * error_codes_count + sizeof(GlobalInfo));
#endif
/* Worker parameter and registration */
MemSet(&worker, 0, sizeof(BackgroundWorker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
Expand All @@ -414,7 +423,7 @@ _PG_fini(void)
}

static void
pgss_shmem_startup(void) {
logerrors_shmem_startup(void) {
bool found;
HASHCTL ctl;
if (prev_shmem_startup_hook)
Expand All @@ -438,6 +447,20 @@ pgss_shmem_startup(void) {
return;
}

#if (PG_VERSION_NUM >= 150000)
/*
* Requests any additional shared memory required for our extension
*/
static void
logerrors_shmem_request(void)
{
if (prev_shmem_request_hook)
prev_shmem_request_hook();

RequestAddinShmemSpace((sizeof(ErrorCode) + sizeof(ErrorName)) * error_codes_count + sizeof(GlobalInfo));
}
#endif

PG_FUNCTION_INFO_V1(pg_log_errors_stats);

static void
Expand Down

0 comments on commit eb11ad6

Please sign in to comment.