[PATCH] sys_posix: support SCHED_FIFO and mlockall on more OSs

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


Real-time scheduling and memory locking is available on posix compliant
OSs. This patch centralizes this functionality and brings support to
FreeBSD, NetBSD, and Solaris.
---
 configure   |  31 +++++++++++----
 sys.c       |  12 ++++--
 sys_linux.c |  67 --------------------------------
 sys_posix.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sys_posix.h |  36 +++++++++++++++++
 5 files changed, 177 insertions(+), 78 deletions(-)
 create mode 100644 sys_posix.c
 create mode 100644 sys_posix.h

diff --git a/configure b/configure
index c434127..b458ab3 100755
--- a/configure
+++ b/configure
@@ -396,7 +396,7 @@ SYSTEM=${OPERATINGSYSTEM}-${MACHINE}

 case $OPERATINGSYSTEM in
     Linux)
-        EXTRA_OBJECTS="sys_generic.o sys_linux.o sys_timex.o"
+        EXTRA_OBJECTS="sys_generic.o sys_linux.o sys_timex.o sys_posix.o"
         [ $try_libcap != "0" ] && try_libcap=1
         try_rtc=1
         [ $try_seccomp != "0" ] && try_seccomp=1
@@ -405,14 +405,18 @@ case $OPERATINGSYSTEM in
         try_lockmem=1
         try_phc=1
         add_def LINUX
+        add_def POSIX
         echo "Configuring for " $SYSTEM
     ;;
     FreeBSD)
         # recvmmsg() seems to be broken on FreeBSD 11.0 and it's just
         # a wrapper around recvmsg()
         try_recvmmsg=0
-        EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o"
+        EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
+        try_setsched=1
+        try_lockmem=1
         add_def FREEBSD
+        add_def POSIX
         if [ $feat_droproot = "1" ]; then
           add_def FEAT_PRIVDROP
           priv_ops="ADJUSTTIME ADJUSTTIMEX SETTIME BINDSOCKET"
@@ -420,9 +424,12 @@ case $OPERATINGSYSTEM in
         echo "Configuring for $SYSTEM"
     ;;
     NetBSD)
-        EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o"
+        EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
         try_clockctl=1
+        try_setsched=1
+        try_lockmem=1
         add_def NETBSD
+        add_def POSIX
         echo "Configuring for $SYSTEM"
     ;;
     Darwin)
@@ -446,10 +453,13 @@ case $OPERATINGSYSTEM in
         echo "Configuring for macOS (" $SYSTEM "macOS version" $VERSION ")"
     ;;
     SunOS)
-        EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o"
+        EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o sys_posix.o"
         EXTRA_LIBS="-lsocket -lnsl -lresolv"
         EXTRA_CLI_LIBS="-lsocket -lnsl -lresolv"
+        try_setsched=1
+        try_lockmem=1
         add_def SOLARIS
+        add_def POSIX
         # These are needed to have msg_control in struct msghdr
         add_def __EXTENSIONS__
         add_def _XOPEN_SOURCE 1
@@ -800,13 +810,20 @@ fi
 if [ $try_lockmem = "1" ] && \
   test_code \
     'mlockall()' \
-    'sys/mman.h sys/resource.h' '' '' '
-     struct rlimit rlim;
-     setrlimit(RLIMIT_MEMLOCK, &rlim);
+    'sys/mman.h' '' '' '
      mlockall(MCL_CURRENT|MCL_FUTURE);'
 then
   add_def HAVE_MLOCKALL
 fi
+if [ $try_lockmem = "1" ] && \
+  test_code \
+    'setrlimit(RLIMIT_MEMLOCK, ...)' \
+    'sys/resource.h' '' '' '
+     struct rlimit rlim;
+     setrlimit(RLIMIT_MEMLOCK, &rlim);'
+then
+  add_def HAVE_SETRLIMIT_MEMLOCK
+fi

 if [ $feat_forcednsretry = "1" ]
 then
diff --git a/sys.c b/sys.c
index 2c42db1..7201250 100644
--- a/sys.c
+++ b/sys.c
@@ -43,6 +43,10 @@
 #include "sys_macosx.h"
 #endif

+#if defined(POSIX)
+#include "sys_posix.h"
+#endif
+
 /* ================================================== */

 static int null_driver;
@@ -124,8 +128,8 @@ void SYS_EnableSystemCallFilter(int level)

 void SYS_SetScheduler(int SchedPriority)
 {
-#if defined(LINUX) && defined(HAVE_PTHREAD_SETSCHEDPARAM)
-  SYS_Linux_SetScheduler(SchedPriority);
+#if defined(POSIX) && defined(HAVE_PTHREAD_SETSCHEDPARAM)
+  SYS_Posix_SetScheduler(SchedPriority);
 #elif defined(MACOSX)
   SYS_MacOSX_SetScheduler(SchedPriority);
 #else
@@ -137,8 +141,8 @@ void SYS_SetScheduler(int SchedPriority)

 void SYS_LockMemory(void)
 {
-#if defined(LINUX) && defined(HAVE_MLOCKALL)
-  SYS_Linux_MemLockAll(1);
+#if defined(POSIX) && defined(HAVE_MLOCKALL)
+  SYS_Posix_MemLockAll(1);
 #else
   LOG_FATAL("memory locking not supported");
 #endif
diff --git a/sys_linux.c b/sys_linux.c
index 9e4ab3f..898dc7a 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -33,16 +33,6 @@

 #include <sys/utsname.h>

-#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
-#  include <pthread.h>
-#  include <sched.h>
-#endif
-
-#if defined(HAVE_MLOCKALL)
-#  include <sys/mman.h>
-#include <sys/resource.h>
-#endif
-
 #if defined(FEAT_PHC) || defined(HAVE_LINUX_TIMESTAMPING)
 #include <linux/ptp_clock.h>
 #endif
@@ -633,63 +623,6 @@ add_failed:

 /* ================================================== */

-#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
-  /* Install SCHED_FIFO real-time scheduler with specified priority */
-void SYS_Linux_SetScheduler(int SchedPriority)
-{
-  int pmax, pmin;
-  struct sched_param sched;
-
-  if (SchedPriority < 1 || SchedPriority > 99) {
-    LOG_FATAL("Bad scheduler priority: %d", SchedPriority);
-  } else {
-    sched.sched_priority = SchedPriority;
-    pmax = sched_get_priority_max(SCHED_FIFO);
-    pmin = sched_get_priority_min(SCHED_FIFO);
-    if ( SchedPriority > pmax ) {
-      sched.sched_priority = pmax;
-    }
-    else if ( SchedPriority < pmin ) {
-      sched.sched_priority = pmin;
-    }
-    if ( pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched) == -1 )
{
-      LOG(LOGS_ERR, "pthread_setschedparam() failed");
-    }
-    else {
-      DEBUG_LOG("Enabled SCHED_FIFO with priority %d",
-          sched.sched_priority);
-    }
-  }
-}
-#endif /* HAVE_PTHREAD_SETSCHEDPARAM  */
-
-#if defined(HAVE_MLOCKALL)
-/* Lock the process into RAM so that it will never be swapped out */
-void SYS_Linux_MemLockAll(int LockAll)
-{
-  struct rlimit rlim;
-  if (LockAll == 1 ) {
-    /* Make sure that we will be able to lock all the memory we need */
-    /* even after dropping privileges.  This does not actually reaerve any
memory */
-    rlim.rlim_max = RLIM_INFINITY;
-    rlim.rlim_cur = RLIM_INFINITY;
-    if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) {
-      LOG(LOGS_ERR, "setrlimit() failed: not locking into RAM");
-    }
-    else {
-      if (mlockall(MCL_CURRENT|MCL_FUTURE) < 0) {
-    LOG(LOGS_ERR, "mlockall() failed");
-      }
-      else {
-    DEBUG_LOG("Successfully locked into RAM");
-      }
-    }
-  }
-}
-#endif /* HAVE_MLOCKALL */
-
-/* ================================================== */
-
 int
 SYS_Linux_CheckKernelVersion(int req_major, int req_minor)
 {
diff --git a/sys_posix.c b/sys_posix.c
new file mode 100644
index 0000000..77720c3
--- /dev/null
+++ b/sys_posix.c
@@ -0,0 +1,109 @@
+/*
+  chronyd/chronyc - Programs for keeping computer clocks accurate.
+
+ **********************************************************************
+ * Copyright (C) Richard P. Curnow  1997-2003
+ * Copyright (C) John G. Hasler  2009
+ * Copyright (C) Miroslav Lichvar  2009-2012, 2014-2018
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ **********************************************************************
+
+  =======================================================================
+
+  This is the module is for POSIX compliant operating systems.
+
+  */
+
+#include "config.h"
+
+#include "sysincl.h"
+
+#include <sys/utsname.h>
+
+#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
+#  include <pthread.h>
+#  include <sched.h>
+#endif
+
+#if defined(HAVE_MLOCKALL)
+#  include <sys/mman.h>
+#  include <sys/resource.h>
+#endif
+
+#include "sys_posix.h"
+#include "conf.h"
+#include "local.h"
+#include "logging.h"
+#include "util.h"
+
+/* ================================================== */
+
+#if defined(HAVE_PTHREAD_SETSCHEDPARAM)
+  /* Install SCHED_FIFO real-time scheduler with specified priority */
+void SYS_Posix_SetScheduler(int SchedPriority)
+{
+  int pmax, pmin;
+  struct sched_param sched;
+
+  if (SchedPriority < 1 || SchedPriority > 99) {
+    LOG_FATAL("Bad scheduler priority: %d", SchedPriority);
+  } else {
+    sched.sched_priority = SchedPriority;
+    pmax = sched_get_priority_max(SCHED_FIFO);
+    pmin = sched_get_priority_min(SCHED_FIFO);
+    if ( SchedPriority > pmax ) {
+      sched.sched_priority = pmax;
+    }
+    else if ( SchedPriority < pmin ) {
+      sched.sched_priority = pmin;
+    }
+    if ( pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched) == -1 )
{
+      LOG(LOGS_ERR, "pthread_setschedparam() failed");
+    }
+    else {
+      DEBUG_LOG("Enabled SCHED_FIFO with priority %d",
+          sched.sched_priority);
+    }
+  }
+}
+#endif /* HAVE_PTHREAD_SETSCHEDPARAM  */
+
+/* ================================================== */
+
+#if defined(HAVE_MLOCKALL)
+/* Lock the process into RAM so that it will never be swapped out */
+void SYS_Posix_MemLockAll(int LockAll)
+{
+  if (LockAll == 1 ) {
+#if defined(HAVE_SETRLIMIT_MEMLOCK)
+    // Try to reserve as much as we can
+    struct rlimit rlim;
+    rlim.rlim_max = RLIM_INFINITY;
+    rlim.rlim_cur = RLIM_INFINITY;
+    if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) {
+      LOG(LOGS_ERR, "setrlimit() failed");
+    }
+#endif
+    if (mlockall(MCL_CURRENT|MCL_FUTURE) < 0) {
+      LOG(LOGS_ERR, "mlockall() failed");
+    }
+    else {
+      DEBUG_LOG("Successfully locked into RAM");
+    }
+  }
+}
+#endif /* HAVE_MLOCKALL */
+
diff --git a/sys_posix.h b/sys_posix.h
new file mode 100644
index 0000000..2138c16
--- /dev/null
+++ b/sys_posix.h
@@ -0,0 +1,36 @@
+/*
+  chronyd/chronyc - Programs for keeping computer clocks accurate.
+
+ **********************************************************************
+ * Copyright (C) Richard P. Curnow  1997-2003
+ * Copyright (C) John G. Hasler  2009
+ * Copyright (C) Miroslav Lichvar  2009-2012, 2014-2018
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ **********************************************************************
+
+  =======================================================================
+
+  The header file for shared Posix functionality
+  */
+
+#ifndef GOT_SYS_POSIX_H
+#define GOT_SYS_POSIX_H
+
+extern void SYS_Posix_MemLockAll(int LockAll);
+
+extern void SYS_Posix_SetScheduler(int SchedPriority);
+
+#endif  /* GOT_SYS_POSIX_H */
-- 
2.21.0

--000000000000792b62058669ec5f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div>Hi,</div><div><br></div><div>The fol=
lowing patch centralizes the memory locking and real-time scheduling for PO=
SIX systems. It brings support for these features to FreeBSD, NetBSD, and S=
olaris. Note that MacOS does support the pthread_setschedparam() API, but i=
t does not function as intended for real-time scheduling. As such, MacOS wa=
s not included in the patch.<br></div><div><br></div><div>Also note that th=
e memory locking behavior changed ever-so-slightly. Solaris does not suppor=
t setrlimit(RLIMIT_MEMLOCK, ...), so this was turned into an optional call =
and an additional configure test. It will no longer prevent memory locking,=
 even if the call fails.<br></div><div><br></div><div>I tested this patch u=
sing Linux 4.18 with glibc, FreeBSD 11.2 &amp; 12, NetBSD 8, and Solaris 11=
.. </div><div><br></div><div>The documentation needs to be updated for the n=
ew support as well. I can submit this as a separate patch or combine it int=
o one. Your choice.<br></div><div><br></div><div>Regards,</div><div>Stefan<=
/div><div><br></div><div><br></div><div>From f2c8a92dea463f5203021d18cfec5e=
db92438d9f Mon Sep 17 00:00:00 2001<br>From: &quot;Stefan R. Filipek&quot; =
&lt;<a href=3D"mailto:srfilipek@xxxxxxxxx"; target=3D"_blank">srfilipek@gmai=
l.com</a>&gt;<br>Date: Mon, 8 Apr 2019 20:41:03 -0400<br>Subject: [PATCH] s=
ys_posix: support SCHED_FIFO and mlockall on more OSs<br><br>Real-time sche=
duling and memory locking is available on posix compliant<br>OSs. This patc=
h centralizes this functionality and brings support to<br>FreeBSD, NetBSD, =
and Solaris.<br>---<br>=C2=A0configure=C2=A0=C2=A0 |=C2=A0 31 +++++++++++--=
--<br>=C2=A0sys.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 12 ++++--<br>=
=C2=A0sys_linux.c |=C2=A0 67 --------------------------------<br>=C2=A0sys_=
posix.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>=C2=
=A0sys_posix.h |=C2=A0 36 +++++++++++++++++<br>=C2=A05 files changed, 177 i=
nsertions(+), 78 deletions(-)<br>=C2=A0create mode 100644 sys_posix.c<br>=
=C2=A0create mode 100644 sys_posix.h<br><br>diff --git a/configure b/config=
ure<br>index c434127..b458ab3 100755<br>--- a/configure<br>+++ b/configure<=
br>@@ -396,7 +396,7 @@ SYSTEM=3D${OPERATINGSYSTEM}-${MACHINE}<br>=C2=A0<br>=
=C2=A0case $OPERATINGSYSTEM in<br>=C2=A0=C2=A0=C2=A0=C2=A0 Linux)<br>-=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EXTRA_OBJECTS=3D&quot;sys_generic.o=
 sys_linux.o sys_timex.o&quot;<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 EXTRA_OBJECTS=3D&quot;sys_generic.o sys_linux.o sys_timex.o sys_posix.o=
