mirror of
https://github.com/netdata/netdata.git
synced 2025-04-26 22:04:46 +00:00
set "HOME" after switching to netdata user (#16548)
This commit is contained in:
parent
35403d6c55
commit
9fdf1c96e4
3 changed files with 11 additions and 3 deletions
|
@ -842,7 +842,6 @@ void set_global_environment() {
|
|||
setenv("NETDATA_LIB_DIR", verify_or_create_required_directory(netdata_configured_varlib_dir), 1);
|
||||
setenv("NETDATA_LOCK_DIR", verify_or_create_required_directory(netdata_configured_lock_dir), 1);
|
||||
setenv("NETDATA_LOG_DIR", verify_or_create_required_directory(netdata_configured_log_dir), 1);
|
||||
setenv("HOME", verify_or_create_required_directory(netdata_configured_home_dir), 1);
|
||||
setenv("NETDATA_HOST_PREFIX", netdata_configured_host_prefix, 1);
|
||||
|
||||
{
|
||||
|
|
|
@ -1167,8 +1167,6 @@ static void get_netdata_configured_variables() {
|
|||
netdata_configured_web_dir = config_get(CONFIG_SECTION_DIRECTORIES, "web", netdata_configured_web_dir);
|
||||
netdata_configured_cache_dir = config_get(CONFIG_SECTION_DIRECTORIES, "cache", netdata_configured_cache_dir);
|
||||
netdata_configured_varlib_dir = config_get(CONFIG_SECTION_DIRECTORIES, "lib", netdata_configured_varlib_dir);
|
||||
char *env_home=getenv("HOME");
|
||||
netdata_configured_home_dir = config_get(CONFIG_SECTION_DIRECTORIES, "home", env_home?env_home:netdata_configured_home_dir);
|
||||
|
||||
netdata_configured_lock_dir = initialize_lock_directory_path(netdata_configured_varlib_dir);
|
||||
|
||||
|
@ -2080,6 +2078,16 @@ int main(int argc, char **argv) {
|
|||
if(become_daemon(dont_fork, user) == -1)
|
||||
fatal("Cannot daemonize myself.");
|
||||
|
||||
// The "HOME" env var points to the root's home dir because Netdata starts as root. Can't use "HOME".
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
if (config_exists(CONFIG_SECTION_DIRECTORIES, "home") || !pw || !pw->pw_dir) {
|
||||
netdata_configured_home_dir = config_get(CONFIG_SECTION_DIRECTORIES, "home", netdata_configured_home_dir);
|
||||
} else {
|
||||
netdata_configured_home_dir = config_get(CONFIG_SECTION_DIRECTORIES, "home", pw->pw_dir);
|
||||
}
|
||||
|
||||
setenv("HOME", netdata_configured_home_dir, 1);
|
||||
|
||||
dyn_conf_init();
|
||||
|
||||
netdata_log_info("netdata started on pid %d.", getpid());
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
|
||||
CLEANFILES = \
|
||||
install-service.sh \
|
||||
cron/netdata-updater-daily \
|
||||
freebsd/rc.d/netdata \
|
||||
initd/init.d/netdata \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue