Bug 194025 - [PATCH] nscd set query timeout properly
Summary: [PATCH] nscd set query timeout properly
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: John Baldwin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-30 04:14 UTC by David Shane Holden
Modified: 2014-10-17 20:40 UTC (History)
1 user (show)

See Also:


Attachments
set timeout properly (559 bytes, patch)
2014-09-30 04:14 UTC, David Shane Holden
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Shane Holden 2014-09-30 04:14:12 UTC
Created attachment 147818 [details]
set timeout properly

So, I've noticed nscd hasn't worked right for awhile now.  Since I
upgraded to 10.0 it never seemed to cache properly but I never bothered
to really dig into it until recently and here's what I've found.  In my
environment I have nsswitch set to use caching and LDAP as such:

group: files cache ldap
passwd: files cache ldap

The LDAP part works fine, but caching didn't on 10.0 for some reason.
On my 9.2 machines it works as expected though.  What I've found is in
usr.sbin/nscd/query.c

struct query_state *
init_query_state(int sockfd, size_t kevent_watermark, uid_t euid, gid_t
egid)
{
  ...
    memcpy(&retval->timeout, &s_configuration->query_timeout,
        sizeof(struct timeval));
  ...
}

s_configuration->query_timeout is an 'int' which is being memcpy'd into
a 'struct timeval' causing it to grab other parts of the s_configuration
struct along with the query_timeout value and polluting retval->timeout.
In this case it appears to be grabbing s_configuration->threads_num and
shoving that into timeout.tv_sec along with the query_timeout. This ends
up confusing nscd later on (instead of being 8 it ends up being set to
34359738376) and breaks it's ability to cache.  I've attached a patch to
set the retval->timeout properly and gets nscd working again.  I'm
guessing gcc was handling this differently from clang which is why it
wasn't a problem before 10.0.
Comment 1 commit-hook freebsd_committer freebsd_triage 2014-10-06 18:17:24 UTC
A commit references this bug:

Author: jhb
Date: Mon Oct  6 18:16:46 UTC 2014
New revision: 272668
URL: https://svnweb.freebsd.org/changeset/base/272668

Log:
  Properly set the timeout in a query_state.  The global query_timeout
  configuration value is an integer count of seconds, it is not a timeval.
  Using memcpy() to copy a timeval from it put garbage into the tv_usec
  field.

  PR:		194025
  Submitted by:	David Shane Holden <dpejesh@yahoo.com>
  MFC after:	1 week

Changes:
  head/usr.sbin/nscd/query.c
Comment 2 commit-hook freebsd_committer freebsd_triage 2014-10-17 19:55:22 UTC
A commit references this bug:

Author: jhb
Date: Fri Oct 17 19:55:13 UTC 2014
New revision: 273238
URL: https://svnweb.freebsd.org/changeset/base/273238

Log:
  MFC 272668:
  Properly set the timeout in a query_state.  The global query_timeout
  configuration value is an integer count of seconds, it is not a timeval.
  Using memcpy() to copy a timeval from it put garbage into the tv_usec
  field.

  PR:		194025

Changes:
_U  stable/10/
  stable/10/usr.sbin/nscd/query.c
_U  stable/9/usr.sbin/nscd/
  stable/9/usr.sbin/nscd/query.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2014-10-17 20:40:27 UTC
A commit references this bug:

Author: jhb
Date: Fri Oct 17 20:39:39 UTC 2014
New revision: 273240
URL: https://svnweb.freebsd.org/changeset/base/273240

Log:
  MFS10 273238;
  Properly set the timeout in a query_state.  The global query_timeout
  configuration value is an integer count of seconds, it is not a timeval.
  Using memcpy() to copy a timeval from it put garbage into the tv_usec
  field.

  PR:		194025
  Approved by:	re (gjb)

Changes:
_U  releng/10.1/
  releng/10.1/usr.sbin/nscd/query.c