[Git][NTPsec/ntpsec][master] 3 commits: Eliminate use of non-POSIX rtprio() calls for priority-setting.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Jul 18 16:19:38 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
4a76d3d4 by Eric S. Raymond at 2016-07-18T11:54:27-04:00
Eliminate use of non-POSIX rtprio() calls for priority-setting.

Even if it were portable, that code looked pretty bit-rotted.

- - - - -
be6fab00 by Eric S. Raymond at 2016-07-18T12:04:00-04:00
Visibility limitation. No logic changes.

- - - - -
1957fa7f by Eric S. Raymond at 2016-07-18T12:19:19-04:00
Simplify the logic of the priority-setting code...

...removing a confusing tri-state enum in favor of a bool.  Should be
no actual behavior change from this.

- - - - -


2 changed files:

- ntpd/ntpd.c
- pylib/configure.py


Changes:

=====================================
ntpd/ntpd.c
=====================================
--- a/ntpd/ntpd.c
+++ b/ntpd/ntpd.c
@@ -8,7 +8,7 @@
 #include "ntpd.h"
 #include "ntp_io.h"
 #include "ntp_stdlib.h"
-#include <ntp_random.h>
+#include "ntp_random.h"
 
 #include "ntp_config.h"
 #include "ntp_syslog.h"
@@ -68,11 +68,9 @@ DNSServiceRef mdns;
  */
 #define NTPD_PRIO	(-12)
 
-static  enum {PRIORITY_UNSET,	/* Set priority */
-	      PRIORITY_OK,	/* Priority is OK where it is */
-	      PRIORITY_NOSET,	/* Don't set priority */
-				/* Latter two are pretty much the same */
-} priority_done = PRIORITY_NOSET;
+static bool priority_ok = true;
+static bool config_priority_override = false;
+static int config_priority;
 
 bool listen_to_virtual_ips = true;
 
@@ -105,9 +103,6 @@ const char *chrootdir;	/* directory to chroot to */
 int	waitsync_fd_to_close = -1;	/* -w/--wait-sync */
 #endif
 
-bool config_priority_override = false;
-int config_priority;
-
 char const *progname;
 
 #ifdef HAVE_NETINFO_NI_H
@@ -343,7 +338,7 @@ parse_cmdline_opts(
 		nofork = true;
 		break;
 	    case 'N':
-		priority_done = PRIORITY_UNSET;
+		priority_ok = false;
 		break;
 	    case 'p':
 		pidfile = ntp_optarg;
@@ -351,7 +346,7 @@ parse_cmdline_opts(
 	    case 'P':
 		config_priority = atoi(ntp_optarg);
 		config_priority_override = true;
-		priority_done = PRIORITY_UNSET;
+		priority_ok = false;
 		break;
 	    case 'q':
 		mode_ntpdate = true;
@@ -527,18 +522,16 @@ catch_danger(int signo)
 static void
 set_process_priority(void)
 {
-
 # ifdef DEBUG
 	if (debug > 1)
-		msyslog(LOG_DEBUG, "set_process_priority: %s: priority_done is <%d>",
-			((priority_done)
+		msyslog(LOG_DEBUG, "set_process_priority: %s",
+			((priority_ok)
 			 ? "Leave priority alone"
 			 : "Attempt to set priority"
-				),
-			priority_done);
+				));
 # endif /* DEBUG */
-
-	if (priority_done == PRIORITY_UNSET) {
+#ifdef HAVE_SCHED_SETSCHEDULER
+	if (!priority_ok) {
 		int pmax, pmin;
 		struct sched_param sched;
 
@@ -553,44 +546,19 @@ set_process_priority(void)
 			else
 				sched.sched_priority = config_priority;
 		}
-#ifdef HAVE_SCHED_SETSCHEDULER
 		if ( sched_setscheduler(0, SCHED_FIFO, &sched) == -1 )
 			msyslog(LOG_ERR, "sched_setscheduler(): %m");
 		else
-#endif
-			priority_done = PRIORITY_OK;
+			priority_ok = true;
 	}
-# ifdef HAVE_RTPRIO
-#  ifdef RTP_SET
-	if (priority_done == PRIORITY_UNSET) {
-		struct rtprio srtp;
-
-		srtp.type = RTP_PRIO_REALTIME;	/* was: RTP_PRIO_NORMAL */
-		srtp.prio = 0;		/* 0 (hi) -> RTP_PRIO_MAX (31,lo) */
-
-		if (rtprio(RTP_SET, getpid(), &srtp) < 0)
-			msyslog(LOG_ERR, "rtprio() error: %m");
-		else
-			priority_done = PRIORITY_OK;
-	}
-#  else	/* !RTP_SET follows */
-	if (priority_done == oriority_set) {
-		if (rtprio(0, 120) < 0)
-			msyslog(LOG_ERR, "rtprio() error: %m");
-		else
-			priority_done = PRIORITY_OK;
-	}
-#  endif	/* !RTP_SET */
-# endif	/* HAVE_RTPRIO */
-# if defined(NTPD_PRIO) && NTPD_PRIO != 0
-	if (priority_done == PRIORITY_UNSET) {
+#endif
+	if (!priority_ok) {
 		if (-1 == setpriority(PRIO_PROCESS, 0, NTPD_PRIO))
 			msyslog(LOG_ERR, "setpriority() error: %m");
 		else
-			priority_done = PRIORITY_OK;
+			priority_ok = true;
 	}
-# endif	/* NTPD_PRIO && NTPD_PRIO != 0 */
-	if (priority_done == PRIORITY_UNSET)
+	if (!priority_ok)
 		msyslog(LOG_ERR, "set_process_priority: No way found to improve our priority");
 }
 #endif	/* !SIM */


=====================================
pylib/configure.py
=====================================
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -295,7 +295,6 @@ def cmd_configure(ctx, config):
 		('ntp_adjtime', ["sys/time.h", "sys/timex.h"]),		# BSD
 		('ntp_gettime', ["sys/time.h", "sys/timex.h"]),		# BSD
 		('res_init', ["resolv.h"]),
-		("rtprio", ["sys/rtprio.h"]),		# Sun/BSD
 		('sched_setscheduler', ["sched.h"]),
 		('settimeofday', ["sys/time.h"], "RT"),	# BSD
 		('strlcpy', ["string.h"]),



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/170941fa42cb129cca33cc40085d1f917ccdadcb...1957fa7f332eb4a732a71b76355b08a9fe4a2e6d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160718/17808ddd/attachment.html>


More information about the vc mailing list