lists.arthurdejong.org
RSS feed

nss-pam-ldapd branch master updated. 0.9.1-12-g560e5de

[Date Prev][Date Next] [Thread Prev][Thread Next]

nss-pam-ldapd branch master updated. 0.9.1-12-g560e5de



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "nss-pam-ldapd".

The branch, master has been updated
       via  560e5de575720c13d9085fe1014cb0377c9ccd12 (commit)
       via  db5382ec111ba1080cf7a5b2d6a4c881ec04bc5d (commit)
       via  7895739cfec05b5edb9eff8c8673803fcdf9ed75 (commit)
      from  a683aa8c7266e7851ca571b8705476268b8e9314 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=560e5de575720c13d9085fe1014cb0377c9ccd12

commit 560e5de575720c13d9085fe1014cb0377c9ccd12
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Sep 2 23:34:56 2013 +0200

    Add a test for tio timeout calculations
    
    This test checks whether the proposed remaining time to sleep is
    reasonable.

diff --git a/.gitignore b/.gitignore
index c06a860..294a9f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,6 +72,7 @@ stamp-*
 /tests/test_pamcmds.log
 /tests/test_set
 /tests/test_tio
+/tests/test_tio_timeout
 
 # /utils/
 /utils/constants.py
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 45f73fc..e8a5680 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,7 @@
 
 TESTS = test_dict test_set test_tio test_expr test_getpeercred test_cfg \
         test_myldap.sh test_common test_nsscmds.sh test_pamcmds.sh \
-        test_manpages.sh test_clock
+        test_manpages.sh test_clock test_tio_timeout
 if HAVE_PYTHON
   TESTS += test_pycompile.sh test_pylint.sh
 endif
@@ -31,7 +31,7 @@ endif
 AM_TESTS_ENVIRONMENT = PYTHON='@PYTHON@'; export PYTHON;
 
 check_PROGRAMS = test_dict test_set test_tio test_expr test_getpeercred \
-                 test_cfg test_myldap test_common test_clock \
+                 test_cfg test_myldap test_common test_clock test_tio_timeout \
                  lookup_netgroup lookup_shadow
 
 EXTRA_DIST = nslcd-test.conf usernames.txt in_testenv.sh test_myldap.sh \
@@ -87,6 +87,8 @@ test_common_LDADD = ../nslcd/cfg.o $(common_nslcd_LDADD)
 
 test_clock_SOURCES = test_clock.c
 
+test_tio_timeout_SOURCES = test_tio_timeout.c ../common/tio.h
+
 lookup_netgroup_SOURCES = lookup_netgroup.c
 
 lookup_shadow_SOURCES = lookup_shadow.c
diff --git a/tests/test_tio_timeout.c b/tests/test_tio_timeout.c
new file mode 100644
index 0000000..18d8d4f
--- /dev/null
+++ b/tests/test_tio_timeout.c
@@ -0,0 +1,50 @@
+/*
+   test_tio_timeout.c - tests for tio deadline calculations
+   This file is part of the nss-pam-ldapd library.
+
+   Copyright (C) 2013 Arthur de Jong
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301 USA
+*/
+
+/* we include the source because we want to test static methods */
+#include "../common/tio.c"
+
+#include <assert.h>
+
+int main(int UNUSED(argc), char UNUSED(*argv[]))
+{
+  struct timespec deadline = {0, 0};
+  int timeout = 100 * 1000;
+  int sleeptime = 1000;
+  int low = -100;
+  int high = 200;
+  int res;
+  int ok;
+  /* initialise deadline */
+  assert(tio_time_remaining(&deadline, timeout) == timeout);
+  /* wait one second */
+  sleep(sleeptime / 1000);
+  /* re-calculate the deadline */
+  res = tio_time_remaining(&deadline, timeout);
+  /* it should be timeout - sleeptime */
+  res = timeout - sleeptime - res;
+  ok = (res > low) && (res < high);
+  printf("%s: %d msec difference (%swithin %d...%d msec)\n",
+         ok ? "OK" : "FAIL", res, ok ? "" : "NOT ",
+         low, high);
+  return !ok;
+}

http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=db5382ec111ba1080cf7a5b2d6a4c881ec04bc5d

commit db5382ec111ba1080cf7a5b2d6a4c881ec04bc5d
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Mon Sep 2 23:07:33 2013 +0200

    Add a test for clock_gettime() supported clocks
    
    This probes the system for available clocks to see if they can be
    reliably used to get a monotonic-like timer (the test doesn't verify the
    monotonic part, just usability).

diff --git a/.gitignore b/.gitignore
index 4316faa..c06a860 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,6 +63,7 @@ stamp-*
 /tests/test*.log
 /tests/test*.trs
 /tests/test_cfg
+/tests/test_clock
 /tests/test_common
 /tests/test_dict
 /tests/test_expr
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 441af73..45f73fc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,7 @@
 
 TESTS = test_dict test_set test_tio test_expr test_getpeercred test_cfg \
         test_myldap.sh test_common test_nsscmds.sh test_pamcmds.sh \
-        test_manpages.sh
+        test_manpages.sh test_clock
 if HAVE_PYTHON
   TESTS += test_pycompile.sh test_pylint.sh
 endif
@@ -31,7 +31,7 @@ endif
 AM_TESTS_ENVIRONMENT = PYTHON='@PYTHON@'; export PYTHON;
 
 check_PROGRAMS = test_dict test_set test_tio test_expr test_getpeercred \
-                 test_cfg test_myldap test_common \
+                 test_cfg test_myldap test_common test_clock \
                  lookup_netgroup lookup_shadow
 
 EXTRA_DIST = nslcd-test.conf usernames.txt in_testenv.sh test_myldap.sh \
@@ -85,6 +85,8 @@ test_myldap_LDADD = ../nslcd/cfg.o $(common_nslcd_LDADD)
 test_common_SOURCES = test_common.c ../nslcd/common.h
 test_common_LDADD = ../nslcd/cfg.o $(common_nslcd_LDADD)
 
+test_clock_SOURCES = test_clock.c
+
 lookup_netgroup_SOURCES = lookup_netgroup.c
 
 lookup_shadow_SOURCES = lookup_shadow.c