&quot;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [ $try_libcap !=
=3D &quot;0&quot; ] &amp;&amp; try_libcap=3D1<br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 try_rtc=3D1<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 [ $try_seccomp !=3D &quot;0&quot; ] &amp;&amp; try_seccomp=
=3D1<br>@@ -405,14 +405,18 @@ case $OPERATINGSYSTEM in<br>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_lockmem=3D1<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_phc=3D1<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 add_def LINUX<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 add_def POSIX<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ec=
ho &quot;Configuring for &quot; $SYSTEM<br>=C2=A0=C2=A0=C2=A0=C2=A0 ;;<br>=
=C2=A0=C2=A0=C2=A0=C2=A0 FreeBSD)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 # recvmmsg() seems to be broken on FreeBSD 11.0 and it&#39;s j=
ust<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # a wrapper around =
recvmsg()<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_recvmmsg=
=3D0<br>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EXTRA_OBJECTS=3D&quot;s=
ys_generic.o sys_netbsd.o sys_timex.o&quot;<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 EXTRA_OBJECTS=3D&quot;sys_generic.o sys_netbsd.o sys_timex.=
o sys_posix.o&quot;<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_sets=
ched=3D1<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_lockmem=3D1<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 add_def FREEBSD<br>+=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 add_def POSIX<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 if [ $feat_droproot =3D &quot;1&quot; ]; then<b=
r>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 add_def FEAT=
_PRIVDROP<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 p=
riv_ops=3D&quot;ADJUSTTIME ADJUSTTIMEX SETTIME BINDSOCKET&quot;<br>@@ -420,=
9 +424,12 @@ case $OPERATINGSYSTEM in<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 echo &quot;Configuring for $SYSTEM&quot;<br>=C2=A0=C2=A0=C2=
=A0=C2=A0 ;;<br>=C2=A0=C2=A0=C2=A0=C2=A0 NetBSD)<br>-=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 EXTRA_OBJECTS=3D&quot;sys_generic.o sys_netbsd.o sys_=
timex.o&quot;<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EXTRA_OBJECTS=
=3D&quot;sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o&quot;<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_clockctl=3D1<br>+=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_setsched=3D1<br>+=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 try_lockmem=3D1<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 add_def NETBSD<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 add_def POSIX<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ec=
ho &quot;Configuring for $SYSTEM&quot;<br>=C2=A0=C2=A0=C2=A0=C2=A0 ;;<br>=
=C2=A0=C2=A0=C2=A0=C2=A0 Darwin)<br>@@ -446,10 +453,13 @@ case $OPERATINGSY=
STEM in<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 echo &quot;Conf=
iguring for macOS (&quot; $SYSTEM &quot;macOS version&quot; $VERSION &quot;=
)&quot;<br>=C2=A0=C2=A0=C2=A0=C2=A0 ;;<br>=C2=A0=C2=A0=C2=A0=C2=A0 SunOS)<b=
r>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EXTRA_OBJECTS=3D&quot;sys_gen=
eric.o sys_solaris.o sys_timex.o&quot;<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 EXTRA_OBJECTS=3D&quot;sys_generic.o sys_solaris.o sys_timex.o =
sys_posix.o&quot;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 EXTRA=
_LIBS=3D&quot;-lsocket -lnsl -lresolv&quot;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 EXTRA_CLI_LIBS=3D&quot;-lsocket -lnsl -lresolv&quot;<=
br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_setsched=3D1<br>+=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try_lockmem=3D1<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 add_def SOLARIS<br>+=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 add_def POSIX<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 # These are needed to have msg_control in struct msghdr<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 add_def __EXTENSIONS__<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 add_def _XOPEN_SOURCE 1<br>@@ -8=
00,13 +810,20 @@ fi<br>=C2=A0if [ $try_lockmem =3D &quot;1&quot; ] &amp;&am=
p; \<br>=C2=A0=C2=A0 test_code \<br>=C2=A0=C2=A0=C2=A0=C2=A0 &#39;mlockall(=
)&#39; \<br>-=C2=A0=C2=A0=C2=A0 &#39;sys/mman.h sys/resource.h&#39; &#39;&#=
39; &#39;&#39; &#39;<br>-=C2=A0=C2=A0=C2=A0=C2=A0 struct rlimit rlim;<br>-=
=C2=A0=C2=A0=C2=A0=C2=A0 setrlimit(RLIMIT_MEMLOCK, &amp;rlim);<br>+=C2=A0=
=C2=A0=C2=A0 &#39;sys/mman.h&#39; &#39;&#39; &#39;&#39; &#39;<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 mlockall(MCL_CURRENT|MCL_FUTURE);&#39;<br>=C2=A0then<=
br>=C2=A0=C2=A0 add_def HAVE_MLOCKALL<br>=C2=A0fi<br>+if [ $try_lockmem =3D=
 &quot;1&quot; ] &amp;&amp; \<br>+=C2=A0 test_code \<br>+=C2=A0=C2=A0=C2=A0=
 &#39;setrlimit(RLIMIT_MEMLOCK, ...)&#39; \<br>+=C2=A0=C2=A0=C2=A0 &#39;sys=
