[Git][NTPsec/ntpsec][master] 7 commits: add signal.h to test for timer_create in wscript

Hal Murray gitlab at mg.gitlab.com
Sat Dec 22 00:57:04 UTC 2018


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
a82dc90f by Hal Murray at 2018-12-20T21:28:43Z
add signal.h to test for timer_create in wscript

- - - - -
031a824d by Hal Murray at 2018-12-20T21:28:43Z
Remove HAVE_CLOCK_SETTIME test from libntp/clockwork.c

- - - - -
66143743 by Hal Murray at 2018-12-20T21:28:43Z
Don't check for threads if no DNS

- - - - -
feecefbd by Hal Murray at 2018-12-21T10:00:40Z
Add comment for MAP_HASSEMAPHORE in ntpd/refclock_oncore.c

- - - - -
88eb64e5 by Hal Murray at 2018-12-21T10:02:03Z
Use sigprocmask vs pthread_sigmask if no DNS

To avoid dragging in libpthread.

- - - - -
dd913226 by Hal Murray at 2018-12-21T10:05:03Z
Add seccomp support for timer_create

It was never tested due to bug in wscript.

- - - - -
04e53271 by Hal Murray at 2018-12-21T23:54:41Z
work on probe cleanup in wscript, fix timer_create

- - - - -


7 changed files:

- libntp/clockwork.c
- ntpd/ntp_io.c
- ntpd/ntp_sandbox.c
- ntpd/refclock_oncore.c
- wafhelpers/check_pthread.py
- wafhelpers/probes.py
- wscript


Changes:

=====================================
libntp/clockwork.c
=====================================
@@ -77,14 +77,10 @@ ntp_set_tod(
 	int		saved_errno;
 
 	TPRINT(1, ("In ntp_set_tod\n"));
-#ifdef HAVE_CLOCK_SETTIME
 	errno = 0;
 	rc = clock_settime(CLOCK_REALTIME, tvs);
 	saved_errno = errno;
 	TPRINT(1, ("ntp_set_tod: clock_settime: %d %m\n", rc));
-#else
-#error POSIX clock_settime(2) is required
-#endif /* HAVE_CLOCK_SETTIME */
 	errno = saved_errno;	/* for %m below */
 	TPRINT(1, ("ntp_set_tod: Final result: clock_settime: %d %m\n", rc));
 


=====================================
ntpd/ntp_io.c
=====================================
@@ -2257,7 +2257,11 @@ io_handler(void)
 	 * time.  select() will terminate on SIGALARM or on the
 	 * reception of input.
 	 */
+#ifdef ENABLE_DNS_LOOKUP
 	pthread_sigmask(SIG_BLOCK, &blockMask, &runMask);
+#else
+	sigprocmask(SIG_BLOCK, &blockMask, &runMask);
+#endif
 	flag = sig_flags.sawALRM || sig_flags.sawQuit || sig_flags.sawHUP || \
 	  sig_flags.sawDNS;
 	if (!flag) {
@@ -2267,7 +2271,11 @@ io_handler(void)
 	  nfound = -1;
 	  errno = EINTR;
 	}
+#ifdef ENABLE_DNS_LOOKUP
 	pthread_sigmask(SIG_SETMASK, &runMask, NULL);
+#else
+	sigprocmask(SIG_SETMASK, &runMask, NULL);
+#endif  
 
 	if (nfound > 0) {
 		input_handler(&rdfdes);


=====================================
ntpd/ntp_sandbox.c
=====================================
@@ -321,7 +321,6 @@ int scmp_sc[] = {
 #ifdef __NR_getrandom
 	SCMP_SYS(getrandom),	/* Added in 3.17 kernel */
 #endif
-	SCMP_SYS(getitimer),
 #ifdef __NR_ugetrlimit
 	SCMP_SYS(ugetrlimit),	/* sysconf */
 #endif
@@ -360,7 +359,6 @@ int scmp_sc[] = {
 	SCMP_SYS(select),	/* not in ARM */
 #endif
 	SCMP_SYS(sendto),
-	SCMP_SYS(setitimer),
 	SCMP_SYS(setsid),
 #ifdef __NR_setsockopt
 	SCMP_SYS(setsockopt),	/* not in old kernels */
@@ -371,6 +369,14 @@ int scmp_sc[] = {
 	SCMP_SYS(statfs64),	/* from getaddrinfo after lid open */
 #ifdef __NR_time
 	SCMP_SYS(time),		/* not in ARM */
+#endif
+#ifdef HAVE_TIMER_CREATE
+	SCMP_SYS(timer_create),
+	SCMP_SYS(timer_gettime),
+	SCMP_SYS(timer_settime),
+#else
+	SCMP_SYS(getitimer),
+	SCMP_SYS(setitimer),
 #endif
 	SCMP_SYS(write),
         SCMP_SYS(unlink),


=====================================
ntpd/refclock_oncore.c
=====================================
@@ -1046,6 +1046,8 @@ oncore_init_shmem(
 	instance->shmem = (uint8_t *) mmap(0, shmem_length,
 		PROT_READ | PROT_WRITE,
 #ifdef MAP_HASSEMAPHORE
+		/* In API and man pages for FreeBSD and NetBSD
+		   But unused in kernel.  HGM, 2018-Dec.  */
 		MAP_HASSEMAPHORE |
 #endif
 		MAP_SHARED, instance->shmemfd, (off_t)0);


=====================================
wafhelpers/check_pthread.py
=====================================
@@ -13,6 +13,10 @@ int main(void) {
 
 
 def check_pthread_header_lib(ctx):
+    if ctx.options.disable_dns_lookup:
+      # threads only used by DNS lookup
+      # libcrypto uses pthread_once, but that's not our problem
+      return
     ctx.check(header_name="pthread.h", includes=ctx.env.PLATFORM_INCLUDES,
               mandatory=False, comment="pthread header")
     ctx.check(feature="c cshlib", lib="pthread",


=====================================
wafhelpers/probes.py
=====================================
@@ -4,7 +4,7 @@ up the logic in the main configure.py.
 """
 
 
-def probe_header_with_prerequisites(ctx, header, prerequisites, use=None):
+def probe_header(ctx, header, prerequisites, mandatory=False, use=None):
     "Check that a header (with its prerequisites) compiles."
     src = ""
     for hdr in prerequisites + [header]:
@@ -17,14 +17,14 @@ def probe_header_with_prerequisites(ctx, header, prerequisites, use=None):
         define_name=have_name,
         fragment=src,
         includes=ctx.env.PLATFORM_INCLUDES,
-        mandatory=False,
+        mandatory=mandatory,
         msg="Checking for header %s" % header,
         use=use or [],
     )
     return ctx.get_define(have_name)
 
 
-def probe_function_with_prerequisites(ctx, function, prerequisites, use=None):
+def probe_function(ctx, function, prerequisites, mandatory=False, use=None):
     "Check that a function (with its prerequisites) compiles."
     src = ""
     for hdr in prerequisites:
@@ -40,7 +40,7 @@ def probe_function_with_prerequisites(ctx, function, prerequisites, use=None):
         define_name=have_name,
         fragment=src,
         includes=ctx.env.PLATFORM_INCLUDES,
-        mandatory=False,
+        mandatory=mandatory,
         msg="Checking for function %s" % function,
         use=use or [],
     )


=====================================
wscript
=====================================
@@ -22,8 +22,7 @@ from waflib.Tools import waf_unit_test
 sys.dont_write_bytecode = True
 
 from wafhelpers.options import options_cmd
-from wafhelpers.probes \
-    import probe_header_with_prerequisites, probe_function_with_prerequisites
+from wafhelpers.probes import probe_header, probe_function
 from wafhelpers.test import test_write_log, test_print_log
 
 
@@ -603,57 +602,49 @@ int main(int argc, char **argv) {
     ):
         ctx.check_cc(msg="Checking for OpenSSL's crypto library",
                      lib="crypto", mandatory=True)
-    # Very old versions of OpenSSL don't have cmac support.
-    # This gives a sane(er) error message.
-    # It would be possible to make CMAC support optional by adding
-    # appropriate #ifdefs to the code.
-    openssl_headers = (
-        "openssl/evp.h",
-        "openssl/cmac.h",
-        "openssl/objects.h",
-        "openssl/md5.h",
-        "openssl/rand.h",
-    )
-    for hdr in openssl_headers:
-        ctx.check_cc(header_name=hdr, mandatory=True,
-            includes=ctx.env.PLATFORM_INCLUDES)
 
     # Optional functions.  Do all function checks here, otherwise
     # we're likely to duplicate them.
-    functions = (
+    optional_functions = (
         ('_Unwind_Backtrace', ["unwind.h"]),
         ('adjtimex', ["sys/time.h", "sys/timex.h"]),
         ('backtrace_symbols_fd', ["execinfo.h"]),
         ('closefrom', ["stdlib.h"]),
-        ('clock_gettime', ["time.h"], "RT"),
-        ('clock_settime', ["time.h"], "RT"),
         ('ntp_adjtime', ["sys/time.h", "sys/timex.h"]),     # BSD
         ('ntp_gettime', ["sys/time.h", "sys/timex.h"]),     # BSD
         ('res_init', ["netinet/in.h", "arpa/nameser.h", "resolv.h"]),
         ('sched_setscheduler', ["sched.h"]),
         ('strlcpy', ["string.h"]),
-        ('strlcat', ["string.h"]),
-        ('timer_create', ["time.h"])
+        ('strlcat', ["string.h"]) 
     )
-    for ft in functions:
-        if len(ft) == 2:
-            probe_function_with_prerequisites(ctx, function=ft[0],
-                                              prerequisites=ft[1])
-        else:
-            probe_function_with_prerequisites(ctx, function=ft[0],
-                                              prerequisites=ft[1],
-                                              use=ft[2])
+    for ft in optional_functions:
+            probe_function(ctx, function=ft[0], prerequisites=ft[1])
+
+    # This area is still work in progress
+    # Need to disable making symbols
+    #   but not until killing off HAVE_TIMER_CREATE
+
+    # Sanity checks to give a sensible error message
+    required_functions = (
+        ('timer_create', ["signal.h", "time.h"], "RT"),
+        ('CMAC_CTX_new', ["openssl/cmac.h"], "CRYPTO") )
+    for ft in required_functions:
+            probe_function(ctx, function=ft[0],
+                prerequisites=ft[1], use=ft[2],
+                mandatory=True)
+
+
 
     # check for BSD versions outside of libc
     if not ctx.get_define("HAVE_STRLCAT"):
-        ret = probe_function_with_prerequisites(ctx, function='strlcat',
-                                                prerequisites=['bsd/string.h'])
+        ret = probe_function(ctx, function='strlcat',
+                    prerequisites=['bsd/string.h'])
         if ret:
             ctx.define("HAVE_STRLCAT", 1, comment="Using bsd/strlcat")
 
     if not ctx.get_define("HAVE_STRLCPY"):
-        ret = probe_function_with_prerequisites(ctx, function='strlcpy',
-                                                prerequisites=['bsd/string.h'])
+        ret = probe_function(ctx, function='strlcpy',
+                    prerequisites=['bsd/string.h'])
         if ret:
             ctx.define("HAVE_STRLCPY", 1, comment="Using bsd/strlcpy")
 
@@ -684,7 +675,6 @@ int main(int argc, char **argv) {
         ("net/route.h", ["sys/types.h", "sys/socket.h", "net/if.h"]),
         "netinfo/ni.h",     # Apple
         "priv.h",           # Solaris
-        "semaphore.h",
         "stdatomic.h",
         "sys/clockctl.h",   # NetBSD
         "sys/ioctl.h",
@@ -702,7 +692,7 @@ int main(int argc, char **argv) {
                 continue
         else:
             (hdr, prereqs) = hdr
-            if probe_header_with_prerequisites(ctx, hdr, prereqs):
+            if probe_header(ctx, hdr, prereqs):
                 continue
         if os.path.exists("/usr/include/" + hdr):
             # Sanity check...



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/87fd0e300e5621147967be3953a97d50290611b8...04e53271a4a979b83d343a7a279ce5c4fd1b0bf8

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/87fd0e300e5621147967be3953a97d50290611b8...04e53271a4a979b83d343a7a279ce5c4fd1b0bf8
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20181222/7086d4aa/attachment-0001.html>


More information about the vc mailing list