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

Commit 56f8f96

Browse files
committed
Fix compilation failure of vacuumdb and reindexdb with OpenBSD
FD_SETSIZE is included in sys/select.h per POSIX, and this header inclusion has been moved to scripts_parallel.c as of 5f38403 without moving the variable, causing a compilation failure on recent versions of OpenBSD (6.6 was the version used in the report). In order to take care of the failure, move FD_SETSIZE directly to scripts_parallel.c with a wrapper controlling the maximum number of parallel slots supported, based on a suggestion by Andres Freund. While on it, reduce the maximum number to be less than FD_SETSIZE, leaving some room for stdin, stdout and such as they consume some file descriptors. The buildfarm did not complain about that, as it happens to only be an issue on recent versions of OpenBSD and there is no coverage in this area. 51c3e9f fixed a similar set of issues. Bug: #15964 Reported-by: Sean Farrell Discussion: https://postgr.es/m/15964-c1753bdfed722e04@postgresql.org
1 parent 0431a78 commit 56f8f96

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/bin/scripts/reindexdb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ main(int argc, char *argv[])
153153
pg_log_error("number of parallel jobs must be at least 1");
154154
exit(1);
155155
}
156-
if (concurrentCons > FD_SETSIZE - 1)
156+
if (concurrentCons > ParallelSlotsMax())
157157
{
158158
pg_log_error("too many parallel jobs requested (maximum: %d)",
159-
FD_SETSIZE - 1);
159+
ParallelSlotsMax());
160160
exit(1);
161161
}
162162
break;

src/bin/scripts/scripts_parallel.c

+14
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ select_loop(int maxFd, fd_set *workerset, bool *aborting)
9494
return i;
9595
}
9696

97+
/*
98+
* ParallelSlotsMax
99+
* Returns the maximum number of parallel slots supported.
100+
*
101+
* Note that this is included here as FD_SETSIZE is declared in sys/select.h
102+
* per POSIX.
103+
*/
104+
int
105+
ParallelSlotsMax(void)
106+
{
107+
/* leave some room for pre-existing fds */
108+
return FD_SETSIZE - 10;
109+
}
110+
97111
/*
98112
* ParallelSlotsGetIdle
99113
* Return a connection slot that is ready to execute a command.

src/bin/scripts/scripts_parallel.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ typedef struct ParallelSlot
2121
bool isFree; /* Is it known to be idle? */
2222
} ParallelSlot;
2323

24+
extern int ParallelSlotsMax(void);
25+
2426
extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlot *slots, int numslots);
2527

2628
extern ParallelSlot *ParallelSlotsSetup(const char *dbname, const char *host,

src/bin/scripts/vacuumdb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ main(int argc, char *argv[])
181181
pg_log_error("number of parallel jobs must be at least 1");
182182
exit(1);
183183
}
184-
if (concurrentCons > FD_SETSIZE - 1)
184+
if (concurrentCons > ParallelSlotsMax())
185185
{
186186
pg_log_error("too many parallel jobs requested (maximum: %d)",
187-
FD_SETSIZE - 1);
187+
ParallelSlotsMax());
188188
exit(1);
189189
}
190190
break;

0 commit comments

Comments
 (0)