@@ -36,9 +36,16 @@ void RawWrite(const char *buffer) {
36
36
37
37
void ReportFile::ReopenIfNecessary () {
38
38
mu->CheckLocked ();
39
- if (fd == kStdoutFd || fd == kStderrFd ) return ;
39
+ if (!lastOpenFailed)
40
+ if (fd == kStdoutFd || fd == kStderrFd )
41
+ return ;
40
42
41
43
uptr pid = internal_getpid ();
44
+ if (lastOpenFailed && fd_pid != pid) {
45
+ fd = kInvalidFd ;
46
+ lastOpenFailed = false ;
47
+ }
48
+
42
49
// If in tracer, use the parent's file.
43
50
if (pid == stoptheworld_tracer_pid)
44
51
pid = stoptheworld_tracer_ppid;
@@ -48,8 +55,7 @@ void ReportFile::ReopenIfNecessary() {
48
55
// process, close it now.
49
56
if (fd_pid == pid)
50
57
return ;
51
- else
52
- CloseFile (fd);
58
+ CloseFile (fd);
53
59
}
54
60
55
61
const char *exe_name = GetProcessName ();
@@ -71,12 +77,17 @@ void ReportFile::ReopenIfNecessary() {
71
77
char errmsg[100 ];
72
78
internal_snprintf (errmsg, sizeof (errmsg), " (reason: %d)\n " , err);
73
79
WriteToFile (kStderrFd , errmsg, internal_strlen (errmsg));
74
- Die ();
80
+ if (!common_flags ()->log_fallback_to_stderr )
81
+ Die ();
82
+ const char *errmsg2 = " ERROR: Fallback to stderr\n " ;
83
+ WriteToFile (kStderrFd , errmsg2, internal_strlen (errmsg2));
84
+ lastOpenFailed = true ;
85
+ fd = kStderrFd ;
75
86
}
76
87
fd_pid = pid;
77
88
}
78
89
79
- static void RecursiveCreateParentDirs (char *path) {
90
+ static void RecursiveCreateParentDirs (char *path, fd_t &fd ) {
80
91
if (path[0 ] == ' \0 ' )
81
92
return ;
82
93
for (int i = 1 ; path[i] != ' \0 ' ; ++i) {
@@ -90,7 +101,13 @@ static void RecursiveCreateParentDirs(char *path) {
90
101
WriteToFile (kStderrFd , path, internal_strlen (path));
91
102
const char *ErrorMsgSuffix = " \n " ;
92
103
WriteToFile (kStderrFd , ErrorMsgSuffix, internal_strlen (ErrorMsgSuffix));
93
- Die ();
104
+ if (!common_flags ()->log_fallback_to_stderr )
105
+ Die ();
106
+ path[i] = save;
107
+ const char *ErrorMsgSuffix2 = " ERROR: Fallback to stderr\n " ;
108
+ WriteToFile (kStderrFd , ErrorMsgSuffix2, internal_strlen (ErrorMsgSuffix2));
109
+ fd = kStderrFd ;
110
+ return ;
94
111
}
95
112
path[i] = save;
96
113
}
@@ -166,7 +183,11 @@ void ReportFile::SetReportPath(const char *path) {
166
183
WriteToFile (kStderrFd , path, 8 );
167
184
message = " ...\n " ;
168
185
WriteToFile (kStderrFd , message, internal_strlen (message));
169
- Die ();
186
+ if (!common_flags ()->log_fallback_to_stderr )
187
+ Die ();
188
+ const char *message2 = " ERROR: Fallback to stderr\n " ;
189
+ WriteToFile (kStderrFd , message2, internal_strlen (message2));
190
+ path = " stderr" ;
170
191
}
171
192
}
172
193
@@ -180,7 +201,7 @@ void ReportFile::SetReportPath(const char *path) {
180
201
fd = kStdoutFd ;
181
202
} else {
182
203
ParseAndSetPath (path, path_prefix, kMaxPathLength );
183
- RecursiveCreateParentDirs (path_prefix);
204
+ RecursiveCreateParentDirs (path_prefix, fd );
184
205
}
185
206
}
186
207
0 commit comments