/resource.h&#39; &#39;&#39; &#39;&#39; &#39;<br>+=C2=A0=C2=A0=C2=A0=C2=A0 s=
truct rlimit rlim;<br>+=C2=A0=C2=A0=C2=A0=C2=A0 setrlimit(RLIMIT_MEMLOCK, &=
amp;rlim);&#39;<br>+then<br>+=C2=A0 add_def HAVE_SETRLIMIT_MEMLOCK<br>+fi<b=
r>=C2=A0<br>=C2=A0if [ $feat_forcednsretry =3D &quot;1&quot; ]<br>=C2=A0the=
n<br>diff --git a/sys.c b/sys.c<br>index 2c42db1..7201250 100644<br>--- a/s=
ys.c<br>+++ b/sys.c<br>@@ -43,6 +43,10 @@<br>=C2=A0#include &quot;sys_macos=
x.h&quot;<br>=C2=A0#endif<br>=C2=A0<br>+#if defined(POSIX)<br>+#include &qu=
ot;sys_posix.h&quot;<br>+#endif<br>+<br>=C2=A0/* =3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */<br>=C2=A0<br>=C2=A0s=
tatic int null_driver;<br>@@ -124,8 +128,8 @@ void SYS_EnableSystemCallFilt=
er(int level)<br>=C2=A0<br>=C2=A0void SYS_SetScheduler(int SchedPriority)<b=
r>=C2=A0{<br>-#if defined(LINUX) &amp;&amp; defined(HAVE_PTHREAD_SETSCHEDPA=
RAM)<br>-=C2=A0 SYS_Linux_SetScheduler(SchedPriority);<br>+#if defined(POSI=
X) &amp;&amp; defined(HAVE_PTHREAD_SETSCHEDPARAM)<br>+=C2=A0 SYS_Posix_SetS=
cheduler(SchedPriority);<br>=C2=A0#elif defined(MACOSX)<br>=C2=A0=C2=A0 SYS=
_MacOSX_SetScheduler(SchedPriority);<br>=C2=A0#else<br>@@ -137,8 +141,8 @@ =
void SYS_SetScheduler(int SchedPriority)<br>=C2=A0<br>=C2=A0void SYS_LockMe=
mory(void)<br>=C2=A0{<br>-#if defined(LINUX) &amp;&amp; defined(HAVE_MLOCKA=
LL)<br>-=C2=A0 SYS_Linux_MemLockAll(1);<br>+#if defined(POSIX) &amp;&amp; d=
efined(HAVE_MLOCKALL)<br>+=C2=A0 SYS_Posix_MemLockAll(1);<br>=C2=A0#else<br=
>=C2=A0=C2=A0 LOG_FATAL(&quot;memory locking not supported&quot;);<br>=C2=
=A0#endif<br>diff --git a/sys_linux.c b/sys_linux.c<br>index 9e4ab3f..898dc=
7a 100644<br>--- a/sys_linux.c<br>+++ b/sys_linux.c<br>@@ -33,16 +33,6 @@<b=
r>=C2=A0<br>=C2=A0#include &lt;sys/utsname.h&gt;<br>=C2=A0<br>-#if defined(=
HAVE_PTHREAD_SETSCHEDPARAM)<br>-#=C2=A0 include &lt;pthread.h&gt;<br>-#=C2=
=A0 include &lt;sched.h&gt;<br>-#endif<br>-<br>-#if defined(HAVE_MLOCKALL)<=
br>-#=C2=A0 include &lt;sys/mman.h&gt;<br>-#include &lt;sys/resource.h&gt;<=
br>-#endif<br>-<br>=C2=A0#if defined(FEAT_PHC) || defined(HAVE_LINUX_TIMEST=
AMPING)<br>=C2=A0#include &lt;linux/ptp_clock.h&gt;<br>=C2=A0#endif<br>@@ -=
633,63 +623,6 @@ add_failed:<br>=C2=A0<br>=C2=A0/* =3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */<br>=C2=A0<br>-#if de=
fined(HAVE_PTHREAD_SETSCHEDPARAM)<br>-=C2=A0 /* Install SCHED_FIFO real-tim=
e scheduler with specified priority */<br>-void SYS_Linux_SetScheduler(int =
SchedPriority)<br>-{<br>-=C2=A0 int pmax, pmin;<br>-=C2=A0 struct sched_par=
am sched;<br>-<br>-=C2=A0 if (SchedPriority &lt; 1 || SchedPriority &gt; 99=
) {<br>-=C2=A0=C2=A0=C2=A0 LOG_FATAL(&quot;Bad scheduler priority: %d&quot;=
, SchedPriority);<br>-=C2=A0 } else {<br>-=C2=A0=C2=A0=C2=A0 sched.sched_pr=
iority =3D SchedPriority;<br>-=C2=A0=C2=A0=C2=A0 pmax =3D sched_get_priorit=
y_max(SCHED_FIFO);<br>-=C2=A0=C2=A0=C2=A0 pmin =3D sched_get_priority_min(S=
CHED_FIFO);<br>-=C2=A0=C2=A0=C2=A0 if ( SchedPriority &gt; pmax ) {<br>-=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 sched.sched_priority =3D pmax;<br>-=C2=A0=C2=A0=
=C2=A0 }<br>-=C2=A0=C2=A0=C2=A0 else if ( SchedPriority &lt; pmin ) {<br>-=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sched.sched_priority =3D pmin;<br>-=C2=A0=C2=
=A0=C2=A0 }<br>-=C2=A0=C2=A0=C2=A0 if ( pthread_setschedparam(pthread_self(=
), SCHED_FIFO, &amp;sched) =3D=3D -1 ) {<br>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
 LOG(LOGS_ERR, &quot;pthread_setschedparam() failed&quot;);<br>-=C2=A0=C2=
=A0=C2=A0 }<br>-=C2=A0=C2=A0=C2=A0 else {<br>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 DEBUG_LOG(&quot;Enabled SCHED_FIFO with priority %d&quot;,<br>-=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sched.sched_priority);<br>=
-=C2=A0=C2=A0=C2=A0 }<br>-=C2=A0 }<br>-}<br>-#endif /* HAVE_PTHREAD_SETSCHE=
DPARAM=C2=A0 */<br>-<br>-#if defined(HAVE_MLOCKALL)<br>-/* Lock the process=
 into RAM so that it will never be swapped out */ <br>-void SYS_Linux_MemLo=
