Fix compilation failure of vacuumdb and reindexdb with OpenBSD
authorMichael Paquier <michael@paquier.xyz>
Tue, 20 Aug 2019 07:10:20 +0000 (16:10 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 20 Aug 2019 07:10:20 +0000 (16:10 +0900)
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

src/bin/scripts/reindexdb.c
src/bin/scripts/scripts_parallel.c
src/bin/scripts/scripts_parallel.h
src/bin/scripts/vacuumdb.c

index 14a4f4a91c708dd1e7112ebff982155760ca198d..f93f7dd5fec76b80c131a2021b0cfff49d9a42d8 100644 (file)
@@ -153,10 +153,10 @@ main(int argc, char *argv[])
                                        pg_log_error("number of parallel jobs must be at least 1");
                                        exit(1);
                                }
-                               if (concurrentCons > FD_SETSIZE - 1)
+                               if (concurrentCons > ParallelSlotsMax())
                                {
                                        pg_log_error("too many parallel jobs requested (maximum: %d)",
-                                                                FD_SETSIZE - 1);
+                                                                ParallelSlotsMax());
                                        exit(1);
                                }
                                break;
index ffdc4e49ef81bda32ceab385b0f8a5837d19a472..10379a1f99bd279959ff90c5dcadb7ca7c3df0d0 100644 (file)
@@ -94,6 +94,20 @@ select_loop(int maxFd, fd_set *workerset, bool *aborting)
        return i;
 }
 
+/*
+ * ParallelSlotsMax
+ *             Returns the maximum number of parallel slots supported.
+ *
+ * Note that this is included here as FD_SETSIZE is declared in sys/select.h
+ * per POSIX.
+ */
+int
+ParallelSlotsMax(void)
+{
+       /* leave some room for pre-existing fds */
+       return FD_SETSIZE - 10;
+}
+
 /*
  * ParallelSlotsGetIdle
  *             Return a connection slot that is ready to execute a command.
index ab82c5e6a962fb8e0521035abeb0a968fc3748c9..8042345072a5e3760c68956fedc13ba17a929fe1 100644 (file)
@@ -21,6 +21,8 @@ typedef struct ParallelSlot
        bool            isFree;                 /* Is it known to be idle? */
 } ParallelSlot;
 
+extern int     ParallelSlotsMax(void);
+
 extern ParallelSlot *ParallelSlotsGetIdle(ParallelSlot *slots, int numslots);
 
 extern ParallelSlot *ParallelSlotsSetup(const char *dbname, const char *host,
index d81bfa3a6b4688e01a2aa374cfce34e8f138b6ec..c5c38692edeaa1f40885b10ab571564155003d40 100644 (file)
@@ -181,10 +181,10 @@ main(int argc, char *argv[])
                                        pg_log_error("number of parallel jobs must be at least 1");
                                        exit(1);
                                }
-                               if (concurrentCons > FD_SETSIZE - 1)
+                               if (concurrentCons > ParallelSlotsMax())
                                {
                                        pg_log_error("too many parallel jobs requested (maximum: %d)",
-                                                                FD_SETSIZE - 1);
+                                                                ParallelSlotsMax());
                                        exit(1);
                                }
                                break;