mirror of https://github.com/Icinga/icinga2.git
Merge pull request #6020 from Icinga/fix/console-home-env
Fix crash when running 'icinga2 console' without HOME environment variable
This commit is contained in:
commit
9cb7c9d7f7
|
@ -287,17 +287,22 @@ int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& add
|
||||||
int next_line = 1;
|
int next_line = 1;
|
||||||
|
|
||||||
#ifdef HAVE_EDITLINE
|
#ifdef HAVE_EDITLINE
|
||||||
String homeEnv = getenv("HOME");
|
char *homeEnv = getenv("HOME");
|
||||||
String historyPath = homeEnv + "/.icinga2_history";
|
|
||||||
|
|
||||||
|
String historyPath;
|
||||||
std::fstream historyfp;
|
std::fstream historyfp;
|
||||||
historyfp.open(historyPath.CStr(), std::fstream::in);
|
|
||||||
|
|
||||||
String line;
|
if (homeEnv) {
|
||||||
while (std::getline(historyfp, line.GetData()))
|
historyPath = String(homeEnv) + "/.icinga2_history";
|
||||||
add_history(line.CStr());
|
|
||||||
|
|
||||||
historyfp.close();
|
historyfp.open(historyPath.CStr(), std::fstream::in);
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while (std::getline(historyfp, line.GetData()))
|
||||||
|
add_history(line.CStr());
|
||||||
|
|
||||||
|
historyfp.close();
|
||||||
|
}
|
||||||
#endif /* HAVE_EDITLINE */
|
#endif /* HAVE_EDITLINE */
|
||||||
|
|
||||||
l_ScriptFrame = &scriptFrame;
|
l_ScriptFrame = &scriptFrame;
|
||||||
|
@ -370,9 +375,11 @@ incomplete:
|
||||||
if (commandOnce.IsEmpty() && cline[0] != '\0') {
|
if (commandOnce.IsEmpty() && cline[0] != '\0') {
|
||||||
add_history(cline);
|
add_history(cline);
|
||||||
|
|
||||||
historyfp.open(historyPath.CStr(), std::fstream::out | std::fstream::app);
|
if (!historyPath.IsEmpty()) {
|
||||||
historyfp << cline << "\n";
|
historyfp.open(historyPath.CStr(), std::fstream::out | std::fstream::app);
|
||||||
historyfp.close();
|
historyfp << cline << "\n";
|
||||||
|
historyfp.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
line = cline;
|
line = cline;
|
||||||
|
|
Loading…
Reference in New Issue