From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jules Tamagnan Newsgroups: gmane.emacs.bugs Subject: bug#33195: 27.0.50; user-login-name has no group-login-name Date: Tue, 30 Oct 2018 11:25:33 -0700 Message-ID: <871s87e1gi.fsf@gmail.com> References: <87d0rsegbi.fsf@gmail.com> <837ehzlo3a.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1540923850 26355 195.159.176.226 (30 Oct 2018 18:24:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 30 Oct 2018 18:24:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 33195@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 30 19:24:06 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gHYgO-0006jC-VG for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Oct 2018 19:24:05 +0100 Original-Received: from localhost ([::1]:54923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHYiV-0003B1-AE for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Oct 2018 14:26:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHYiN-0003At-ML for bug-gnu-emacs@gnu.org; Tue, 30 Oct 2018 14:26:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHYiJ-0004lk-Jv for bug-gnu-emacs@gnu.org; Tue, 30 Oct 2018 14:26:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51652) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHYiJ-0004lN-Eg for bug-gnu-emacs@gnu.org; Tue, 30 Oct 2018 14:26:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gHYiH-0004Pm-Ja for bug-gnu-emacs@gnu.org; Tue, 30 Oct 2018 14:26:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jules Tamagnan Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 30 Oct 2018 18:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33195 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 33195-submit@debbugs.gnu.org id=B33195.154092394416946 (code B ref 33195); Tue, 30 Oct 2018 18:26:01 +0000 Original-Received: (at 33195) by debbugs.gnu.org; 30 Oct 2018 18:25:44 +0000 Original-Received: from localhost ([127.0.0.1]:55910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gHYi0-0004PE-DP for submit@debbugs.gnu.org; Tue, 30 Oct 2018 14:25:44 -0400 Original-Received: from mail-pg1-f178.google.com ([209.85.215.178]:44228) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gHYhy-0004P0-Dh for 33195@debbugs.gnu.org; Tue, 30 Oct 2018 14:25:42 -0400 Original-Received: by mail-pg1-f178.google.com with SMTP id w3-v6so6054081pgs.11 for <33195@debbugs.gnu.org>; Tue, 30 Oct 2018 11:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=+l+oVWrJe1PmfaL532s/mNI1u0IFWPg0nvQnWJ+SpZo=; b=CTlMPuyvE4uh+T7ynFK82A6iJvKxtoCsJ6KYtYFNHzlsKn7Ch+gMpxaCm6+QoKaQG4 HP2+o5qQTS+mpD/gz/5eZowowvUJ+ehsbYtj1Df3iNv/52WViKrrLUImdi38UXSbWBmC JtcCqwv4uGRTaRO25fDpaVMADD0oMKwXhqcO7pggsHIXJFemMR7ah/TbYKVpS1gKawlD WWgj7etsGnKNXGawVn7xmuva+qkFMOY738QKmvbn/o40ty9gxgkWnTm76Oz0NSGKvNXv 4BVZYhOFIxaMFDjIsqBLRzGKsZGd56ozfsYeC82nPtLS+kN5B3Nhrj3B06qUvpjbqoKf bLNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=+l+oVWrJe1PmfaL532s/mNI1u0IFWPg0nvQnWJ+SpZo=; b=RHHYkQf0k4OMoqfjMwL8uktszamEgPLWi7p5Xdrh0tzfAcdX81UeFOMnWFRCkLupQe 1DnG3AazcHpL7nF43Gxe2w3sGPca+FaLEZ5vt3aAKbCwfVlD4iIfQW/cBpUzGEifc8a9 /SX2pqM8UBpc+abHfp6CuF3XpChyHNuJZYBnjhXrlxuTOCZ28lip1jWrjrzm6NlBZ+hV 323p+Y9zSAQgK8dUHOOLr6NedfSV0O/+8fJjkp2W8pAcXk9HtKApMjijt7zPk7HKJHZU 71oG8XSiOvV1tJRVjxsWtVzkh9qosASSYKFh2sHnFWz4H7erbQWIknelUcs9w4ZFxe6D APZQ== X-Gm-Message-State: AGRZ1gJO6FoMx1Fo8wlS5alCG7sMX6Su+s/EuX1mQwmw0xzyVCoI8+UG pkJV6W2K5JknOxTnuYMtBz4g7gid X-Google-Smtp-Source: AJdET5eeHbbSSZKspTr8tlc+Vn8mdKf2KAm5QjsSwt7DLjqhyoL+3aYo9ySw78HefMF7rXy0jJy5Iw== X-Received: by 2002:a63:6984:: with SMTP id e126mr3541870pgc.143.1540923935866; Tue, 30 Oct 2018 11:25:35 -0700 (PDT) Original-Received: from jat-delphix-lap (DELPHIX-COR.ear2.SanJose1.Level3.net. [4.16.207.62]) by smtp.gmail.com with ESMTPSA id s4-v6sm7370244pfh.168.2018.10.30.11.25.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 11:25:34 -0700 (PDT) In-Reply-To: <837ehzlo3a.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 30 Oct 2018 12:34:49 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:151841 Archived-At: --=-=-= Content-Type: text/plain First off I want to say thank you for your review and your time Eli Zaretskii writes: >> From: Jules Tamagnan >> Date: Mon, 29 Oct 2018 11:52:17 -0700 >> >> I've found it difficult to go from an integer group id to the name of >> that group. I've looked at the source for `user-login-name` and >> `system-groups` and could not find a way to do what I needed. >> >> As such I think it would be great to add a function to do that. > > Thanks. Please allow me a few comments: > > Please always provide a ChangeLog-style commit log message describing > your changes. The file CONTRIBUTE has more about that. > >> I'm unsure how to make an argument not be optional. > > You want the argument NOT to be optional? If so, make this: > >> +DEFUN ("group-name", Fgroup_name, Sgroup_name, 0, 1, 0, > > say this instead: > >> +DEFUN ("group-name", Fgroup_name, Sgroup_name, 1, 1, 0, > > See the node "Writing Emacs Primitives" in the ELisp manual, which > describes how to use the DEFUN macro. Turns out there is a word for not optional... required :) >> +DEFUN ("group-name", Fgroup_name, Sgroup_name, 0, 1, 0, >> + doc: /* If argument GID is an integer or a float, return the login name >> +of the group with that GID, or nil if there is no such GID. */) >> + (Lisp_Object gid) >> +{ >> + struct group *gr; >> + gid_t id; >> + >> + if (NILP (gid)) >> + return Qnil; > > Wouldn't it be more useful to return user's group name when the > argument is nil or omitted? I always thought that user could have many groups, for example if I run $ groups $(id -un) I get a long list of groups. I'm not sure if I misunderstood your statement or the desired behavior but for the moment I think a separate function would be best for this. Or maybe the `system-groups` function could be modified to take in a UID and then list groups for that UID, then if no argument is passed in, it would return the full list of system-groups as it does now. > Also, would you please write a couple of simple tests for this new > function? I've tried my hand at writing a test for this but am dubious it will pass on all machines, I believe it should work on gnu/linux > Finally, this function should be announced in NEWS and documented in > the ELisp manual. I've added a short entry in NEWS under "Lisp Changes in Emacs 27.1" and in os.texi --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-src-editfns.c-group-name-New-function.patch Content-Description: Patch >From 671c8b55d80743a13d6fda99f5181558cd56eea6 Mon Sep 17 00:00:00 2001 From: Jules Tamagnan Date: Tue, 30 Oct 2018 10:22:03 -0700 Subject: [PATCH] src/editfns.c (group-name): New function. --- doc/lispref/os.texi | 5 +++++ etc/NEWS | 3 +++ src/editfns.c | 16 ++++++++++++++++ test/src/editfns-tests.el | 7 +++++++ 4 files changed, 31 insertions(+) diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index cb33757..dc32958 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi @@ -1230,6 +1230,11 @@ User Identification return value is @code{nil}. @end defun +@defun user-login-name &optional gid +This runction returns the group name that corresponds to @var{gid}, +or @code{nil} if there is no such group. +@end defun + @node Time of Day @section Time of Day diff --git a/etc/NEWS b/etc/NEWS index 226ae1e..a0bcbb5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1228,6 +1228,9 @@ where there's no better alternative. We believe that the incorrect uses of this function all but disappeared by now, so we are un-obsoleting it. ++++ +** New function 'group-name' returns a group name based on a group-GID + * Changes in Emacs 27.1 on Non-Free Operating Systems diff --git a/src/editfns.c b/src/editfns.c index e995b38..15a0fa7 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -1143,6 +1143,21 @@ of the user with that uid, or nil if there is no such user. */) return (pw ? build_string (pw->pw_name) : Qnil); } +DEFUN ("group-name", Fgroup_name, Sgroup_name, 1, 1, 0, + doc: /* If argument GID is an integer or a float, return the login name +of the group with that gid, or nil if there is no such GID. */) + (Lisp_Object gid) +{ + struct group *gr; + gid_t id; + + CONS_TO_INTEGER (gid, gid_t, id); + block_input (); + gr = getgrgid (id); + unblock_input (); + return (gr ? build_string (gr->gr_name) : Qnil); +} + DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name, 0, 0, 0, doc: /* Return the name of the user's real uid, as a string. @@ -4487,6 +4502,7 @@ it to be non-nil. */); defsubr (&Sinsert_byte); defsubr (&Suser_login_name); + defsubr (&Sgroup_name); defsubr (&Suser_real_login_name); defsubr (&Suser_uid); defsubr (&Suser_real_uid); diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 17b2c51..6ee0ab0 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el @@ -351,4 +351,11 @@ transpose-test-get-byte-positions (should (equal (format "%-#50.40x" v3) "-0x000000003ffffffffffffffe000000000000000 ")))) +(ert-deftest group-name () + (let ((list `((0 . "root") + (1000 . ,(user-login-name 1000)) + (1212345 . nil)))) + (dolist (test list) + (should (equal (group-name (car test)) (cdr test)))))) + ;;; editfns-tests.el ends here -- 2.7.4 --=-=-=--