conf: replace empty strings with NULL
Avoid mixing empty strings with NULLs in configuration strings to make the handling of default or disabled values consistent.
This commit is contained in:
parent
e555548dda
commit
60049f1551
5 changed files with 21 additions and 25 deletions
2
cmdmon.c
2
cmdmon.c
|
@ -291,7 +291,7 @@ CAM_OpenUnixSocket(void)
|
||||||
{
|
{
|
||||||
/* This is separated from CAM_Initialise() as it needs to be called when
|
/* This is separated from CAM_Initialise() as it needs to be called when
|
||||||
the process has already dropped the root privileges */
|
the process has already dropped the root privileges */
|
||||||
if (CNF_GetBindCommandPath()[0])
|
if (CNF_GetBindCommandPath())
|
||||||
sock_fdu = open_socket(IPADDR_UNSPEC);
|
sock_fdu = open_socket(IPADDR_UNSPEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
conf.c
27
conf.c
|
@ -114,8 +114,8 @@ static int do_log_rtc = 0;
|
||||||
static int do_log_refclocks = 0;
|
static int do_log_refclocks = 0;
|
||||||
static int do_log_tempcomp = 0;
|
static int do_log_tempcomp = 0;
|
||||||
static int log_banner = 32;
|
static int log_banner = 32;
|
||||||
static char *logdir;
|
static char *logdir = NULL;
|
||||||
static char *dumpdir;
|
static char *dumpdir = NULL;
|
||||||
|
|
||||||
static int enable_local=0;
|
static int enable_local=0;
|
||||||
static int local_stratum;
|
static int local_stratum;
|
||||||
|
@ -190,14 +190,14 @@ static IPAddr bind_acq_address4, bind_acq_address6;
|
||||||
static IPAddr bind_cmd_address4, bind_cmd_address6;
|
static IPAddr bind_cmd_address4, bind_cmd_address6;
|
||||||
|
|
||||||
/* Path to the Unix domain command socket. */
|
/* Path to the Unix domain command socket. */
|
||||||
static char *bind_cmd_path;
|
static char *bind_cmd_path = NULL;
|
||||||
|
|
||||||
/* Path to Samba (ntp_signd) socket. */
|
/* Path to Samba (ntp_signd) socket. */
|
||||||
static char *ntp_signd_socket = NULL;
|
static char *ntp_signd_socket = NULL;
|
||||||
|
|
||||||
/* Filename to use for storing pid of running chronyd, to prevent multiple
|
/* Filename to use for storing pid of running chronyd, to prevent multiple
|
||||||
* chronyds being started. */
|
* chronyds being started. */
|
||||||
static char *pidfile;
|
static char *pidfile = NULL;
|
||||||
|
|
||||||
/* Rate limiting parameters */
|
/* Rate limiting parameters */
|
||||||
static int ntp_ratelimit_enabled = 0;
|
static int ntp_ratelimit_enabled = 0;
|
||||||
|
@ -370,16 +370,12 @@ CNF_Initialise(int r, int client_only)
|
||||||
ntp_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
ntp_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
||||||
cmd_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
cmd_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
||||||
|
|
||||||
dumpdir = Strdup("");
|
|
||||||
logdir = Strdup("");
|
|
||||||
rtc_device = Strdup(DEFAULT_RTC_DEVICE);
|
rtc_device = Strdup(DEFAULT_RTC_DEVICE);
|
||||||
hwclock_file = Strdup(DEFAULT_HWCLOCK_FILE);
|
hwclock_file = Strdup(DEFAULT_HWCLOCK_FILE);
|
||||||
user = Strdup(DEFAULT_USER);
|
user = Strdup(DEFAULT_USER);
|
||||||
|
|
||||||
if (client_only) {
|
if (client_only) {
|
||||||
cmd_port = ntp_port = 0;
|
cmd_port = ntp_port = 0;
|
||||||
bind_cmd_path = Strdup("");
|
|
||||||
pidfile = Strdup("");
|
|
||||||
} else {
|
} else {
|
||||||
bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
|
bind_cmd_path = Strdup(DEFAULT_COMMAND_SOCKET);
|
||||||
pidfile = Strdup(DEFAULT_PID_FILE);
|
pidfile = Strdup(DEFAULT_PID_FILE);
|
||||||
|
@ -1233,8 +1229,10 @@ parse_bindcmdaddress(char *line)
|
||||||
if (line[0] == '/') {
|
if (line[0] == '/') {
|
||||||
parse_string(line, &bind_cmd_path);
|
parse_string(line, &bind_cmd_path);
|
||||||
/* / disables the socket */
|
/* / disables the socket */
|
||||||
if (!strcmp(bind_cmd_path, "/"))
|
if (strcmp(bind_cmd_path, "/") == 0) {
|
||||||
bind_cmd_path[0] = '\0';
|
Free(bind_cmd_path);
|
||||||
|
bind_cmd_path = NULL;
|
||||||
|
}
|
||||||
} else if (UTI_StringToIP(line, &ip)) {
|
} else if (UTI_StringToIP(line, &ip)) {
|
||||||
if (ip.family == IPADDR_INET4)
|
if (ip.family == IPADDR_INET4)
|
||||||
bind_cmd_address4 = ip;
|
bind_cmd_address4 = ip;
|
||||||
|
@ -1537,7 +1535,7 @@ CNF_CreateDirs(uid_t uid, gid_t gid)
|
||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
/* Create a directory for the Unix domain command socket */
|
/* Create a directory for the Unix domain command socket */
|
||||||
if (bind_cmd_path[0]) {
|
if (bind_cmd_path) {
|
||||||
dir = UTI_PathToDir(bind_cmd_path);
|
dir = UTI_PathToDir(bind_cmd_path);
|
||||||
UTI_CreateDirAndParents(dir, 0770, uid, gid);
|
UTI_CreateDirAndParents(dir, 0770, uid, gid);
|
||||||
|
|
||||||
|
@ -1546,15 +1544,16 @@ CNF_CreateDirs(uid_t uid, gid_t gid)
|
||||||
domain sockets are ignored on some systems (e.g. Solaris). */
|
domain sockets are ignored on some systems (e.g. Solaris). */
|
||||||
if (!UTI_CheckDirPermissions(dir, 0770, uid, gid)) {
|
if (!UTI_CheckDirPermissions(dir, 0770, uid, gid)) {
|
||||||
LOG(LOGS_WARN, "Disabled command socket %s", bind_cmd_path);
|
LOG(LOGS_WARN, "Disabled command socket %s", bind_cmd_path);
|
||||||
bind_cmd_path[0] = '\0';
|
Free(bind_cmd_path);
|
||||||
|
bind_cmd_path = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Free(dir);
|
Free(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logdir[0])
|
if (logdir)
|
||||||
UTI_CreateDirAndParents(logdir, 0755, uid, gid);
|
UTI_CreateDirAndParents(logdir, 0755, uid, gid);
|
||||||
if (dumpdir[0])
|
if (dumpdir)
|
||||||
UTI_CreateDirAndParents(dumpdir, 0755, uid, gid);
|
UTI_CreateDirAndParents(dumpdir, 0755, uid, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -267,7 +267,7 @@ LOG_FileWrite(LOG_FileID id, const char *format, ...)
|
||||||
if (!logfiles[id].file) {
|
if (!logfiles[id].file) {
|
||||||
char *logdir = CNF_GetLogDir();
|
char *logdir = CNF_GetLogDir();
|
||||||
|
|
||||||
if (logdir[0] == '\0') {
|
if (!logdir) {
|
||||||
LOG(LOGS_WARN, "logdir not specified");
|
LOG(LOGS_WARN, "logdir not specified");
|
||||||
logfiles[id].name = NULL;
|
logfiles[id].name = NULL;
|
||||||
return;
|
return;
|
||||||
|
|
10
main.c
10
main.c
|
@ -91,7 +91,7 @@ delete_pidfile(void)
|
||||||
{
|
{
|
||||||
const char *pidfile = CNF_GetPidFile();
|
const char *pidfile = CNF_GetPidFile();
|
||||||
|
|
||||||
if (!pidfile[0])
|
if (!pidfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!UTI_RemoveFile(NULL, pidfile, NULL))
|
if (!UTI_RemoveFile(NULL, pidfile, NULL))
|
||||||
|
@ -105,9 +105,7 @@ MAI_CleanupAndExit(void)
|
||||||
{
|
{
|
||||||
if (!initialised) exit(exit_status);
|
if (!initialised) exit(exit_status);
|
||||||
|
|
||||||
if (CNF_GetDumpDir()[0] != '\0') {
|
SRC_DumpSources();
|
||||||
SRC_DumpSources();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't update clock when removing sources */
|
/* Don't update clock when removing sources */
|
||||||
REF_SetMode(REF_ModeIgnore);
|
REF_SetMode(REF_ModeIgnore);
|
||||||
|
@ -261,7 +259,7 @@ check_pidfile(void)
|
||||||
FILE *in;
|
FILE *in;
|
||||||
int pid, count;
|
int pid, count;
|
||||||
|
|
||||||
if (!pidfile[0])
|
if (!pidfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
in = UTI_OpenFile(NULL, pidfile, NULL, 'r', 0);
|
in = UTI_OpenFile(NULL, pidfile, NULL, 'r', 0);
|
||||||
|
@ -289,7 +287,7 @@ write_pidfile(void)
|
||||||
const char *pidfile = CNF_GetPidFile();
|
const char *pidfile = CNF_GetPidFile();
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
|
||||||
if (!pidfile[0])
|
if (!pidfile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
out = UTI_OpenFile(NULL, pidfile, NULL, 'W', 0644);
|
out = UTI_OpenFile(NULL, pidfile, NULL, 'W', 0644);
|
||||||
|
|
|
@ -1284,9 +1284,8 @@ FILE *open_dumpfile(SRC_Instance inst, char mode)
|
||||||
char filename[64], *dumpdir;
|
char filename[64], *dumpdir;
|
||||||
|
|
||||||
dumpdir = CNF_GetDumpDir();
|
dumpdir = CNF_GetDumpDir();
|
||||||
if (dumpdir[0] == '\0') {
|
if (!dumpdir)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* Include IP address in the name for NTP sources, or reference ID in hex */
|
/* Include IP address in the name for NTP sources, or reference ID in hex */
|
||||||
if (inst->type == SRC_NTP && UTI_IsIPReal(inst->ip_addr))
|
if (inst->type == SRC_NTP && UTI_IsIPReal(inst->ip_addr))
|
||||||
|
@ -1350,7 +1349,7 @@ SRC_RemoveDumpFiles(void)
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
dumpdir = CNF_GetDumpDir();
|
dumpdir = CNF_GetDumpDir();
|
||||||
if (dumpdir[0] == '\0' ||
|
if (!dumpdir ||
|
||||||
snprintf(pattern, sizeof (pattern), "%s/*.dat", dumpdir) >= sizeof (pattern))
|
snprintf(pattern, sizeof (pattern), "%s/*.dat", dumpdir) >= sizeof (pattern))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue