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_linux_hz(const char *);
|
||||
static void parse_linux_freq_scale(const char *);
|
||||
|
||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||
static void parse_sched_priority(const char *);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MLOCKALL)
|
||||
static void parse_lockall(const char *);
|
||||
#endif
|
||||
|
||||
/* ================================================== */
|
||||
/* Configuration variables */
|
||||
|
@ -184,6 +178,9 @@ static int linux_hz;
|
|||
static int set_linux_freq_scale = 0;
|
||||
static double linux_freq_scale;
|
||||
|
||||
static int sched_priority = 0;
|
||||
static int lock_memory = 0;
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
typedef struct {
|
||||
|
@ -226,15 +223,9 @@ static const Command commands[] = {
|
|||
{"pidfile", 7, parse_pidfile},
|
||||
{"broadcast", 9, parse_broadcast},
|
||||
{"linux_hz", 8, parse_linux_hz},
|
||||
{"linux_freq_scale", 16, parse_linux_freq_scale}
|
||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||
,{"sched_priority", 14, parse_sched_priority}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MLOCKALL)
|
||||
,{"lock_all", 8, parse_lockall}
|
||||
#endif
|
||||
|
||||
{"linux_freq_scale", 16, parse_linux_freq_scale},
|
||||
{"sched_priority", 14, parse_sched_priority},
|
||||
{"lock_all", 8, parse_lockall}
|
||||
};
|
||||
|
||||
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
|
||||
parse_sched_priority(const char *line)
|
||||
{
|
||||
if (SchedPriority == 0) { /* Command-line switch must have priority */
|
||||
sscanf(line, "%d", &SchedPriority);
|
||||
if (sscanf(line, "%d", &sched_priority) != 1) {
|
||||
LOG(LOGS_WARN, LOGF_Configure, "Could not read scheduling priority at line %d", line_number);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MLOCKALL)
|
||||
/* ================================================== */
|
||||
|
||||
static void
|
||||
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 ;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
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);
|
||||
|
||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||
extern int SchedPriority;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MLOCKALL)
|
||||
extern int LockAll;
|
||||
#endif
|
||||
extern int CNF_GetSchedPriority(void);
|
||||
extern int CNF_GetLockMemory(void);
|
||||
|
||||
#endif /* GOT_CONF_H */
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef enum {
|
|||
LOGF_Logging,
|
||||
LOGF_Rtc,
|
||||
LOGF_Regress,
|
||||
LOGF_Sys,
|
||||
LOGF_SysLinux,
|
||||
LOGF_SysSolaris,
|
||||
LOGF_SysSunOS,
|
||||
|
|
41
main.c
41
main.c
|
@ -216,10 +216,7 @@ int main
|
|||
int debug = 0;
|
||||
int do_init_rtc = 0;
|
||||
int other_pid;
|
||||
|
||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||
int return_value = 0;
|
||||
#endif
|
||||
int lock_memory = 0, sched_priority = 0;
|
||||
|
||||
LOG_Initialise();
|
||||
|
||||
|
@ -229,29 +226,22 @@ int main
|
|||
if (!strcmp("-f", *argv)) {
|
||||
++argv, --argc;
|
||||
conf_file = *argv;
|
||||
|
||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||
/* Get real-time scheduler priority */
|
||||
} else if (!strcmp("-P", *argv)) {
|
||||
++argv, --argc;
|
||||
return_value = sscanf(*argv, "%d", &SchedPriority);
|
||||
if (return_value != 1 || SchedPriority < 1 || SchedPriority > 99) {
|
||||
SchedPriority = 0;
|
||||
LOG(LOGS_WARN, LOGF_Main, "Bad scheduler priority: [%s]", *argv);
|
||||
if (argc == 0 || sscanf(*argv, "%d", &sched_priority) != 1) {
|
||||
LOG_FATAL(LOGF_Main, "Bad scheduler priority");
|
||||
}
|
||||
#endif /* HAVE_SCHED_SETCHEDULER */
|
||||
|
||||
#if defined(HAVE_MLOCKALL)
|
||||
/* Detect lockall switch */
|
||||
} else if (!strcmp("-m", *argv)) {
|
||||
LockAll = 1;
|
||||
#endif /* HAVE_MLOCKALL */
|
||||
|
||||
lock_memory = 1;
|
||||
} else if (!strcmp("-r", *argv)) {
|
||||
reload = 1;
|
||||
} else if (!strcmp("-u", *argv)) {
|
||||
++argv, --argc;
|
||||
if (argc == 0) {
|
||||
LOG_FATAL(LOGF_Main, "Missing user name");
|
||||
} else {
|
||||
user = *argv;
|
||||
}
|
||||
} else if (!strcmp("-s", *argv)) {
|
||||
do_init_rtc = 1;
|
||||
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
||||
|
@ -310,16 +300,21 @@ int main
|
|||
RTC_Initialise();
|
||||
RCL_Initialise();
|
||||
|
||||
if (SchedPriority > 0) {
|
||||
SYS_SetScheduler(SchedPriority);
|
||||
/* Command-line switch must have priority */
|
||||
if (!sched_priority) {
|
||||
sched_priority = CNF_GetSchedPriority();
|
||||
}
|
||||
if (sched_priority) {
|
||||
SYS_SetScheduler(sched_priority);
|
||||
}
|
||||
|
||||
if (LockAll == 1 ) {
|
||||
SYS_MemLockAll(LockAll);
|
||||
if (lock_memory || CNF_GetLockMemory()) {
|
||||
SYS_LockMemory();
|
||||
}
|
||||
|
||||
if (user)
|
||||
if (user) {
|
||||
SYS_DropRoot(user);
|
||||
}
|
||||
|
||||
REF_Initialise();
|
||||
SST_Initialise();
|
||||
|
|
26
sys.c
26
sys.c
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
|
||||
#include "sys.h"
|
||||
#include "logging.h"
|
||||
|
||||
#if defined (LINUX)
|
||||
#include "sys_linux.h"
|
||||
|
@ -102,7 +103,11 @@ void SYS_DropRoot(char *user)
|
|||
{
|
||||
#if defined(LINUX) && defined (FEAT_LINUXCAPS)
|
||||
SYS_Linux_DropRoot(user);
|
||||
#else
|
||||
LOG_FATAL(LOGF_Sys, "dropping root privileges not supported");
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
@ -111,19 +116,24 @@ void SYS_SetScheduler(int SchedPriority)
|
|||
{
|
||||
#if defined(LINUX) && defined(HAVE_SCHED_SETSCHEDULER)
|
||||
SYS_Linux_SetScheduler(SchedPriority);
|
||||
#else
|
||||
LOG_FATAL(LOGF_Sys, "scheduler priority setting not supported");
|
||||
#endif
|
||||
;;
|
||||
}
|
||||
|
||||
void SYS_MemLockAll(int LockAll)
|
||||
{
|
||||
#if defined(LINUX) && defined(HAVE_MLOCKALL)
|
||||
SYS_Linux_MemLockAll(LockAll);
|
||||
#endif
|
||||
;;
|
||||
return;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
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_SetScheduler(int SchedPriority);
|
||||
extern void SYS_MemLockAll(int LockAll);
|
||||
extern void SYS_LockMemory(void);
|
||||
|
||||
#endif /* GOT_SYS_H */
|
||||
|
|
|
@ -963,7 +963,9 @@ void SYS_Linux_SetScheduler(int SchedPriority)
|
|||
int pmax, pmin;
|
||||
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;
|
||||
pmax = sched_get_priority_max(SCHED_FIFO);
|
||||
pmin = sched_get_priority_min(SCHED_FIFO);
|
||||
|
|
Loading…
Reference in a new issue