pgsql: Fix option argument lookup in in-tree getopt_long().

From: Nathan Bossart <nathan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix option argument lookup in in-tree getopt_long().
Date: 2026-09-11 20:20:00
Message-ID: E1x57j5-00000004U1u-1Eit@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix option argument lookup in in-tree getopt_long().

The in-tree getopt_long() moves each non-option to the end of argv,
which might put it right where an option's argument lookup expects
to find the argument. For example, "vacuumdb postgres --jobs"
takes "postgres" as the number of jobs instead of complaining that
--jobs is missing its argument. To fix, stop the argument lookups
at the start of the moved non-options, which we already track to
know when to stop scanning.

Oversight in commit 411b720343.

Author: Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
Reviewed-by: solai v <solai(dot)cdac(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAH7T-arxDuVCSkorO%3Dk7%2BM-_JV0JFzMpN_EtKMyD2K0RDqZ2OA%40mail.gmail.com
Backpatch-through: 17

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/237176b7951539fcc54f6a81ce1f29853099c3f7

Modified Files
--------------
src/bin/scripts/t/100_vacuumdb.pl | 4 ++++
src/port/getopt_long.c | 14 +++++++-------
2 files changed, 11 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-09-12 00:04:38 pgsql: doc: Fix output column name for pg_stat_get_backend_subxact()
Previous Message Nathan Bossart 2026-09-11 19:38:29 pgsql: Fix optional-argument handling in in-tree getopt_long().