pty: fallback to ~ or / when creating new term if current dir is not available

Closes T5186
This commit is contained in:
Boris Faure 2017-02-17 21:57:57 +01:00
parent 74c1ceffd8
commit e188244c72
1 changed files with 22 additions and 2 deletions

View File

@ -575,14 +575,34 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
if (!ty->pid)
{
char buf[256];
int ret;
if (cd)
{
if (chdir(cd) != 0)
ret = chdir(cd);
if (ret != 0)
{
ERR(_("Could not change current directory to '%s': %s"),
cd, strerror(errno));
exit(127);
cd = getenv("HOME");
if (cd)
{
ret = chdir(cd);
if (ret != 0)
{
ERR(_("Could not change current directory to '%s': %s"),
cd, strerror(errno));
}
}
if (ret != 0)
{
cd = "/";
if (chdir(cd) != 0)
{
ERR(_("Could not change current directory to '%s': %s"),
cd, strerror(errno));
}
}
}
}