aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMidgard <M1dgard@users.noreply.github.com>2018-05-28 16:00:42 +0000
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-05-28 18:00:42 +0200
commit67ed56be3b5cc674ee9d42ccef409952b5e0c362 (patch)
tree079433769838619026836b972a553292ebeac86c /src
parenta78659ed0529226ad937f5e241ad72ba93702959 (diff)
downloadminetest-67ed56be3b5cc674ee9d42ccef409952b5e0c362.tar.gz
minetest-67ed56be3b5cc674ee9d42ccef409952b5e0c362.tar.bz2
minetest-67ed56be3b5cc674ee9d42ccef409952b5e0c362.zip
Print error when HOME is not set (#7376)
In some configurations, such as when using the runit supervisor and its tool chpst, the HOME variable might be unset. This resulted in an unclear error message that was hard to pin down.
Diffstat (limited to 'src')
-rw-r--r--src/porting.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/porting.cpp b/src/porting.cpp
index 1e3d610bc..240ee0af0 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -351,6 +351,21 @@ bool getCurrentExecPath(char *buf, size_t len)
#endif
+//// Non-Windows
+#if !defined(_WIN32)
+
+const char *getHomeOrFail()
+{
+ const char *home = getenv("HOME");
+ // In rare cases the HOME environment variable may be unset
+ FATAL_ERROR_IF(!home,
+ "Required environment variable HOME is not set");
+ return home;
+}
+
+#endif
+
+
//// Windows
#if defined(_WIN32)
@@ -430,7 +445,7 @@ bool setSystemPaths()
}
#ifndef __ANDROID__
- path_user = std::string(getenv("HOME")) + DIR_DELIM "."
+ path_user = std::string(getHomeOrFail()) + DIR_DELIM "."
+ PROJECT_NAME;
#endif
@@ -454,7 +469,7 @@ bool setSystemPaths()
}
CFRelease(resources_url);
- path_user = std::string(getenv("HOME"))
+ path_user = std::string(getHomeOrFail())
+ "/Library/Application Support/"
+ PROJECT_NAME;
return true;
@@ -466,7 +481,7 @@ bool setSystemPaths()
bool setSystemPaths()
{
path_share = STATIC_SHAREDIR;
- path_user = std::string(getenv("HOME")) + DIR_DELIM "."
+ path_user = std::string(getHomeOrFail()) + DIR_DELIM "."
+ lowercase(PROJECT_NAME);
return true;
}