Bug 269738 - /rescue/pgrep does not work
Summary: /rescue/pgrep does not work
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.1-RELEASE
Hardware: amd64 Any
: --- Affects Some People
Assignee: Zhenlei Huang
URL:
Keywords:
: 269864 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-02-21 15:35 UTC by Stephen Wall
Modified: 2023-03-02 08:59 UTC (History)
4 users (show)

See Also:
zlei: mfc-stable13+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Wall 2023-02-21 15:35:21 UTC
/rescue/pgrep fails to recognize the -q option.  When run without any options, it prints the usage message for pkill.

Debugging with lldb shows that the call to getprogname() is actually calling getexecname() from sys/contrib/openzfs/lib/libspl/os/freebsd/getexecname.c, which does not trim the leading path from the executable name, resulting in "if (strcmp(_getprogname(), "pgrep") == 0) {" not matching, and the executable behaving as pkill instead of pgrep.
Comment 1 Christos Margiolis freebsd_committer freebsd_triage 2023-02-21 23:51:55 UTC
I submitted a patch on Phabricator:
https://reviews.freebsd.org/D38716
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-02-23 18:11:11 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7f0ebf0876c82a098bd5815ea6bf3a8efa6dd6f3

commit 7f0ebf0876c82a098bd5815ea6bf3a8efa6dd6f3
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-02-23 18:00:09 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-02-23 18:00:09 +0000

    Delete obsolete Solaris compat header file stdlib.h

    This drops function `getexecname()` redirection.

    Historically `getexecname()` is a compatibility definition. Since
    openzfs has its own implementation of function `getexecname()` in libspl
    and has been merged into base, the compat header file stdlib.h is
    no longer needed and should not be used.

    Also without this fix libspl will end up an incompatible version of
    `getprogname()` with libc. In particular, if zfs is enabled, programs
    such as pgrep in /rescue can be wrongly statically linked with libspl
    and will not function properly.

    PR:             269738
    Reviewed by:    markj
    Fixes:          9e5787d2284e Merge OpenZFS support in to HEAD
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D38733

 cddl/compat/opensolaris/include/stdlib.h (gone) | 37 -------------------------
 1 file changed, 37 deletions(-)
Comment 3 Stephen Wall 2023-02-23 19:52:06 UTC
I cherry-picked 7f0ebf08 into a 13.1 repo, and got this error:

ld: error: undefined symbol: getexecname
>>> referenced by utils.c:50 (/space/jenkins/customws/13.1_Sandbox/amd64/ports/REDCOM-src/fbsd_base/cddl/contrib/opensolaris/tools/ctf/common/utils.c:50)
>>>               utils.o:(getpname)

Is this change suitable only for head, and not 13?
Comment 4 Yuri 2023-02-23 19:55:00 UTC
(In reply to Stephen Wall from comment #3)
You also want 3dd5524264095ed8612c28908e13f80668eff2f9.
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-03-02 02:57:27 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=95f418fe2a0fb96080afbd2afc160929a32d12fb

commit 95f418fe2a0fb96080afbd2afc160929a32d12fb
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-02-23 18:00:09 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-03-02 02:56:05 +0000

    Delete obsolete Solaris compat header file stdlib.h

    This drops function `getexecname()` redirection.

    Historically `getexecname()` is a compatibility definition. Since
    openzfs has its own implementation of function `getexecname()` in libspl
    and has been merged into base, the compat header file stdlib.h is
    no longer needed and should not be used.

    Also without this fix libspl will end up an incompatible version of
    `getprogname()` with libc. In particular, if zfs is enabled, programs
    such as pgrep in /rescue can be wrongly statically linked with libspl
    and will not function properly.

    PR:             269738
    Reviewed by:    markj
    Fixes:          9e5787d2284e Merge OpenZFS support in to HEAD
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D38733

    (cherry picked from commit 7f0ebf0876c82a098bd5815ea6bf3a8efa6dd6f3)

 cddl/compat/opensolaris/include/stdlib.h (gone) | 37 -------------------------
 1 file changed, 37 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-03-02 08:29:16 UTC
A commit in branch releng/13.2 references this bug:

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

commit b4eb5f81eead115fe49e349a933c72046158b930
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-02-23 18:00:09 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-03-02 08:22:26 +0000

    Delete obsolete Solaris compat header file stdlib.h

    This drops function `getexecname()` redirection.

    Historically `getexecname()` is a compatibility definition. Since
    openzfs has its own implementation of function `getexecname()` in libspl
    and has been merged into base, the compat header file stdlib.h is
    no longer needed and should not be used.

    Also without this fix libspl will end up an incompatible version of
    `getprogname()` with libc. In particular, if zfs is enabled, programs
    such as pgrep in /rescue can be wrongly statically linked with libspl
    and will not function properly.

    PR:             269738
    Reviewed by:    markj
    Approved by:    re (delphij)
    Fixes:          9e5787d2284e Merge OpenZFS support in to HEAD
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D38733

    (cherry picked from commit 7f0ebf0876c82a098bd5815ea6bf3a8efa6dd6f3)
    (cherry picked from commit 95f418fe2a0fb96080afbd2afc160929a32d12fb)

 cddl/compat/opensolaris/include/stdlib.h (gone) | 37 -------------------------
 1 file changed, 37 deletions(-)
Comment 7 Zhenlei Huang freebsd_committer freebsd_triage 2023-03-02 08:51:39 UTC
The fix will be in upcoming release 13.2-RC1.

Thanks for the report!
Comment 8 Zhenlei Huang freebsd_committer freebsd_triage 2023-03-02 08:57:26 UTC
*** Bug 269864 has been marked as a duplicate of this bug. ***