From: | Anders Kaseorg <andersk(at)mit(dot)edu> |
---|---|
To: | Daniel Gustafsson <daniel(at)yesql(dot)se>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> |
Cc: | alvherre(at)alvh(dot)no-ip(dot)org, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: [PATCH] Prefer getenv("HOME") to find the UNIX home directory |
Date: | 2021-10-20 17:09:51 |
Message-ID: | d452fd57-8c34-0a94-79c1-4498eb4ffbdc@mit.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 10/20/21 04:55, Daniel Gustafsson wrote:
> Is the proposed change portable across all linux/unix systems we support?
> Reading aobut indicates that it's likely to be, but neither NetBSD nor FreeBSD
> have the upthread referenced wording in their manpages.
Since the proposed change falls back to the old behavior if HOME is
unset or empty, I assume this is a question about convention and not
literally about whether it will work on these systems. I don’t find it
surprising that this convention isn’t explicitly called out in every
system’s manpage for the wrong function, but it still applies to these
systems.
POSIX specifies that the shell uses the HOME environment variable for
‘cd’ with no arguments and for the expansion of ~. This implies by
reference that this behavior is required of wordexp() as well.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01
https://pubs.opengroup.org/onlinepubs/9699919799/functions/wordexp.html
libc’s glob() and wordexp() respect HOME in glibc, musl, NetBSD, and
FreeBSD.
https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/glob.c;hb=glibc-2.34#l622
https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/wordexp.c;hb=glibc-2.34#l293
https://git.musl-libc.org/cgit/musl/tree/src/regex/glob.c?h=v1.2.2#n203
https://git.musl-libc.org/cgit/musl/tree/src/misc/wordexp.c?h=v1.2.2#n111
https://github.com/NetBSD/src/blob/netbsd-9/lib/libc/gen/glob.c#L424
https://github.com/NetBSD/src/blob/netbsd-9/lib/libc/gen/wordexp.c#L129-L150
https://github.com/NetBSD/src/blob/netbsd-9/bin/sh/expand.c#L434-L441
https://github.com/freebsd/freebsd-src/blob/release/13.0.0/lib/libc/gen/glob.c#L457
https://github.com/freebsd/freebsd-src/blob/release/13.0.0/lib/libc/gen/wordexp.c#L171-L190
https://github.com/freebsd/freebsd-src/blob/release/13.0.0/bin/sh/expand.c#L396
(Today I learned that musl and BSD libc literally spawn a shell process
to handle wordexp(). Wow.)
Anders
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2021-10-20 17:20:28 | Re: Delegating superuser tasks to new security roles (Was: Granting control of SUSET gucs to non-superusers) |
Previous Message | Mark Dilger | 2021-10-20 16:41:10 | Re: Extending amcheck to check toast size and compression |