when not running as root, get the username we run as
Costa Tsaousis (ktsaou) committed
Feb 26, 2017 at 02:09 UTC
e69f2f5b4dcc8630348ae359ebdb7673ddf9af33
1 file changed
+10
-1
src/main.c
+10
-1
@@ -513,6 +513,9 @@ void set_global_environment() {
513
514
// disable buffering for python plugins
515
setenv("PYTHONUNBUFFERED", "1", 1);
516
+
517
+ // switch to standard locale for plugins
518
+ setenv("LC_ALL", "C", 1);
519
}
520
521
int main(int argc, char **argv) {
@@ -851,7 +854,13 @@ int main(int argc, char **argv) {
854
// get the user we should run
855
856
// IMPORTANT: this is required before web_files_uid()
854
- user = config_get(CONFIG_SECTION_GLOBAL, "run as user" , (getuid() == 0)?NETDATA_USER:"");
857
+ if(getuid() == 0) {
858
+ user = config_get(CONFIG_SECTION_GLOBAL, "run as user", NETDATA_USER);
859
+ }
860
+ else {
861
+ struct passwd *passwd = getpwuid(getuid());
862
+ user = config_get(CONFIG_SECTION_GLOBAL, "run as user", (passwd && passwd->pw_name)?passwd->pw_name:"");
863
+ }
864
865
// IMPORTANT: these have to run once, while single threaded
866
web_files_uid(); // IMPORTANT: web_files_uid() before web_files_gid()