-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed By: alexmalyshev Differential Revision: D56644394 fbshipit-source-id: bd2ebd296ddfa0b00a8f3ac9f85330282710a614
- Loading branch information
1 parent
53c58ac
commit 32c9c6c
Showing
2 changed files
with
38 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
/* Minimal main program -- everything is loaded from the library */ | ||
|
||
#include "Python.h" | ||
|
||
#ifdef MS_WINDOWS | ||
int | ||
wmain(int argc, wchar_t **argv) | ||
{ | ||
return Py_Main(argc, argv); | ||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdint.h> | ||
|
||
// In Meta's setup, ASAN_OPTIONS set in an environment variable are ignored. | ||
// However, we want to respect the log_path we set via cinder_test_runner.py | ||
// for use by sub-processes of individual tests. | ||
__attribute__((weak)) void __sanitizer_set_report_fd(void *); | ||
|
||
void open_asan_logfile(void) { | ||
if (__sanitizer_set_report_fd == NULL) { | ||
return; | ||
} | ||
|
||
char* asan_options = getenv("ASAN_OPTIONS"); | ||
if (asan_options == NULL) { | ||
return; | ||
} | ||
|
||
char* tokenptr = NULL; | ||
char* token = strtok_r(asan_options, ",", &tokenptr); | ||
const char* log_path_str = "log_path="; | ||
const int log_path_len = strlen(log_path_str); | ||
while (token != NULL) { | ||
if (strncmp(token, log_path_str, log_path_len) == 0) { | ||
char* filename = token + log_path_len; | ||
int fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0666); | ||
__sanitizer_set_report_fd((void*)(uintptr_t)fd); | ||
break; | ||
} | ||
token = strtok_r(NULL, ",", &tokenptr); | ||
} | ||
} | ||
#else | ||
int | ||
main(int argc, char **argv) | ||
{ | ||
|
||
int main(int argc, char **argv) { | ||
open_asan_logfile(); | ||
return Py_BytesMain(argc, argv); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters