Bug 275370 - Add execvpe()
Summary: Add execvpe()
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 14.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Brooks Davis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-27 10:23 UTC by vini.ipsmaker
Modified: 2024-02-18 17:51 UTC (History)
2 users (show)

See Also:
antoine: exp-run+


Attachments
patch (7.77 KB, text/plain)
2023-11-30 00:35 UTC, Brooks Davis
no flags Details
second attempt to add patch (8.08 KB, patch)
2023-12-05 20:34 UTC, Brooks Davis
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description vini.ipsmaker 2023-11-27 10:23:51 UTC
Would it be possible to add execvpe() that is found on Linux/glibc systems? Currently I have to do the following:

environ = args->envp;
execvp(args->program, args->argv);

However this workaround will not even compile for shared libraries (one of my scenarios) because of another FreeBSD bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263265

execvpe() would solve my problem.
Comment 1 firk 2023-11-27 22:47:26 UTC
execvpe() is not a kernel syscall, it is libc wrapper for execve() syscall.
Comment 2 vini.ipsmaker 2023-11-29 18:58:36 UTC
> execvpe() is not a kernel syscall, it is libc wrapper for execve() syscall.

That sounds about right. libc performs PATH-resolution and then calls execve(). Still, would it be possible to add execvpe()? The problem I face still stands.
Comment 3 Brooks Davis freebsd_committer freebsd_triage 2023-11-29 19:30:14 UTC
It appears to already be implemented at _execvpe() and not made public. It looks trivial enough I'll take a shot at exposing it.
Comment 4 Brooks Davis freebsd_committer freebsd_triage 2023-11-29 23:41:54 UTC
As always it's more complicated than expected. Some software (e.g., openzfs) blindly added execvpe shims so an exp-run will be required.

https://reviews.freebsd.org/D42846
Comment 5 Brooks Davis freebsd_committer freebsd_triage 2023-11-30 00:35:02 UTC
Created attachment 246678 [details]
patch

see also https://github.com/brooksdavis/freebsd/tree/execvpe
Comment 7 vini.ipsmaker 2023-12-05 16:54:03 UTC
> New failure logs

> checking for execvpe... no

These projects use autotools to check for execvpe(), but for some reason they're failing to detect FreeBSD's execvpe(). That's how they use autotools:

> AC_CHECK_FUNCS(execvpe)

If execvpe() is found, then HAVE_EXECVPE is defined. One workaround should be to explicitly define HAVE_EXECVPE and bypass the internal definition. However I think it's better to understand why autotools didn't find FreeBSD's execvpe().
Comment 8 Brooks Davis freebsd_committer freebsd_triage 2023-12-05 20:34:06 UTC
Created attachment 246807 [details]
second attempt to add patch

Sigh, some how exposing the symbol didn't make it into the initial patch.  I've fixed that and now scheme48 builds fine. I didn't test the others because I expect different failure modes across the ports tree. :(
Comment 9 Antoine Brodin freebsd_committer freebsd_triage 2023-12-08 21:47:18 UTC
Exp-run looks fine.
Comment 10 commit-hook freebsd_committer freebsd_triage 2023-12-11 19:28:35 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8ccd0b876e67fda6249f294ff484798cc1e1569f

commit 8ccd0b876e67fda6249f294ff484798cc1e1569f
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2023-12-11 19:24:53 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2023-12-11 19:24:53 +0000

    libc: expose execvpe for Linux compat

    We already implemented execvpe internally with an _ prefix in libc so
    go ahead and expose it for compatibility with Linux.

    This reverts c605eea952146348e5e1ad5cab6c127d7a1bd164.

    Bump __FreeBSD_version for the addition and add definitions to supress
    compat shims in libzfs (zfs changes were merged from upstream).

    PR:             275370 (request and exp-run (thanks antoine!))
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D42846

 cddl/lib/libzfs/Makefile           |  1 +
 cddl/usr.sbin/zfsd/Makefile.common |  2 +-
 include/unistd.h                   |  1 +
 lib/libc/gen/Symbol.map            |  4 ++++
 lib/libc/gen/exec.3                | 24 ++++++++++++++++++++----
 lib/libc/gen/exec.c                |  4 ++--
 lib/libc/gen/posix_spawn.c         |  4 ++--
 lib/libc/include/libc_private.h    |  3 ---
 sys/sys/param.h                    |  2 +-
 9 files changed, 32 insertions(+), 13 deletions(-)
Comment 11 Brooks Davis freebsd_committer freebsd_triage 2024-01-24 22:16:26 UTC
I might yet MFC this, but don't need a PR to track that.
Comment 12 commit-hook freebsd_committer freebsd_triage 2024-02-18 10:03:11 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0667d0e0e3658128098ff4d672f5c2ce8aa9068e

commit 0667d0e0e3658128098ff4d672f5c2ce8aa9068e
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2023-12-11 19:24:53 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-02-18 10:01:46 +0000

    libc: expose execvpe for Linux compat

    PR:             275370

    (cherry picked from commit 8ccd0b876e67fda6249f294ff484798cc1e1569f)

 cddl/lib/libzfs/Makefile           |  1 +
 cddl/usr.sbin/zfsd/Makefile.common |  2 +-
 include/unistd.h                   |  1 +
 lib/libc/gen/Symbol.map            |  4 ++++
 lib/libc/gen/exec.3                | 26 ++++++++++++++++++++------
 lib/libc/gen/exec.c                |  4 ++--
 lib/libc/gen/posix_spawn.c         |  4 ++--
 lib/libc/include/libc_private.h    |  3 ---
 8 files changed, 31 insertions(+), 14 deletions(-)
Comment 13 Dmitry Wagin 2024-02-18 14:00:32 UTC
(In reply to commit-hook from comment #12)

FreeBSD-14/STABLE build is broken.


In file included from /usr/src/cddl/usr.sbin/zfsd/zfsd_main.cc:44:
In file included from /usr/src/sys/contrib/openzfs/lib/libspl/include/unistd.h:27:
/tmp/make_world.IDxEs5PH5i/obj.oXuTuncfnb/usr/src/amd64.amd64/tmp/usr/include/unistd.h:507:6: error: declaration of 'execvpe' has a different language linkage
  507 | int      execvpe(const char *, char * const *, char * const *);
      |          ^
/usr/src/sys/contrib/openzfs/lib/libspl/include/os/freebsd/sys/param.h:60:12: note: previous declaration is here
   60 | extern int execvpe(const char *name, char * const argv[], char * const envp[]);
      |            ^
1 error generated.
Comment 14 Dmitry Wagin 2024-02-18 17:51:24 UTC
(In reply to Dmitry Wagin from comment #13)

Fixed in https://cgit.freebsd.org/src/commit/?h=stable/14&id=bda0c0dc87c54b611d96b6d0dc1947819ffec083

Thanx @kib