Bug 267384 - Make Mk/Scripts/do-users-groups.sh fail-fast instead of silently succeeding
Summary: Make Mk/Scripts/do-users-groups.sh fail-fast instead of silently succeeding
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Ports Framework (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Michael Osipov
URL:
Keywords:
Depends on:
Blocks: 267364
  Show dependency treegraph
 
Reported: 2022-10-27 08:21 UTC by Michael Osipov
Modified: 2024-05-03 07:48 UTC (History)
7 users (show)

See Also:


Attachments
Git-formatted patch (2.81 KB, text/plain)
2022-10-27 08:21 UTC, Michael Osipov
no flags Details
Git-formatted patch (2.09 KB, patch)
2023-03-01 10:40 UTC, Michael Osipov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Osipov 2022-10-27 08:21:12 UTC
Created attachment 237674 [details]
Git-formatted patch

This has been found during Bug 267364.

If user or group creation fails before the last element this goes unnoticed since the exit code isn't examined. Only the last exit code is taken into account. There is no point in creating a user when the group creation has failed.

A Git-formatted patch has been attached.

The patch also cleans up a few inconsistencies in the messages.
Comment 1 Li-Wen Hsu freebsd_committer freebsd_triage 2022-10-27 09:42:58 UTC
Over to maintainer
Comment 2 Michael Osipov 2023-02-16 22:03:31 UTC
Port manager, can you have a look?
Comment 3 Mathieu Arnold freebsd_committer freebsd_triage 2023-02-17 07:54:09 UTC
using `|| exit` is probably a bad idea, the script should probably use `set -e` instead.
Comment 4 Michael Osipov 2023-02-17 07:55:29 UTC
(In reply to Mathieu Arnold from comment #3)

This might be, but the behavior would then be consistent at least and fail fast.
Comment 5 Michael Osipov 2023-02-17 18:00:28 UTC
(In reply to Mathieu Arnold from comment #3)

The script uses already "set -e", but it does not work:
https://github.com/freebsd/freebsd-ports/blob/a535111bd3362c3463253683afbf485ffd8762cc/Mk/Scripts/do-users-groups.sh#L5
Comment 6 Mathieu Arnold freebsd_committer freebsd_triage 2023-02-24 11:04:00 UTC
Well, it works for the script, but not the generated script, the do-users-groups.sh script generates a script that is run by pkg when the package is installed. `set -e` needs to be added to the generated script.
Comment 7 Michael Osipov 2023-03-01 10:40:49 UTC
Created attachment 240499 [details]
Git-formatted patch

Matthieu, agree with you. Here is an updated patch. Works in a test jail.
Comment 8 Michael Osipov 2023-03-01 10:46:02 UTC
Well, as it turned out, the issue has been reported already seven years ago (!): https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=206951
Comment 9 Michael Osipov 2023-03-28 13:30:55 UTC
Mathieu Arnold,

the patch is, I hope, as you expect. Can you review?
Comment 10 commit-hook freebsd_committer freebsd_triage 2024-05-03 07:47:40 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=4280a82efe69f5dc77a67394f7bd36095c74cd6c

commit 4280a82efe69f5dc77a67394f7bd36095c74cd6c
Author:     Michael Osipov <michaelo@FreeBSD.org>
AuthorDate: 2023-11-22 11:30:32 +0000
Commit:     Michael Osipov <michaelo@FreeBSD.org>
CommitDate: 2024-05-03 07:44:53 +0000

    Mk/Scripts/do-users-groups.sh: Make users and groups creation fail-fast

    Fail fast when pw(8) fails to create a user or a group. Especially when it is
    not the last command in the pre-install script then the exit code will be 0 and
    the failure will go unnoticed.

    PR:             267384
    Approved by:    jrm (mentor)
    Differential Revision:  https://reviews.freebsd.org/D42719

 Mk/Scripts/do-users-groups.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)