GNU bug report logs - #14462
useless calls of setpwent()/setgrent() in stat

Previous Next

Package: coreutils;

Reported by: Fridolín Pokorný <fpokorny <at> redhat.com>

Date: Fri, 24 May 2013 15:48:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14462 in the body.
You can then email your comments to 14462 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#14462; Package coreutils. (Fri, 24 May 2013 15:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Fridolín Pokorný <fpokorny <at> redhat.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 24 May 2013 15:48:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Fridolín Pokorný <fpokorny <at> redhat.com>
To: bug-coreutils <at> gnu.org
Subject: useless calls of setpwent()/setgrent() in stat
Date: Fri, 24 May 2013 15:32:56 +0200
Hi,

I am investigating an issue with stat. stat calls setpwent() (when
resolving a username) and setgrent() (when resolving a group name). This
has a bad impact when a LDAP is used and a database is quite large. It
forces to download the whole database. According to RFC 2307,
getpwuid()/getgrgid() are handled correctly with a search pattern to get
an username/group name and there is no need to call
setpwent()/setgrent(). My tests have approved this.

Even when the LDAP is not used, I don't see the point of using
setpwent() and setgrent() calls. On local system with /etc/passwd in
use, these calls does nothing in fact. For example setpwent() should be
used with functions getpwent()/endpwent(), on the other hand, setgrent()
is designed to be used with getgrent()/endgrent() functions. I cannot
find anything why are these functions used with getpwuid()/getgrgid().
Is there any non-documented behavior? For example nscd is using its own
cache and these calls are, again, useless.

I cannot determinate why these functions are called. They request
additional computation which is not used. In my opinion, these spare
calls should be removed.

If these calls are useful, why there are no endpwent()/endgrent() calls?

Thanks for your response!

Best regards,
Fridolin Pokorny.

---coreutils_old/src/stat.c	2013-05-24 08:14:35.922027283 +0200
+++ coreutils/src/stat.c	2013-05-24 08:14:56.076101484 +0200
@@ -965,7 +965,6 @@ print_stat (char *pformat, size_t prefix
       out_uint (pformat, prefix_len, statbuf->st_uid);
       break;
     case 'U':
-      setpwent ();
       pw_ent = getpwuid (statbuf->st_uid);
       out_string (pformat, prefix_len,
                   pw_ent ? pw_ent->pw_name : "UNKNOWN");
@@ -974,7 +973,6 @@ print_stat (char *pformat, size_t prefix
       out_uint (pformat, prefix_len, statbuf->st_gid);
       break;
     case 'G':
-      setgrent ();
       gw_ent = getgrgid (statbuf->st_gid);
       out_string (pformat, prefix_len,
                   gw_ent ? gw_ent->gr_name : "UNKNOWN");








Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Fri, 24 May 2013 17:24:02 GMT) Full text and rfc822 format available.

Notification sent to Fridolín Pokorný <fpokorny <at> redhat.com>:
bug acknowledged by developer. (Fri, 24 May 2013 17:24:02 GMT) Full text and rfc822 format available.

Message #10 received at 14462-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Fridolín Pokorný <fpokorny <at> redhat.com>
Cc: 14462-done <at> debbugs.gnu.org
Subject: Re: bug#14462: useless calls of setpwent()/setgrent() in stat
Date: Fri, 24 May 2013 10:22:40 -0700
On 05/24/2013 06:32 AM, Fridolín Pokorný wrote:
> I cannot determinate why these functions are called.

Nor I.  Thanks, I installed that patch and am marking this as done.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 22 Jun 2013 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 327 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.