-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Omnibus to get a clean OpenBSD build. #3003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
808e89e
1bcf2e3
5d90405
56e5046
3aa51bd
c86c025
2271829
a515417
1f0a55f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,12 @@ static inline void _CFSetProgramNameFromPath(const char *path) { | |
__CFprogname = (__CFprogname ? __CFprogname + 1 : __CFProcessPath); | ||
} | ||
|
||
#if TARGET_OS_BSD && defined(__OpenBSD__) | ||
#include <sys/types.h> | ||
#include <sys/sysctl.h> | ||
#include <sys/exec.h> | ||
#endif | ||
|
||
const char *_CFProcessPath(void) { | ||
if (__CFProcessPath) return __CFProcessPath; | ||
|
||
|
@@ -175,6 +181,53 @@ const char *_CFProcessPath(void) { | |
} | ||
return __CFProcessPath; | ||
#else // TARGET_OS_BSD | ||
char *argv0 = NULL; | ||
|
||
// Get argv[0]. | ||
#if defined(__OpenBSD__) | ||
int mib[2] = {CTL_VM, VM_PSSTRINGS}; | ||
struct _ps_strings _ps; | ||
size_t len = sizeof(_ps); | ||
|
||
if (sysctl(mib, 2, &_ps, &len, NULL, 0) != -1) { | ||
struct ps_strings *ps = _ps.val; | ||
char *res = realpath(ps->ps_argvstr[0], NULL); | ||
argv0 = res? res: strdup(ps->ps_argvstr[0]); | ||
} | ||
#endif | ||
|
||
if (!__CFProcessIsRestricted() && argv0 && argv0[0] == '/') { | ||
_CFSetProgramNameFromPath(argv0); | ||
free(argv0); | ||
return __CFProcessPath; | ||
} | ||
|
||
// Search PATH. | ||
if (argv0) { | ||
char *paths = getenv("PATH"); | ||
char *p = NULL; | ||
while ((p = strsep(&paths, ":")) != NULL) { | ||
char pp[PATH_MAX]; | ||
int l = snprintf(pp, PATH_MAX, "%s/%s", p, argv0); | ||
if (l >= PATH_MAX) { | ||
continue; | ||
} | ||
char *res = realpath(pp, NULL); | ||
if (!res) { | ||
continue; | ||
} | ||
if (!__CFProcessIsRestricted() && access(res, X_OK) == 0) { | ||
_CFSetProgramNameFromPath(res); | ||
free(argv0); | ||
free(res); | ||
return __CFProcessPath; | ||
} | ||
free(res); | ||
} | ||
free(argv0); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this have issues if the executable was specified using a relative path ,eg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that would not work if the realpath call failed and we fell back to argv[0]. We can call realpath a second time to ensure we get an absolute path. Added missing free calls as well. |
||
// See if the shell will help. | ||
if (!__CFProcessIsRestricted()) { | ||
char *path = getenv("_"); | ||
if (path != NULL) { | ||
|
@@ -1574,6 +1627,9 @@ CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(_CFThreadRef thread, const char *_ | |
return 0; | ||
#elif TARGET_OS_LINUX | ||
return pthread_setname_np(thread, name); | ||
#elif TARGET_OS_BSD | ||
pthread_set_name_np(thread, name); | ||
return 0; | ||
#endif | ||
} | ||
|
||
|
@@ -1593,6 +1649,9 @@ CF_CROSS_PLATFORM_EXPORT int _CFThreadGetName(char *buf, int length) { | |
return 0; | ||
#elif TARGET_OS_LINUX | ||
return pthread_getname_np(pthread_self(), buf, length); | ||
#elif TARGET_OS_BSD | ||
pthread_get_name_np(pthread_self(), buf, length); | ||
return 0; | ||
#elif TARGET_OS_WIN32 | ||
*buf = '\0'; | ||
|
||
|
@@ -1630,6 +1689,9 @@ CF_EXPORT char **_CFEnviron(void) { | |
#elif TARGET_OS_WIN32 | ||
return _environ; | ||
#else | ||
#if TARGET_OS_BSD | ||
extern char **environ; | ||
#endif | ||
return environ; | ||
#endif | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just tidy up the formatting in this
if
block so its all consistent at 4 space indent, thanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops -- sorry about that. Fixed.