Skip to content

Commit 67ed56b

Browse files
M1dgardnerzhul
authored andcommittedMay 28, 2018
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.
1 parent a78659e commit 67ed56b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed
 

‎src/porting.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,21 @@ bool getCurrentExecPath(char *buf, size_t len)
351351
#endif
352352

353353

354+
//// Non-Windows
355+
#if !defined(_WIN32)
356+
357+
const char *getHomeOrFail()
358+
{
359+
const char *home = getenv("HOME");
360+
// In rare cases the HOME environment variable may be unset
361+
FATAL_ERROR_IF(!home,
362+
"Required environment variable HOME is not set");
363+
return home;
364+
}
365+
366+
#endif
367+
368+
354369
//// Windows
355370
#if defined(_WIN32)
356371

@@ -430,7 +445,7 @@ bool setSystemPaths()
430445
}
431446

432447
#ifndef __ANDROID__
433-
path_user = std::string(getenv("HOME")) + DIR_DELIM "."
448+
path_user = std::string(getHomeOrFail()) + DIR_DELIM "."
434449
+ PROJECT_NAME;
435450
#endif
436451

@@ -454,7 +469,7 @@ bool setSystemPaths()
454469
}
455470
CFRelease(resources_url);
456471

457-
path_user = std::string(getenv("HOME"))
472+
path_user = std::string(getHomeOrFail())
458473
+ "/Library/Application Support/"
459474
+ PROJECT_NAME;
460475
return true;
@@ -466,7 +481,7 @@ bool setSystemPaths()
466481
bool setSystemPaths()
467482
{
468483
path_share = STATIC_SHAREDIR;
469-
path_user = std::string(getenv("HOME")) + DIR_DELIM "."
484+
path_user = std::string(getHomeOrFail()) + DIR_DELIM "."
470485
+ lowercase(PROJECT_NAME);
471486
return true;
472487
}

0 commit comments

Comments
 (0)
Please sign in to comment.