Bug 106240 - wtmp-helper: don't call getpwnam()
Summary: wtmp-helper: don't call getpwnam()
Status: RESOLVED FIXED
Alias: None
Product: accountsservice
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: Matthias Clasen
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-25 15:20 UTC by Ray Strode [halfline]
Modified: 2018-04-26 17:03 UTC (History)
4 users (show)

See Also:
i915 platform:
i915 features:


Attachments
wtmp-helper: don't call getpwnam() (5.67 KB, patch)
2018-04-25 15:20 UTC, Ray Strode [halfline]
Details | Splinter Review

Description Ray Strode [halfline] 2018-04-25 15:20:26 UTC
The wtmp helper code examines /var/log/wtmp to determine which
users log in the most frequently.

That code calls getpwnam() once for every entry in /var/log/wtmp.
This is very inefficient, since getpwnam() can be quite slow, and
/var/log/wtmp will often have the same users repeated over and
over again.

Also, we don't actually use the result for anything other than verifying
the existence of the user! And we already verify the existence of
the user later later in the code in a more efficient way (by finding
the user in the users hashtable).

This commit just drops the unnecessary getpwnam() call.
Comment 1 Ray Strode [halfline] 2018-04-25 15:20:31 UTC
Created attachment 139099 [details] [review]
wtmp-helper: don't call getpwnam()
Comment 2 Paul Menzel 2018-04-26 16:50:50 UTC
Tested-by: Paul Menzel <pmenzel@molgen.mpg.de>

… with `/var/log/tmp` with size of 20 MB, which are roughly 25,000 lines in the output of `last`.
Comment 3 Ray Strode [halfline] 2018-04-26 17:03:45 UTC
Attachment 139099 [details] pushed as 081a2b7 - wtmp-helper: don't call getpwnam()


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.