🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.netbsd.tech.userlevel
Article #35

Re: Proposal: getexecpath(3)

#35
From: Brad Smith
Date: Sun, 25 Oct 2026 08:20
70 lines
4973 bytes
On Mon, Dec 16, 2024, Taylor R Campbell wrote:
 > PROPOSAL: New libc function
 >
 >     const char *getexecpath(void);
 >
 > returns the pathname that was passed to execve(2), unmodified.

I know this is not quite what you are looking for, but FYI, OpenBSD
has since added a getexecpath(3) to libc, first appearing in
OpenBSD 8.0:

   https://man.openbsd.org/getexecpath.3

Unlike NetBSD, OpenBSD did not even have a sysctl like
KERN_PROC_PATHNAME to fall back on, so software was left guessing
from argv[0]. That said, after looking through many open source
projects, I see a lot of them have not been updated to use NetBSD's
sysctl either.

   #include <unistd.h>

   int
   getexecpath(char *buf, size_t bufsize);

It copies the absolute pathname of the executable into buf,
canonicalized the same way as realpath(3), and returns 0 on success
or -1 with errno set on failure (e.g. the executable was started in
a directory no longer linked into the filesystem, or the buffer is
too small; PATH_MAX is the recommended size).

The path is computed by the kernel in execve(2) and placed on the
new process's stack as an ELF auxiliary vector entry, which libc
picks up at startup. The relevant commits:

https://github.com/openbsd/src/commit/4dde6567f895c6faa36acbacd4cdf62954a70399
     In execve(2), attempt to create a realpath buffer for the
     executable and pass it to userland as an auxval

https://github.com/openbsd/src/commit/026846f111232f45cd1f4883414c190c8ff722a7
     Add getexecpath(3) to libc

https://github.com/openbsd/src/commit/1d46e5b94d0221c062218de40c6d15f9f5cacb31
     Make getexecpath() return the ELF executable that is running
     (for a script run via a shebang line, the canonicalized path of
     the interpreter actually executed)

So the name is the same, but both the signature and the semantics
differ from what is proposed here: a canonical absolute path rather
than the verbatim execve(2) argument. If NetBSD goes ahead with
this, it would be good to either match OpenBSD's interface or pick a
different name. Portable software is already starting to probe for
getexecpath() (HAVE_GETEXECPATH checks in configure/meson/CMake), and
two incompatible functions under the same name would be an
unpleasant trap.

On the consumer side, I have been adding getexecpath() support for
OpenBSD to quite a few common open source packages, Racket among
them, which uses the same kind of self-path logic that tripped up
lang/racket in your postscript. A compatible interface on NetBSD
would let the same code paths be reused.


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <210e9bde-0c69-4db4-9b68-6a78bf3ad615@comstyle.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: Brad Smith <brad@comstyle.com>
Newsgroups: muc.lists.netbsd.tech.userlevel
Subject: Re: Proposal: getexecpath(3)
Date: Sun, 25 Oct 2026 04:20:57 -0400
Organization: Newsgate at muc.de e.V.
Sender: tech-userlevel-owner@NetBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <210e9bde-0c69-4db4-9b68-6a78bf3ad615@comstyle.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="19989"; mail-complaints-to="news-admin@muc.de"
User-Agent: Mozilla Thunderbird
Authentication-Results: mail.netbsd.org (amavisd-new);
	dkim=pass (1024-bit key) header.d=comstyle.com;
	domainkeys=pass (1024-bit key) header.from=brad@comstyle.com
	header.d=comstyle.com
X-Greylist: delayed 589 seconds by postgrey-1.37 at homeworld.NetBSD.org; Sun, 25 Oct 2026 08:30:47 UTC
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=comstyle.com; h=
	message-id:date:mime-version:from:to:subject:content-type
	:content-transfer-encoding; s=default; bh=VY79pW7gZQ7WmMV3VAU5KO
	sSSYHwb6wN13fxGfKumlM=; b=eFKJtNk4r9pzGavIIQ2hz6oEl0wFSSnJ2tKdgc
	RNzeb0Wg+GSwkH28wgqV/Ey/ZZHQxzDluFTFUM+W2CcSB1myFJc1nFqmiglnPOXn
	PqzTl6CdShDkdtoyng0sLcfzeFVU3Uw4qEireoUY7P+5WbavYKKsyFAPDuDdPXRu
	HofSo=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=comstyle.com; h=message-id
	:date:mime-version:from:to:subject:content-type
	:content-transfer-encoding; q=dns; s=default; b=nHKbDXyNuJZSg1m+
	Q8TAhiBe1bosqKlsOqjrVklQU2EmrN4p3F9b0si1YDE/20MpeEsNdisVtzSaaACJ
	iHY40d2J+1g1NyBmdeHdfsL/GKc6MZNmxW1RvWP7O81O/iiOX6peMJPssAHI0yak
	Pd/oKc1Pn+I+OaQBCjUSRoVIJhw=
Content-Language: en-US
Precedence: bulk
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes