Clean up system options code
Abort with error message when trying to use unsupported/disabled system specific option.
This commit is contained in:
parent
032838b1b0
commit
e3234465e2
7 changed files with 70 additions and 63 deletions
48
conf.c
48
conf.c
|
@ -97,14 +97,8 @@ static void parse_pidfile(const char *);
|
||||||
static void parse_broadcast(const char *);
|
static void parse_broadcast(const char *);
|
||||||
static void parse_linux_hz(const char *);
|
static void parse_linux_hz(const char *);
|
||||||
static void parse_linux_freq_scale(const char *);
|
static void parse_linux_freq_scale(const char *);
|
||||||
|
|
||||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
|
||||||
static void parse_sched_priority(const char *);
|
static void parse_sched_priority(const char *);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_MLOCKALL)
|
|
||||||
static void parse_lockall(const char *);
|
static void parse_lockall(const char *);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Configuration variables */
|
/* Configuration variables */
|
||||||
|
@ -184,6 +178,9 @@ static int linux_hz;
|
||||||
static int set_linux_freq_scale = 0;
|
static int set_linux_freq_scale = 0;
|
||||||
static double linux_freq_scale;
|
static double linux_freq_scale;
|
||||||
|
|
||||||
|
static int sched_priority = 0;
|
||||||
|
static int lock_memory = 0;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -226,15 +223,9 @@ static const Command commands[] = {
|
||||||
{"pidfile", 7, parse_pidfile},
|
{"pidfile", 7, parse_pidfile},
|
||||||
{"broadcast", 9, parse_broadcast},
|
{"broadcast", 9, parse_broadcast},
|
||||||
{"linux_hz", 8, parse_linux_hz},
|
{"linux_hz", 8, parse_linux_hz},
|
||||||
{"linux_freq_scale", 16, parse_linux_freq_scale}
|
{"linux_freq_scale", 16, parse_linux_freq_scale},
|
||||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
{"sched_priority", 14, parse_sched_priority},
|
||||||
,{"sched_priority", 14, parse_sched_priority}
|
{"lock_all", 8, parse_lockall}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_MLOCKALL)
|
|
||||||
,{"lock_all", 8, parse_lockall}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int n_commands = (sizeof(commands) / sizeof(commands[0]));
|
static int n_commands = (sizeof(commands) / sizeof(commands[0]));
|
||||||
|
@ -396,23 +387,21 @@ parse_source(const char *line, NTP_Source_Type type)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
|
||||||
static void
|
static void
|
||||||
parse_sched_priority(const char *line)
|
parse_sched_priority(const char *line)
|
||||||
{
|
{
|
||||||
if (SchedPriority == 0) { /* Command-line switch must have priority */
|
if (sscanf(line, "%d", &sched_priority) != 1) {
|
||||||
sscanf(line, "%d", &SchedPriority);
|
LOG(LOGS_WARN, LOGF_Configure, "Could not read scheduling priority at line %d", line_number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_MLOCKALL)
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_lockall(const char *line)
|
parse_lockall(const char *line)
|
||||||
{
|
{
|
||||||
LockAll = 1;
|
lock_memory = 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
@ -1431,3 +1420,18 @@ CNF_GetLinuxFreqScale(int *set, double *freq_scale)
|
||||||
*freq_scale = linux_freq_scale ;
|
*freq_scale = linux_freq_scale ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CNF_GetSchedPriority(void)
|
||||||
|
{
|
||||||
|
return sched_priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CNF_GetLockMemory(void)
|
||||||
|
{
|
||||||
|
return lock_memory;
|
||||||
|
}
|
||||||
|
|
9
conf.h
9
conf.h
|
@ -75,12 +75,7 @@ extern int CNF_AllowLocalReference(int *stratum);
|
||||||
|
|
||||||
extern void CNF_SetupAccessRestrictions(void);
|
extern void CNF_SetupAccessRestrictions(void);
|
||||||
|
|
||||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
extern int CNF_GetSchedPriority(void);
|
||||||
extern int SchedPriority;
|
extern int CNF_GetLockMemory(void);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_MLOCKALL)
|
|
||||||
extern int LockAll;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* GOT_CONF_H */
|
#endif /* GOT_CONF_H */
|
||||||
|
|
|
@ -61,6 +61,7 @@ typedef enum {
|
||||||
LOGF_Logging,
|
LOGF_Logging,
|
||||||
LOGF_Rtc,
|
LOGF_Rtc,
|
||||||
LOGF_Regress,
|
LOGF_Regress,
|
||||||
|
LOGF_Sys,
|
||||||
LOGF_SysLinux,
|
LOGF_SysLinux,
|
||||||
LOGF_SysSolaris,
|
LOGF_SysSolaris,
|
||||||
LOGF_SysSunOS,
|
LOGF_SysSunOS,
|
||||||
|
|
43
main.c
43
main.c
|
@ -216,10 +216,7 @@ int main
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
int do_init_rtc = 0;
|
int do_init_rtc = 0;
|
||||||
int other_pid;
|
int other_pid;
|
||||||
|
int lock_memory = 0, sched_priority = 0;
|
||||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
|
||||||
int return_value = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LOG_Initialise();
|
LOG_Initialise();
|
||||||
|
|
||||||
|
@ -229,29 +226,22 @@ int main
|
||||||
if (!strcmp("-f", *argv)) {
|
if (!strcmp("-f", *argv)) {
|
||||||
++argv, --argc;
|
++argv, --argc;
|
||||||
conf_file = *argv;
|
conf_file = *argv;
|
||||||
|
|
||||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
|
||||||
/* Get real-time scheduler priority */
|
|
||||||
} else if (!strcmp("-P", *argv)) {
|
} else if (!strcmp("-P", *argv)) {
|
||||||
++argv, --argc;
|
++argv, --argc;
|
||||||
return_value = sscanf(*argv, "%d", &SchedPriority);
|
if (argc == 0 || sscanf(*argv, "%d", &sched_priority) != 1) {
|
||||||
if (return_value != 1 || SchedPriority < 1 || SchedPriority > 99) {
|
LOG_FATAL(LOGF_Main, "Bad scheduler priority");
|
||||||
SchedPriority = 0;
|
|
||||||
LOG(LOGS_WARN, LOGF_Main, "Bad scheduler priority: [%s]", *argv);
|
|
||||||
}
|
}
|
||||||
#endif /* HAVE_SCHED_SETCHEDULER */
|
|
||||||
|
|
||||||
#if defined(HAVE_MLOCKALL)
|
|
||||||
/* Detect lockall switch */
|
|
||||||
} else if (!strcmp("-m", *argv)) {
|
} else if (!strcmp("-m", *argv)) {
|
||||||
LockAll = 1;
|
lock_memory = 1;
|
||||||
#endif /* HAVE_MLOCKALL */
|
|
||||||
|
|
||||||
} else if (!strcmp("-r", *argv)) {
|
} else if (!strcmp("-r", *argv)) {
|
||||||
reload = 1;
|
reload = 1;
|
||||||
} else if (!strcmp("-u", *argv)) {
|
} else if (!strcmp("-u", *argv)) {
|
||||||
++argv, --argc;
|
++argv, --argc;
|
||||||
user = *argv;
|
if (argc == 0) {
|
||||||
|
LOG_FATAL(LOGF_Main, "Missing user name");
|
||||||
|
} else {
|
||||||
|
user = *argv;
|
||||||
|
}
|
||||||
} else if (!strcmp("-s", *argv)) {
|
} else if (!strcmp("-s", *argv)) {
|
||||||
do_init_rtc = 1;
|
do_init_rtc = 1;
|
||||||
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
||||||
|
@ -310,16 +300,21 @@ int main
|
||||||
RTC_Initialise();
|
RTC_Initialise();
|
||||||
RCL_Initialise();
|
RCL_Initialise();
|
||||||
|
|
||||||
if (SchedPriority > 0) {
|
/* Command-line switch must have priority */
|
||||||
SYS_SetScheduler(SchedPriority);
|
if (!sched_priority) {
|
||||||
|
sched_priority = CNF_GetSchedPriority();
|
||||||
|
}
|
||||||
|
if (sched_priority) {
|
||||||
|
SYS_SetScheduler(sched_priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LockAll == 1 ) {
|
if (lock_memory || CNF_GetLockMemory()) {
|
||||||
SYS_MemLockAll(LockAll);
|
SYS_LockMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user)
|
if (user) {
|
||||||
SYS_DropRoot(user);
|
SYS_DropRoot(user);
|
||||||
|
}
|
||||||
|
|
||||||
REF_Initialise();
|
REF_Initialise();
|
||||||
SST_Initialise();
|
SST_Initialise();
|
||||||
|
|
26
sys.c
26
sys.c
|
@ -30,6 +30,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
#if defined (LINUX)
|
#if defined (LINUX)
|
||||||
#include "sys_linux.h"
|
#include "sys_linux.h"
|
||||||
|
@ -102,7 +103,11 @@ void SYS_DropRoot(char *user)
|
||||||
{
|
{
|
||||||
#if defined(LINUX) && defined (FEAT_LINUXCAPS)
|
#if defined(LINUX) && defined (FEAT_LINUXCAPS)
|
||||||
SYS_Linux_DropRoot(user);
|
SYS_Linux_DropRoot(user);
|
||||||
|
#else
|
||||||
|
LOG_FATAL(LOGF_Sys, "dropping root privileges not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
@ -111,19 +116,24 @@ void SYS_SetScheduler(int SchedPriority)
|
||||||
{
|
{
|
||||||
#if defined(LINUX) && defined(HAVE_SCHED_SETSCHEDULER)
|
#if defined(LINUX) && defined(HAVE_SCHED_SETSCHEDULER)
|
||||||
SYS_Linux_SetScheduler(SchedPriority);
|
SYS_Linux_SetScheduler(SchedPriority);
|
||||||
|
#else
|
||||||
|
LOG_FATAL(LOGF_Sys, "scheduler priority setting not supported");
|
||||||
#endif
|
#endif
|
||||||
;;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SYS_MemLockAll(int LockAll)
|
return;
|
||||||
{
|
|
||||||
#if defined(LINUX) && defined(HAVE_MLOCKALL)
|
|
||||||
SYS_Linux_MemLockAll(LockAll);
|
|
||||||
#endif
|
|
||||||
;;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void SYS_LockMemory(void)
|
||||||
|
{
|
||||||
|
#if defined(LINUX) && defined(HAVE_MLOCKALL)
|
||||||
|
SYS_Linux_MemLockAll(1);
|
||||||
|
#else
|
||||||
|
LOG_FATAL(LOGF_Sys, "memory locking not supported");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
2
sys.h
2
sys.h
|
@ -43,6 +43,6 @@ extern void SYS_Finalise(void);
|
||||||
extern void SYS_DropRoot(char *user);
|
extern void SYS_DropRoot(char *user);
|
||||||
|
|
||||||
extern void SYS_SetScheduler(int SchedPriority);
|
extern void SYS_SetScheduler(int SchedPriority);
|
||||||
extern void SYS_MemLockAll(int LockAll);
|
extern void SYS_LockMemory(void);
|
||||||
|
|
||||||
#endif /* GOT_SYS_H */
|
#endif /* GOT_SYS_H */
|
||||||
|
|
|
@ -963,7 +963,9 @@ void SYS_Linux_SetScheduler(int SchedPriority)
|
||||||
int pmax, pmin;
|
int pmax, pmin;
|
||||||
struct sched_param sched;
|
struct sched_param sched;
|
||||||
|
|
||||||
if (SchedPriority > 0) {
|
if (SchedPriority < 1 || SchedPriority > 99) {
|
||||||
|
LOG_FATAL(LOGF_SysLinux, "Bad scheduler priority: %d", SchedPriority);
|
||||||
|
} else {
|
||||||
sched.sched_priority = SchedPriority;
|
sched.sched_priority = SchedPriority;
|
||||||
pmax = sched_get_priority_max(SCHED_FIFO);
|
pmax = sched_get_priority_max(SCHED_FIFO);
|
||||||
pmin = sched_get_priority_min(SCHED_FIFO);
|
pmin = sched_get_priority_min(SCHED_FIFO);
|
||||||
|
|
Loading…
Reference in a new issue