[patch] pg_test_timing does not prompt illegal option

Started by Zhang, Jieover 7 years ago7 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t40459
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 27, 2026 at 07:43 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t40459_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t40459_1 && git checkout t40459_1

Patchset v1 (message #1) is on t40459_1

Jump to latest
#1Zhang, Jie
zhangjie2@cn.fujitsu.com

Hi all,

pg_test_timing accepts the following command-line options:
-d duration
--duration=duration

Specifies the test duration, in seconds. Longer durations give slightly better accuracy, and are more likely to discover problems with the system clock moving backwards. The default test duration is 3 seconds.
-V
--version

Print the pg_test_timing version and exit.
-?
--help

Show help about pg_test_timing command line arguments, and exit.

[https://www.postgresql.org/docs/11/pgtesttiming.html]

However, when I use the following command, no error prompt. the command can run.
pg_test_timing --

I think "--" is a illegal option, errors should be prompted.

Here is a patch for prompt illegal option.

Best Regards!

Attachments:

t40459_1
pg_test_timing.patchapplication/octet-stream; name=pg_test_timing.patchDownload+11-0
#2Fujii Masao
masao.fujii@gmail.com
In reply to: Zhang, Jie (#1)
Re: [patch] pg_test_timing does not prompt illegal option

On Wed, Apr 17, 2019 at 6:21 PM Zhang, Jie <zhangjie2@cn.fujitsu.com> wrote:

Hi all,

pg_test_timing accepts the following command-line options:
-d duration
--duration=duration

Specifies the test duration, in seconds. Longer durations give slightly better accuracy, and are more likely to discover problems with the system clock moving backwards. The default test duration is 3 seconds.
-V
--version

Print the pg_test_timing version and exit.
-?
--help

Show help about pg_test_timing command line arguments, and exit.

[https://www.postgresql.org/docs/11/pgtesttiming.html]

However, when I use the following command, no error prompt. the command can run.
pg_test_timing --

I think "--" is a illegal option, errors should be prompted.

Here is a patch for prompt illegal option.

This is not the problem only for pg_test_timing. If you want to
address this, the patch needs to cover all the client commands
like psql, createuser. I'm not sure if it's worth doing that.

Regards,

--
Fujii Masao

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Fujii Masao (#2)
Re: [patch] pg_test_timing does not prompt illegal option

Fujii Masao <masao.fujii@gmail.com> writes:

On Wed, Apr 17, 2019 at 6:21 PM Zhang, Jie <zhangjie2@cn.fujitsu.com> wrote:

I think "--" is a illegal option, errors should be prompted.

This is not the problem only for pg_test_timing. If you want to
address this, the patch needs to cover all the client commands
like psql, createuser. I'm not sure if it's worth doing that.

I think it might be an actively bad idea. There's a pretty
widespread convention that "--" is a no-op switch indicating
the end of switches. At least some of our tools appear to
honor that behavior (probably because glibc's getopt_long
does; I do not think we are implementing it ourselves).

regards, tom lane

#4Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#3)
Re: [patch] pg_test_timing does not prompt illegal option

On Wed, Apr 17, 2019 at 10:24:17AM -0400, Tom Lane wrote:

Fujii Masao <masao.fujii@gmail.com> writes:

On Wed, Apr 17, 2019 at 6:21 PM Zhang, Jie <zhangjie2@cn.fujitsu.com> wrote:

I think "--" is a illegal option, errors should be prompted.

This is not the problem only for pg_test_timing. If you want to
address this, the patch needs to cover all the client commands
like psql, createuser. I'm not sure if it's worth doing that.

I think it might be an actively bad idea. There's a pretty
widespread convention that "--" is a no-op switch indicating
the end of switches. At least some of our tools appear to
honor that behavior (probably because glibc's getopt_long
does; I do not think we are implementing it ourselves).

Yep, a simple 'ls' on Debian stretch shows it is a common convention:

$ ls --
file1 file2

FYI, 'gcc --' (using Debian 6.3.0-18+deb9u1) does throw an error, so it
is inconsistent.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +
#5Fabien COELHO
coelho@cri.ensmp.fr
In reply to: Tom Lane (#3)
Re: [patch] pg_test_timing does not prompt illegal option

This is not the problem only for pg_test_timing. If you want to
address this, the patch needs to cover all the client commands
like psql, createuser. I'm not sure if it's worth doing that.

I think it might be an actively bad idea. There's a pretty
widespread convention that "--" is a no-op switch indicating
the end of switches. At least some of our tools appear to
honor that behavior (probably because glibc's getopt_long
does; I do not think we are implementing it ourselves).

"src/port/getopt_long.c" checks for "--" as the end of options.

--
Fabien.

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Fabien COELHO (#5)
Re: [patch] pg_test_timing does not prompt illegal option

Fabien COELHO <coelho@cri.ensmp.fr> writes:

I think it might be an actively bad idea. There's a pretty
widespread convention that "--" is a no-op switch indicating
the end of switches. At least some of our tools appear to
honor that behavior (probably because glibc's getopt_long
does; I do not think we are implementing it ourselves).

"src/port/getopt_long.c" checks for "--" as the end of options.

Ah. But I was checking this on a Linux build that's using glibc's
implementation, not our own. It's pretty easy to prove that psql,
for one, acts that way when using the glibc subroutine:

$ psql -- -E
psql: error: could not connect to server: FATAL: database "-E" does not exist

We've generally felt that deferring to the behavior of the platform's
getopt() or getopt_long() is a better idea than trying to enforce some
lowest-common-denominator version of switch parsing, on the theory that
users of a given platform will be used to whatever its getopt does.
This does mean that we have undocumented behaviors on particular
platforms. I'd say that accepting "--" is one of them. Another example
is that glibc's getopt is willing to reorder the arguments, so that
for example this works for me:

$ psql template1 -E
psql (12devel)
Type "help" for help.

template1=# \set
...
ECHO_HIDDEN = 'on'
...

On other platforms that would not work, so we don't document it.

regards, tom lane

#7Fabien COELHO
coelho@cri.ensmp.fr
In reply to: Tom Lane (#6)
Re: [patch] pg_test_timing does not prompt illegal option

Hello Tom,

We've generally felt that deferring to the behavior of the platform's
getopt() or getopt_long() is a better idea than trying to enforce some
lowest-common-denominator version of switch parsing, on the theory that
users of a given platform will be used to whatever its getopt does.
This does mean that we have undocumented behaviors on particular
platforms.

Interesting.

I'd say that accepting "--" is one of them. Another example is that
glibc's getopt is willing to reorder the arguments, so that for example
this works for me:

$ psql template1 -E
psql (12devel)

Yep, I noticed that one by accident once.

On other platforms that would not work, so we don't document it.

People might get surprised anyway, because the very same command may or
may not work depending on the platform. Does not matter much, though.

--
Fabien.