Skip to content

Commit 8755f94

Browse files
committed
Fallback to /proc/self/exe if realpath(argv[0]) fails
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.
1 parent 89266b5 commit 8755f94

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ std::string template_path(std::string backend_extension, std::string argv0)
128128
{
129129
char dirname_argv0[PATH_MAX], tmp[PATH_MAX];
130130
memset(dirname_argv0, 0, sizeof(dirname_argv0));
131-
if (! realpath(argv0.c_str(), dirname_argv0))
131+
if (! realpath(argv0.c_str(), dirname_argv0) && ! realpath("/proc/self/exe", dirname_argv0))
132132
{
133-
fprintf(stderr, "Error resolving path %s: %s\n", argv0.c_str(), strerror(errno));
133+
fprintf(stderr, "Error resolving path to '%s': %s\n", argv0.c_str(), strerror(errno));
134134
return "";
135135
}
136136
char *sep = strrchr(dirname_argv0, '/');

0 commit comments

Comments
 (0)