Skip to content

Commit

Permalink
[Support] Implement getMainExecutable for OpenBSD
Browse files Browse the repository at this point in the history
This uses just argv[0] on OpenBSD. OpenBSD does not support the /proc filesystem.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159168
  • Loading branch information
brad0 committed Sep 1, 2023
1 parent b14e83d commit 69d79f1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions llvm/lib/Support/Unix/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
// Fall back to argv[0] if auxiliary vectors are not available.
if (getprogpath(exe_path, argv0) != NULL)
return exe_path;
#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || \
defined(__FreeBSD_kernel__) || defined(_AIX)
#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) || \
defined(__NetBSD__)
const char *curproc = "/proc/curproc/file";
char exe_path[PATH_MAX];
if (sys::fs::exists(curproc)) {
Expand Down Expand Up @@ -283,6 +283,11 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
// Fall back to the classical detection.
if (getprogpath(exe_path, argv0))
return exe_path;
#elif defined(__OpenBSD__)
char exe_path[PATH_MAX];
// argv[0] only
if (getprogpath(exe_path, argv0) != NULL)
return exe_path;
#elif defined(__sun__) && defined(__svr4__)
char exe_path[PATH_MAX];
const char *aPath = "/proc/self/execname";
Expand Down Expand Up @@ -951,7 +956,7 @@ ErrorOr<basic_file_status> directory_entry::status() const {
// FreeBSD optionally provides /proc/self/fd, but it is incompatible with
// Linux. The thing to use is realpath.
//
#if !defined(__FreeBSD__)
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
#define TRY_PROC_SELF_FD
#endif

Expand Down

0 comments on commit 69d79f1

Please sign in to comment.