Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c94ae9d

Browse files
committed
Emulate sigprocmask(), not sigsetmask(), on Windows.
Since commit a65e086, we've required Unix systems to have sigprocmask(). As noted in that commit's message, we were still emulating the historical pre-standard sigsetmask() function in our Windows support code. Emulate standard sigprocmask() instead, for consistency. The PG_SETMASK() abstraction is now redundant and all calls could in theory be replaced by plain sigprocmask() calls, but that isn't done by this commit. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/3153247.1657834482%40sss.pgh.pa.us
1 parent 3b8d23a commit c94ae9d

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/backend/port/win32/signal.c

+23-6
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pgwin32_signal_initialize(void)
112112
/*
113113
* Dispatch all signals currently queued and not blocked
114114
* Blocked signals are ignored, and will be fired at the time of
115-
* the pqsigsetmask() call.
115+
* the pqsigprocmask() call.
116116
*/
117117
void
118118
pgwin32_dispatch_queued_signals(void)
@@ -154,20 +154,37 @@ pgwin32_dispatch_queued_signals(void)
154154

155155
/* signal masking. Only called on main thread, no sync required */
156156
int
157-
pqsigsetmask(int mask)
157+
pqsigprocmask(int how, const sigset_t *set, sigset_t *oset)
158158
{
159-
int prevmask;
159+
if (oset)
160+
*oset = pg_signal_mask;
160161

161-
prevmask = pg_signal_mask;
162-
pg_signal_mask = mask;
162+
if (!set)
163+
return 0;
164+
165+
switch (how)
166+
{
167+
case SIG_BLOCK:
168+
pg_signal_mask |= *set;
169+
break;
170+
case SIG_UNBLOCK:
171+
pg_signal_mask &= ~*set;
172+
break;
173+
case SIG_SETMASK:
174+
pg_signal_mask = *set;
175+
break;
176+
default:
177+
errno = EINVAL;
178+
return -1;
179+
}
163180

164181
/*
165182
* Dispatch any signals queued up right away, in case we have unblocked
166183
* one or more signals previously queued
167184
*/
168185
pgwin32_dispatch_queued_signals();
169186

170-
return prevmask;
187+
return 0;
171188
}
172189

173190

src/include/libpq/pqsignal.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515

1616
#include <signal.h>
1717

18-
#ifndef WIN32
1918
#define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL)
20-
#else
19+
20+
#ifdef WIN32
2121
/* Emulate POSIX sigset_t APIs on Windows */
2222
typedef int sigset_t;
2323

24-
extern int pqsigsetmask(int mask);
24+
extern int pqsigprocmask(int how, const sigset_t *set, sigset_t *oset);
2525

26-
#define PG_SETMASK(mask) pqsigsetmask(*(mask))
26+
#define SIG_BLOCK 1
27+
#define SIG_UNBLOCK 2
28+
#define SIG_SETMASK 3
29+
#define sigprocmask(how, set, oset) pqsigprocmask((how), (set), (oset))
2730
#define sigemptyset(set) (*(set) = 0)
2831
#define sigfillset(set) (*(set) = ~0)
2932
#define sigaddset(set, signum) (*(set) |= (sigmask(signum)))

0 commit comments

Comments
 (0)