ckAll(int LockAll)<br>-{<br>-=C2=A0 struct rlimit rlim;<br>-=C2=A0 if (Lock=
All =3D=3D 1 ) {<br>-=C2=A0=C2=A0=C2=A0 /* Make sure that we will be able t=
o lock all the memory we need */<br>-=C2=A0=C2=A0=C2=A0 /* even after dropp=
ing privileges.=C2=A0 This does not actually reaerve any memory */<br>-=C2=
=A0=C2=A0=C2=A0 rlim.rlim_max =3D RLIM_INFINITY;<br>-=C2=A0=C2=A0=C2=A0 rli=
m.rlim_cur =3D RLIM_INFINITY;<br>-=C2=A0=C2=A0=C2=A0 if (setrlimit(RLIMIT_M=
EMLOCK, &amp;rlim) &lt; 0) {<br>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG(LOGS_ER=
R, &quot;setrlimit() failed: not locking into RAM&quot;);<br>-=C2=A0=C2=A0=
=C2=A0 }<br>-=C2=A0=C2=A0=C2=A0 else {<br>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 i=
f (mlockall(MCL_CURRENT|MCL_FUTURE) &lt; 0) {<br>-=C2=A0=C2=A0=C2=A0 LOG(LO=
GS_ERR, &quot;mlockall() failed&quot;);<br>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
}<br>-=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else {<br>-=C2=A0=C2=A0=C2=A0 DEBUG_LO=
G(&quot;Successfully locked into RAM&quot;);<br>-=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 }<br>-=C2=A0=C2=A0=C2=A0 }<br>-=C2=A0 }<br>-}<br>-#endif /* HAVE_MLO=
CKALL */<br>-<br>-/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D */<br>-<br>=C2=A0int<br>=C2=A0SYS_Linux_CheckKernelVe=
rsion(int req_major, int req_minor)<br>=C2=A0{<br>diff --git a/sys_posix.c =
b/sys_posix.c<br>new file mode 100644<br>index 0000000..77720c3<br>--- /dev=
/null<br>+++ b/sys_posix.c<br>@@ -0,0 +1,109 @@<br>+/*<br>+=C2=A0 chronyd/c=
hronyc - Programs for keeping computer clocks accurate.<br>+<br>+ *********=
*************************************************************<br>+ * Copyri=
ght (C) Richard P. Curnow=C2=A0 1997-2003<br>+ * Copyright (C) John G. Hasl=
er=C2=A0 2009<br>+ * Copyright (C) Miroslav Lichvar=C2=A0 2009-2012, 2014-2=
018<br>+ *<br>+ * This program is free software; you can redistribute it an=
d/or modify<br>+ * it under the terms of version 2 of the GNU General Publi=
c License as<br>+ * published by the Free Software Foundation.<br>+ *<br>+ =
* This program is distributed in the hope that it will be useful, but<br>+ =
* WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ * MERCHAN=
TABILITY or FITNESS FOR A PARTICULAR PURPOSE.=C2=A0 See the GNU<br>+ * Gene=
ral Public License for more details.<br>+ *<br>+ * You should have received=
 a copy of the GNU General Public License along<br>+ * with this program; i=
f not, write to the Free Software Foundation, Inc.,<br>+ * 51 Franklin Stre=
et, Fifth Floor, Boston, MA=C2=A0 02110-1301, USA.<br>+ *<br>+ ************=
**********************************************************<br>+<br>+=C2=A0 =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>+<br>+=
=C2=A0 This is the module is for POSIX compliant operating systems.<br>+<br=
>+=C2=A0 */<br>+<br>+#include &quot;config.h&quot;<br>+<br>+#include &quot;=
sysincl.h&quot;<br>+<br>+#include &lt;sys/utsname.h&gt;<br>+<br>+#if define=
d(HAVE_PTHREAD_SETSCHEDPARAM)<br>+#=C2=A0 include &lt;pthread.h&gt;<br>+#=
=C2=A0 include &lt;sched.h&gt;<br>+#endif<br>+<br>+#if defined(HAVE_MLOCKAL=
L)<br>+#=C2=A0 include &lt;sys/mman.h&gt;<br>+#=C2=A0 include &lt;sys/resou=
rce.h&gt;<br>+#endif<br>+<br>+#include &quot;sys_posix.h&quot;<br>+#include=
 &quot;conf.h&quot;<br>+#include &quot;local.h&quot;<br>+#include &quot;log=
