From 6886e3c0f6ca692ca8c50bc1886d7e60b7c9508a Mon Sep 17 00:00:00 2001 From: Jakub Wartak Date: Mon, 13 Apr 2026 11:24:20 +0200 Subject: [PATCH 2/2] fixup-win32 --- src/backend/port/win32/signal.c | 13 ++++++++----- src/include/c.h | 5 +++-- src/include/port.h | 4 ++-- src/port/pqsignal.c | 24 +++++++++++++++++------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/backend/port/win32/signal.c b/src/backend/port/win32/signal.c index 465d69a1f28..d7cdb1cd1fe 100644 --- a/src/backend/port/win32/signal.c +++ b/src/backend/port/win32/signal.c @@ -88,7 +88,7 @@ pgwin32_signal_initialize(void) pg_signal_array[i].sa_handler = SIG_DFL; pg_signal_array[i].sa_mask = 0; pg_signal_array[i].sa_flags = 0; - pg_signal_defaults[i] = SIG_IGN; + pg_signal_defaults[i] = PG_SIG_IGN; } pg_signal_mask = 0; pg_signal_queue = 0; @@ -134,15 +134,18 @@ pgwin32_dispatch_queued_signals(void) { /* Execute this signal */ struct sigaction *act = &pg_signal_array[i]; - pqsigfunc sig = act->sa_handler; + pqsigfunc sig = (pqsigfunc)(pg_funcptr_t) act->sa_handler; - if (sig == SIG_DFL) + if (sig == PG_SIG_DFL) sig = pg_signal_defaults[i]; pg_signal_queue &= ~sigmask(i); - if (sig != SIG_ERR && sig != SIG_IGN && sig != SIG_DFL) + if (sig != (pqsigfunc)(pg_funcptr_t)SIG_ERR && sig != PG_SIG_IGN && sig != PG_SIG_DFL) { sigset_t block_mask; sigset_t save_mask; + struct pg_signal_info nodata; + nodata.pid = 0; + nodata.uid = 0; LeaveCriticalSection(&pg_signal_crit_sec); @@ -151,7 +154,7 @@ pgwin32_dispatch_queued_signals(void) block_mask |= sigmask(i); sigprocmask(SIG_BLOCK, &block_mask, &save_mask); - sig(i); + sig(i, &nodata); sigprocmask(SIG_SETMASK, &save_mask, NULL); EnterCriticalSection(&pg_signal_crit_sec); diff --git a/src/include/c.h b/src/include/c.h index 77ea73cc707..b43ac8e995d 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1446,10 +1446,11 @@ extern int fdatasync(int fd); * or a field does not apply to the signal, the value is instead reset to the * documented default value. */ + typedef struct pg_signal_info { - pid_t pid; /* pid of sending process or 0 if unknown */ - uid_t uid; /* uid of sending process or 0 if unknown */ + uint32_t pid; /* pid of sending process or 0 if unknown */ + uint32_t uid; /* uid of sending process or 0 if unknown */ } pg_signal_info; /* diff --git a/src/include/port.h b/src/include/port.h index 7db476d7b01..c029878c6be 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -547,8 +547,8 @@ extern int pg_mkdir_p(char *path, int omode); #define pqsignal pqsignal_be #endif -#define PG_SIG_DFL (pqsigfunc) SIG_DFL -#define PG_SIG_IGN (pqsigfunc) SIG_IGN +#define PG_SIG_DFL (pqsigfunc) (pg_funcptr_t) SIG_DFL +#define PG_SIG_IGN (pqsigfunc) (pg_funcptr_t) SIG_IGN typedef void (*pqsigfunc) (SIGNAL_ARGS); extern void pqsignal(int signo, pqsigfunc func); diff --git a/src/port/pqsignal.c b/src/port/pqsignal.c index 2b39be99f94..dfa5acbb139 100644 --- a/src/port/pqsignal.c +++ b/src/port/pqsignal.c @@ -90,10 +90,10 @@ static volatile pqsigfunc pqsignal_handlers[PG_NSIG]; * * This wrapper also handles restoring the value of errno. */ -#ifdef USE_SIGACTION +#if defined(USE_SIGACTION) && defined(USE_SIGINFO) static void wrapper_handler(int postgres_signal_arg, siginfo_t *info, void *context) -#else +#else /* no USE_SIGINFO */ static void wrapper_handler(int postgres_signal_arg) #endif @@ -157,6 +157,8 @@ pqsignal(int signo, pqsigfunc func) { #ifdef USE_SIGACTION struct sigaction act; +#else + void (*wrapper_func_ptr)(int); #endif bool is_ign = func == PG_SIG_IGN; bool is_dfl = func == PG_SIG_DFL; @@ -182,14 +184,12 @@ pqsignal(int signo, pqsigfunc func) act.sa_handler = SIG_IGN; else if (is_dfl) act.sa_handler = SIG_DFL; - #ifdef USE_SIGINFO if (!(is_ign || is_dfl)) { act.sa_sigaction = wrapper_handler; act.sa_flags |= SA_SIGINFO; } - else #else else act.sa_handler = wrapper_handler; @@ -201,9 +201,19 @@ pqsignal(int signo, pqsigfunc func) #endif if (sigaction(signo, &act, NULL) < 0) Assert(false); /* probably indicates coding error */ -#else - /* Forward to Windows native signal system. */ - if (signal(signo, use_wrapper ? wrapper_handler : func) == SIG_ERR) +#else /* no USE_SIGACTION */ + /* + * Forward to Windows native signal system, we need to send this though + * wrapper handler as it it needs to take single argument only. + */ + if(is_ign) + wrapper_func_ptr = SIG_IGN; + else if (is_dfl) + wrapper_func_ptr = SIG_DFL; + else + wrapper_func_ptr = wrapper_handler; + + if (signal(signo, wrapper_func_ptr) == SIG_ERR) Assert(false); /* probably indicates coding error */ #endif } -- 2.43.0