Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Nov 2025 20:31:40 +0000
From:      Olivier Certner <olce@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b92b1b475830 - main - mdo(1): Avoid calling getgroups() in some unnecessary cases
Message-ID:  <6924c0ac.28e66.58c10bc5@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by olce:

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

commit b92b1b47583036bd02e656564ff22c92b8949077
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-11-14 11:59:09 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-11-24 20:31:00 +0000

    mdo(1): Avoid calling getgroups() in some unnecessary cases
    
    If the basis for supplementary groups are the current ones, we do not
    need to fetch them when they are to be replaced entirely (which we
    already have been doing), as in the '!start_from_current_groups' case,
    but specifically also when they are not going to be touched at all.
    
    This change in passing makes the modified code block's comment saying
    that SETCREDF_SUPP_GROUPS need not be set here correct.
    
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D53771
---
 usr.bin/mdo/mdo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/usr.bin/mdo/mdo.c b/usr.bin/mdo/mdo.c
index 3eb5d4e5c23f..879423bc0128 100644
--- a/usr.bin/mdo/mdo.c
+++ b/usr.bin/mdo/mdo.c
@@ -753,8 +753,14 @@ main(int argc, char **argv)
 			 */
 			setcred_flags |= SETCREDF_SUPP_GROUPS;
 		}
-	} else if (supp_groups_str == NULL && (supp_mod_str == NULL ||
-	    supp_mod_str[0] != '@')) {
+	} else if (supp_groups_str == NULL && supp_mod_str != NULL &&
+	    supp_mod_str[0] != '@') {
+		/*
+		 * We do not need to determine the current groups if, as for the
+		 * '!start_from_current_groups' case, we are going to replace
+		 * them entirely, but here also if we do not amend them at all
+		 * (because they are by definition already in place).
+		 */
 		const int ngroups = getgroups(0, NULL);
 
 		if (ngroups > 0) {


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6924c0ac.28e66.58c10bc5>