ging.h&quot;<br>+#include &quot;util.h&quot;<br>+<br>+/* =3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */<br>+<br>+#if d=
efined(HAVE_PTHREAD_SETSCHEDPARAM)<br>+=C2=A0 /* Install SCHED_FIFO real-ti=
me scheduler with specified priority */<br>+void SYS_Posix_SetScheduler(int=
 SchedPriority)<br>+{<br>+=C2=A0 int pmax, pmin;<br>+=C2=A0 struct sched_pa=
ram sched;<br>+<br>+=C2=A0 if (SchedPriority &lt; 1 || SchedPriority &gt; 9=
9) {<br>+=C2=A0=C2=A0=C2=A0 LOG_FATAL(&quot;Bad scheduler priority: %d&quot=
;, SchedPriority);<br>+=C2=A0 } else {<br>+=C2=A0=C2=A0=C2=A0 sched.sched_p=
riority =3D SchedPriority;<br>+=C2=A0=C2=A0=C2=A0 pmax =3D sched_get_priori=
ty_max(SCHED_FIFO);<br>+=C2=A0=C2=A0=C2=A0 pmin =3D sched_get_priority_min(=
SCHED_FIFO);<br>+=C2=A0=C2=A0=C2=A0 if ( SchedPriority &gt; pmax ) {<br>+=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sched.sched_priority =3D pmax;<br>+=C2=A0=C2=
=A0=C2=A0 }<br>+=C2=A0=C2=A0=C2=A0 else if ( SchedPriority &lt; pmin ) {<br=
>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sched.sched_priority =3D pmin;<br>+=C2=A0=
=C2=A0=C2=A0 }<br>+=C2=A0=C2=A0=C2=A0 if ( pthread_setschedparam(pthread_se=
lf(), SCHED_FIFO, &amp;sched) =3D=3D -1 ) {<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 LOG(LOGS_ERR, &quot;pthread_setschedparam() failed&quot;);<br>+=C2=A0=
=C2=A0=C2=A0 }<br>+=C2=A0=C2=A0=C2=A0 else {<br>+=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 DEBUG_LOG(&quot;Enabled SCHED_FIFO with priority %d&quot;,<br>+=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sched.sched_priority);<=
br>+=C2=A0=C2=A0=C2=A0 }<br>+=C2=A0 }<br>+}<br>+#endif /* HAVE_PTHREAD_SETS=
CHEDPARAM=C2=A0 */<br>+<br>+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */<br>+<br>+#if defined(HAVE_MLOCKALL)<br=
>+/* Lock the process into RAM so that it will never be swapped out */<br>+=
void SYS_Posix_MemLockAll(int LockAll)<br>+{<br>+=C2=A0 if (LockAll =3D=3D =
1 ) {<br>+#if defined(HAVE_SETRLIMIT_MEMLOCK)<br>+=C2=A0=C2=A0=C2=A0 // Try=
 to reserve as much as we can<br>+=C2=A0=C2=A0=C2=A0 struct rlimit rlim;<br=
>+=C2=A0=C2=A0=C2=A0 rlim.rlim_max =3D RLIM_INFINITY;<br>+=C2=A0=C2=A0=C2=
=A0 rlim.rlim_cur =3D RLIM_INFINITY;<br>+=C2=A0=C2=A0=C2=A0 if (setrlimit(R=
LIMIT_MEMLOCK, &amp;rlim) &lt; 0) {<br>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG(=
LOGS_ERR, &quot;setrlimit() failed&quot;);<br>+=C2=A0=C2=A0=C2=A0 }<br>+#en=
dif<br>+=C2=A0=C2=A0=C2=A0 if (mlockall(MCL_CURRENT|MCL_FUTURE) &lt; 0) {<b=
r>+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG(LOGS_ERR, &quot;mlockall() failed&quo=
t;);<br>+=C2=A0=C2=A0=C2=A0 }<br>+=C2=A0=C2=A0=C2=A0 else {<br>+=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 DEBUG_LOG(&quot;Successfully locked into RAM&quot;);<=
br>+=C2=A0=C2=A0=C2=A0 }<br>+=C2=A0 }<br>+}<br>+#endif /* HAVE_MLOCKALL */<=
br>+<br>diff --git a/sys_posix.h b/sys_posix.h<br>new file mode 100644<br>i=
ndex 0000000..2138c16<br>--- /dev/null<br>+++ b/sys_posix.h<br>@@ -0,0 +1,3=
6 @@<br>+/*<br>+=C2=A0 chronyd/chronyc - Programs for keeping computer cloc=
ks accurate.<br>+<br>+ ****************************************************=
******************<br>+ * Copyright (C) Richard P. Curnow=C2=A0 1997-2003<b=
r>+ * Copyright (C) John G. Hasler=C2=A0 2009<br>+ * Copyright (C) Miroslav=
 Lichvar=C2=A0 2009-2012, 2014-2018<br>+ *<br>+ * This program is free soft=
ware; you can redistribute it and/or modify<br>+ * it under the terms of ve=
rsion 2 of the GNU General Public License as<br>+ * published by the Free S=
oftware Foundation.<br>+ *<br>+ * This program is distributed in the hope t=
hat it will be useful, but<br>+ * WITHOUT ANY WARRANTY; without even the im=
plied warranty of<br>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOS=
E.=C2=A0 See the GNU<br>+ * General Public License for more details.<br>+ *=
<br>+ * You should have received a copy of the GNU General Public License a=
long<br>+ * with this program; if not, write to the Free Software Foundatio=
n, Inc.,<br>+ * 51 Franklin Street, Fifth Floor, Boston, MA=C2=A0 02110-130=
1, USA.<br>+ *<br>+ *******************************************************=
***************<br>+<br>+=C2=A0 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D<br>+<br>+=C2=A0 The header file for shared Posix func=
tionality<br>+=C2=A0 */<br>+<br>+#ifndef GOT_SYS_POSIX_H<br>+#define GOT_SY=
S_POSIX_H<br>+<br>+extern void SYS_Posix_MemLockAll(int LockAll);<br>+<br>+=
extern void SYS_Posix_SetScheduler(int SchedPriority);<br>+<br>+#endif=C2=
=A0 /* GOT_SYS_POSIX_H */<br>-- <br>2.21.0<br></div></div></div>

--000000000000792b62058669ec5f--

-- 
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/