main: create directories before refclock initialization

This allows the SOCK refclock to open sockets in the /var/run/chrony
directory.
This commit is contained in:
Miroslav Lichvar 2018-02-16 10:36:41 +01:00
parent 0ce15a8472
commit c5d8af0285

20
main.c
View file

@ -524,6 +524,16 @@ int main
/* Write our pidfile to prevent other chronyds running */ /* Write our pidfile to prevent other chronyds running */
write_pidfile(); write_pidfile();
if (!user)
user = CNF_GetUser();
pw = getpwnam(user);
if (!pw)
LOG_FATAL("Could not get user/group ID of %s", user);
/* Create directories for sockets, log files, and dump files */
CNF_CreateDirs(pw->pw_uid, pw->pw_gid);
PRV_Initialise(); PRV_Initialise();
LCL_Initialise(); LCL_Initialise();
SCH_Initialise(); SCH_Initialise();
@ -551,16 +561,6 @@ int main
SYS_LockMemory(); SYS_LockMemory();
} }
if (!user) {
user = CNF_GetUser();
}
if ((pw = getpwnam(user)) == NULL)
LOG_FATAL("Could not get user/group ID of %s", user);
/* Create all directories before dropping root */
CNF_CreateDirs(pw->pw_uid, pw->pw_gid);
/* Drop root privileges if the specified user has a non-zero UID */ /* Drop root privileges if the specified user has a non-zero UID */
if (!geteuid() && (pw->pw_uid || pw->pw_gid)) if (!geteuid() && (pw->pw_uid || pw->pw_gid))
SYS_DropRoot(pw->pw_uid, pw->pw_gid); SYS_DropRoot(pw->pw_uid, pw->pw_gid);