diff --git a/tests/test_clock.c b/tests/test_clock.c
new file mode 100644
index 0000000..8d55f93
--- /dev/null
+++ b/tests/test_clock.c
@@ -0,0 +1,158 @@
+/*
+   test_clock.c - tests for finding usable system clocks
+   This file is part of the nss-pam-ldapd library.
+
+   Copyright (C) 2013 Arthur de Jong
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <stdio.h>
+#include <assert.h>
+#include <time.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "compat/attrs.h"
+
+/* use clock_gettime() to see if the specified clock is supported */
+static int test_clock_gettime(clockid_t c, const char *cname)
+{
+  struct timespec t1 = {0, 0};
+  struct timespec t2 = {0, 0};
+  struct timespec t3 = {0, 50 * 1000 * 1000}; /* 50 msec */
+  struct timespec t4 = {0, 0};
+  long diff;
+  int result = 0;
+  /* see if we can get resolution (not important so ignore any failures) */
+  errno = 0;
+  if (clock_getres(c, &t1))
+    printf("     clock %s resolution not supported: %s\n", cname, 
strerror(errno));
+  if ((t1.tv_sec != 0) || (t1.tv_nsec != 0))
+    printf("     clock %s resolution: %ld.%09ld\n", cname, (long)t1.tv_sec, 
(long)t1.tv_nsec);
+  /* see if we can get the time */
+  errno = 0;
+  if (clock_gettime(c, &t2))
+  {
+    printf("FAIL clock %s get time not supported: %s\n",
+           cname, strerror(errno));
+    if ((t2.tv_sec != 0) || (t2.tv_nsec != 0))
+      printf("     clock %s time: %ld.%09ld\n", cname, (long)t2.tv_sec, 
(long)t2.tv_nsec);
+    return -1;
+  }
+  else
+    printf("OK   clock %s time: %ld.%09ld\n", cname, (long)t2.tv_sec, 
(long)t2.tv_nsec);
+  /* quick sleep (assume we're not interrupted) */
+  (void)nanosleep(&t3, NULL);
+  /* see if we can get the time again */
+  errno = 0;
+  if (clock_gettime(c, &t4))
+  {
+    printf("FAIL clock %s get time twice not supported: %s\n",
+           cname, strerror(errno));
+    if ((t4.tv_sec != 0) || (t4.tv_nsec != 0))
+      printf("     clock %s time: %ld.%09ld\n", cname, (long)t4.tv_sec, 
(long)t4.tv_nsec);
+    return -1;
+  }
+  else
+    printf("OK   clock %s time: %ld.%09ld\n", cname, (long)t4.tv_sec, 
(long)t4.tv_nsec);
+  /* calculate difference */
+  diff = ((long)t4.tv_sec - (long)t2.tv_sec - (long)t3.tv_sec) * 
(long)1000000000 +
+         ((long)t4.tv_nsec - (long)t2.tv_nsec - (long)t3.tv_nsec);
+  if ((diff < (-10 * 1000 * 1000)) || (diff > (20 * 1000 * 1000)))
+  {
+    result = -1;
+    printf("FAIL ");
+  }
+  else
+    printf("OK   ");
+  printf("clock %s time diff: %s%ld.%09ld %.1f%%\n", cname, (diff < 0) ? "-" : 
"",
+         (labs(diff) / 1000000000L), (labs(diff) % 1000000000L),
+         labs(100L * diff) / (float)((long)t3.tv_sec * 1000000000L + 
(long)t3.tv_nsec));
+  return result;
+}
+
+/* wrapper for test_clock_gettime() that passes the clock name */
+#define TEST_CLOCK_GETTIME(clock) test_clock_gettime(clock, #clock)
+
+int main(int UNUSED(argc), char UNUSED(*argv[]))
+{
+  int found_clocks = 0;
+#ifdef CLOCK_MONOTONIC_RAW
+  if (!TEST_CLOCK_GETTIME(CLOCK_MONOTONIC_RAW))
+    found_clocks++;
+#endif
+#ifdef CLOCK_MONOTONIC_FAST
+  if (!TEST_CLOCK_GETTIME(CLOCK_MONOTONIC_FAST))
+    found_clocks++;
+#endif
+#ifdef CLOCK_MONOTONIC_COARSE
+  if (!TEST_CLOCK_GETTIME(CLOCK_MONOTONIC_COARSE))
+    found_clocks++;
+#endif
+#ifdef CLOCK_MONOTONIC
+  if (!TEST_CLOCK_GETTIME(CLOCK_MONOTONIC))
+    found_clocks++;
+#endif
+#ifdef CLOCK_UPTIME_FAST
+  if (!TEST_CLOCK_GETTIME(CLOCK_UPTIME_FAST))
+    found_clocks++;
+#endif
+#ifdef CLOCK_UPTIME
+  if (!TEST_CLOCK_GETTIME(CLOCK_UPTIME))
+    found_clocks++;
+#endif
+#ifdef CLOCK_BOOTTIME
+  if (!TEST_CLOCK_GETTIME(CLOCK_BOOTTIME))
+    found_clocks++;
+#endif
+#ifdef CLOCK_MONOTONIC_PRECISE
+  if (!TEST_CLOCK_GETTIME(CLOCK_MONOTONIC_PRECISE))
+    found_clocks++;
+#endif
+#ifdef CLOCK_UPTIME_PRECISE
+  if (!TEST_CLOCK_GETTIME(CLOCK_UPTIME_PRECISE))
+    found_clocks++;
+#endif
+#ifdef CLOCK_HIGHRES
+#if CLOCK_HIGHRES == CLOCK_MONOTONIC
+  printf("     CLOCK_HIGHRES == CLOCK_MONOTONIC\n");
+#else
+  /* for Solaris, should be similar to CLOCK_MONOTONIC (it may be an alias) */
+  if (!TEST_CLOCK_GETTIME(CLOCK_HIGHRES))
+    found_clocks++;
+#endif
+#endif
+#ifdef CLOCK_REALTIME_FAST
+  if (!TEST_CLOCK_GETTIME(CLOCK_REALTIME_FAST))
+    found_clocks++;
+#endif
+#ifdef CLOCK_REALTIME_COARSE
+  if (!TEST_CLOCK_GETTIME(CLOCK_REALTIME_COARSE))
+    found_clocks++;
+#endif
+  if (!TEST_CLOCK_GETTIME(CLOCK_REALTIME))
+    found_clocks++;
+#ifdef CLOCK_REALTIME_PRECISE
+  if (!TEST_CLOCK_GETTIME(CLOCK_REALTIME_PRECISE))
+    found_clocks++;
+#endif
+  printf("%d usable clocks found\n", found_clocks);
+  return !(found_clocks > 0);
+}

http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=7895739cfec05b5edb9eff8c8673803fcdf9ed75

commit 7895739cfec05b5edb9eff8c8673803fcdf9ed75
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Sep 1 15:22:56 2013 +0200

    Use clock_gettime() instead of gettimeofday()
    
    This avoids problems with system clock changes (though there are some
    safeguards in place to avoid waiting too long on clock changes).
    
    Thanks to John Sullivan for pointing this out.
    
    We can't easily use CLOCK_MONOTONIC_RAW or CLOCK_MONOTONIC_COARSE even
    on platforms that define the clock because we can get runtime errors.
    CLOCK_MONOTONIC seems to work on all tested platforms that provide it.

diff --git a/AUTHORS b/AUTHORS
index 0889ab1..27437d6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -123,3 +123,4 @@ Thorsten Glaser <t.glaser@tarent.de>
 Steve Hill <steve@opendium.com>
 Caleb Callaway <enlightened.despot@gmail.com>
 Bersl <bersl2@bersl2.info>
+John Sullivan <jsrhbz@kanargh.force9.co.uk>
diff --git a/common/tio.c b/common/tio.c
index aa032d7..650f4d0 100644
--- a/common/tio.c
+++ b/common/tio.c
@@ -36,6 +36,7 @@
 #include <stdio.h>
 #include <limits.h>
 #include <poll.h>
+#include <time.h>
 
 #include "tio.h"
 
@@ -75,28 +76,36 @@ struct tio_fileinfo {
 #endif /* DEBUG_TIO_STATS */
 };
 
+/* some older versions of Solaris don't provide CLOCK_MONOTONIC but do have
+   a CLOCK_HIGHRES that has the same properties we need */
+#ifndef CLOCK_MONOTONIC
+#ifdef CLOCK_HIGHRES
+#define CLOCK_MONOTONIC CLOCK_HIGHRES
+#endif /* CLOCK_HIGHRES */
+#endif /* not CLOCK_MONOTONIC */
+
 /* update the timeout to the value that is remaining before the deadline
    returns the number of milliseconds before the deadline (or a negative
    value of the deadline has expired) */
-static inline int tio_time_remaining(struct timeval *deadline, int timeout)
+static inline int tio_time_remaining(struct timespec *deadline, int timeout)
 {
-  struct timeval tv;
+  struct timespec tv;
   /* if this is the first call, set the deadline and return the full time */
-  if ((deadline->tv_sec == 0) && (deadline->tv_usec == 0))
+  if ((deadline->tv_sec == 0) && (deadline->tv_nsec == 0))
   {
-    if (gettimeofday(deadline, NULL) == 0)
+    if (clock_gettime(CLOCK_MONOTONIC, deadline) == 0)
     {
       deadline->tv_sec += timeout / 1000;
-      deadline->tv_usec += (timeout % 1000) * 1000;
+      deadline->tv_nsec += (timeout % 1000) * 1000000;
     }
     return timeout;
   }
   /* get the current time (fall back to full time on error) */
-  if (gettimeofday(&tv, NULL))
+  if (clock_gettime(CLOCK_MONOTONIC, &tv))
     return timeout;
-  /* calculate time remaining in miliseconds */
+  /* calculate time remaining in milliseconds */
   return (deadline->tv_sec - tv.tv_sec) * 1000 +
-         (deadline->tv_usec - tv.tv_usec) / 1000;
+         (deadline->tv_nsec - tv.tv_nsec) / 1000000;
 }
 
 /* open a new TFILE based on the file descriptor */
@@ -146,7 +155,7 @@ TFILE *tio_fdopen(int fd, int readtimeout, int writetimeout,
 /* wait for any activity on the specified file descriptor using
    the specified deadline */
 static int tio_wait(int fd, short events, int timeout,
-                    struct timeval *deadline)
+                    struct timespec *deadline)
 {
   int t;
   struct pollfd fds[1];
@@ -185,7 +194,7 @@ static int tio_wait(int fd, short events, int timeout,
    if no data was read in the specified time an error is returned */
 int tio_read(TFILE *fp, void *buf, size_t count)
 {
-  struct timeval deadline = {0, 0};
+  struct timespec deadline = {0, 0};
   int rv;
   uint8_t *tmp;
   size_t newsz;
@@ -284,7 +293,7 @@ int tio_skip(TFILE *fp, size_t count)
 /* Read all available data from the stream and empty the read buffer. */
 int tio_skipall(TFILE *fp, int timeout)
 {
-  struct timeval deadline = {0, 0};
+  struct timespec deadline = {0, 0};
   int rv;
   size_t len;
   /* clear the read buffer */
@@ -372,7 +381,7 @@ static int tio_writebuf(TFILE *fp)
 /* write all the data in the buffer to the stream */
 int tio_flush(TFILE *fp)
 {
-  struct timeval deadline = {0, 0};
+  struct timespec deadline = {0, 0};
   /* loop until we have written our buffer */
   while (fp->writebuffer.len > 0)
   {
diff --git a/configure.ac b/configure.ac
index 1dd2419..56d02ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -322,6 +322,7 @@ AC_CHECK_FUNCS([strcasecmp strncasecmp strchr strcspn 
strspn strtol strtoul strt
 AC_CHECK_FUNCS([malloc realloc atexit])
 AC_FUNC_FORK
 AC_CHECK_FUNCS(__assert_fail)
+AC_SEARCH_LIBS(clock_gettime, rt)
 
 # checks for types
 AC_TYPE_MODE_T

-----------------------------------------------------------------------

Summary of changes:
 .gitignore               |    2 +
 AUTHORS                  |    1 +
 common/tio.c             |   33 ++++++----
 configure.ac             |    1 +
 tests/Makefile.am        |    8 ++-
 tests/test_clock.c       |  158 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/test_tio_timeout.c |   50 +++++++++++++++
 7 files changed, 239 insertions(+), 14 deletions(-)
 create mode 100644 tests/test_clock.c
 create mode 100644 tests/test_tio_timeout.c


hooks/post-receive
-- 
nss-pam-ldapd
-- 
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits/