diff options
author | Cole Helbling <cole.e.helbling@outlook.com> | 2022-04-01 12:20:34 -0700 |
---|---|---|
committer | Cole Helbling <cole.e.helbling@outlook.com> | 2022-04-01 12:20:34 -0700 |
commit | 2a45cf54e4201a894254604676dcb51f4c1a471c (patch) | |
tree | d0ac5e0eb1388e42375b0d3570d682c7744b3410 /src | |
parent | 7f5caaa7c0f151520d05d4662415ac09d4cf34b0 (diff) |
libutil: Properly guard self-allocating getcwd on GNU
It's a GNU extension, as pointed out by pennae.
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/util.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 0b18f1027..28ab77adc 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1698,10 +1698,19 @@ void saveMountNamespace() #if __linux__ static std::once_flag done; std::call_once(done, []() { - char* cwd = getcwd(NULL, 0); - if (cwd == NULL) throw SysError("getting cwd"); +#ifdef __GNU__ + // getcwd allocating its return value is a GNU extension. + char *cwd = getcwd(NULL, 0); + if (cwd == NULL) +#else + char cwd[PATH_MAX]; + if (!getcwd(cwd, sizeof(cwd))) +#endif + throw SysError("getting cwd"); savedCwd.emplace(cwd); +#ifdef __GNU__ free(cwd); +#endif AutoCloseFD fd = open("/proc/self/ns/mnt", O_RDONLY); if (!fd) |