Fixed system toolkit: use $HOME for location of settings. Compilation

warning fixed.
This commit is contained in:
brunoherbelin
2020-08-02 11:25:28 +02:00
parent 96d71387dc
commit ed596f0ba5

View File

@@ -51,10 +51,12 @@ long SystemToolkit::memory_usage()
FILE *file = fopen("/proc/self/statm", "r"); FILE *file = fopen("/proc/self/statm", "r");
if (file) { if (file) {
unsigned long m = 0; unsigned long m = 0;
fscanf (file, "%lu", &m); // virtual mem program size, int ret = 0;
fscanf (file, "%lu", &m); // resident set size, ret = fscanf (file, "%lu", &m); // virtual mem program size,
ret = fscanf (file, "%lu", &m); // resident set size,
fclose (file); fclose (file);
size = (size_t)m * getpagesize(); if (ret>0)
size = (size_t)m * getpagesize();
} }
return (long)size; return (long)size;
@@ -167,17 +169,14 @@ std::string SystemToolkit::home_path()
{ {
// 1. find home // 1. find home
char *mHomePath; char *mHomePath;
// try the system user info
// try the environment variable // NB: avoids depending on changes of the $HOME env. variable
mHomePath = getenv("HOME"); struct passwd* pwd = getpwuid(getuid());
if (pwd)
if (!mHomePath) { mHomePath = pwd->pw_dir;
// try the system user info else
struct passwd* pwd = getpwuid(getuid()); // try the $HOME environment variable
if (pwd) mHomePath = getenv("HOME");
mHomePath = pwd->pw_dir;
}
return string(mHomePath) + PATH_SEP; return string(mHomePath) + PATH_SEP;
} }
@@ -217,13 +216,16 @@ bool SystemToolkit::create_directory(const string& path)
string SystemToolkit::settings_path() string SystemToolkit::settings_path()
{ {
string home(home_path()); // start from home folder
// NB: use the env.variable $HOME to allow system to specify
// another directory (e.g. inside a snap)
string home(getenv("HOME"));
// 2. try to access user settings folder // 2. try to access user settings folder
string settingspath = home + PATH_SETTINGS; string settingspath = home + PATH_SETTINGS;
if (SystemToolkit::file_exists(settingspath)) { if (SystemToolkit::file_exists(settingspath)) {
// good, we have a place to put the settings file // good, we have a place to put the settings file
// settings should be in 'vmix' subfolder // settings should be in 'vimix' subfolder
settingspath += APP_NAME; settingspath += APP_NAME;
// 3. create the vmix subfolder in settings folder if not existing already // 3. create the vmix subfolder in settings folder if not existing already