Skip to content

Commit

Permalink
Fallback to /proc/self/exe if realpath(argv[0]) fails
Browse files Browse the repository at this point in the history
We use realpath() to identify the directory where the hdf5-udf file
was installed so we can tell where the UDF template files were put.
If the program name does not contain any elements to be resolved,
then realpath() does not do anything, though -- and we can't tell
where the template files are.

This commit uses /proc/self/exe as a fallback in case realpath on
argv[0] does not return the information we need.
  • Loading branch information
lucasvr committed Oct 7, 2020
1 parent 89266b5 commit 8755f94
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ std::string template_path(std::string backend_extension, std::string argv0)
{
char dirname_argv0[PATH_MAX], tmp[PATH_MAX];
memset(dirname_argv0, 0, sizeof(dirname_argv0));
if (! realpath(argv0.c_str(), dirname_argv0))
if (! realpath(argv0.c_str(), dirname_argv0) && ! realpath("/proc/self/exe", dirname_argv0))
{
fprintf(stderr, "Error resolving path %s: %s\n", argv0.c_str(), strerror(errno));
fprintf(stderr, "Error resolving path to '%s': %s\n", argv0.c_str(), strerror(errno));
return "";
}
char *sep = strrchr(dirname_argv0, '/');
Expand Down

0 comments on commit 8755f94

Please sign in to comment.