- Timestamp:
- Feb 21, 2025 11:33:59 AM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/output.c
r3662 r3664 61 61 62 62 #if defined(KMK) && defined(KBUILD_OS_WINDOWS) && 1 63 # define DEBUG_STDOUT_CLOSE_ISSUE 63 64 /* fflush wrapper w/ error checking + reporting for stdout. 64 65 This is to debug the mysterious 'kmk: write error: stdout' errors. */ 65 66 int g_fStdOutError = 0; 66 67 68 static void my_stdout_error (const char *pszOperation, const char *pszMessage) 69 { 70 DWORD const dwErr = GetLastError (); 71 int const iErrNo = errno; 72 int const fdFile = fileno(stdout); 73 HANDLE const hNative = (HANDLE)_get_osfhandle (_fileno (stdout)); 74 DWORD const dwType = GetFileType (hNative); 75 fprintf (stderr, "kmk: %s: %s! (lasterr=%u errno=%d fileno=%d native=%p type=%#x)\n", 76 pszOperation, pszMessage, dwErr, iErrNo, fdFile, hNative, dwType); 77 } 78 67 79 static int my_fflush (FILE *pFile) 68 80 { … … 72 84 { 73 85 int rcRet = fflush (pFile); 74 g_fStdOutError = ferror (g_fStdOutError);86 g_fStdOutError = ferror (pFile); 75 87 if (rcRet != EOF && !g_fStdOutError) 76 88 { /* likely */ } 77 89 else if (rcRet == EOF) 78 fprintf (stderr, "kmk: fflush(stdout): flush failed! errno=%d\n", errno);90 my_stdout_error ("fflush(stdout)", "flush failed!"); 79 91 else 80 fprintf (stderr, "kmk: fflush(stdout): error pending after successful flush! errno=%d\n", errno);92 my_stdout_error ("fflush(stdout)", "error pending after successful flush!"); 81 93 82 94 return rcRet; … … 84 96 else 85 97 { 86 fprintf (stderr, "kmk: fflush(stdout): error pending on entry! errno=%d\n", errno);98 my_stdout_error ("fflush(stdout)", "error pending on entry!"); 87 99 g_fStdOutError = 1; 88 100 } … … 93 105 94 106 # undef fflush 95 # undeffflush(a_pFile) my_fflush(a_pFile)107 # define fflush(a_pFile) my_fflush(a_pFile) 96 108 97 109 #endif … … 275 287 /* Exit the critical section. */ 276 288 # if defined (KBUILD_OS_WINDOWS) || defined (KBUILD_OS_OS2) || defined (KBUILD_OS_DOS) 277 _setmode (fileno (stdout), prev_mode_out); 278 _setmode (fileno (stderr), prev_mode_err); 289 if (prev_mode_out != -1) 290 _setmode (fileno (stdout), prev_mode_out); 291 if (prev_mode_err != -1) 292 _setmode (fileno (stderr), prev_mode_err); 279 293 # endif 280 294 if (sem) … … 571 585 while (len > 0) 572 586 { 573 const char *nl = memchr ( 587 const char *nl = memchr (src, '\n', len); 574 588 size_t line_len = nl ? nl - src : len; 575 589 output_write_bin (out, is_err, src, line_len); … … 980 994 } 981 995 982 #endif /* CONFIG_WITH_OUTPUT_IN_MEMORY */996 #endif /* !CONFIG_WITH_OUTPUT_IN_MEMORY */ 983 997 984 998 /* Synchronize the output of jobs in -j mode to keep the results of … … 1161 1175 { 1162 1176 int prev_fail = ferror (stdout); 1177 #ifdef DEBUG_STDOUT_CLOSE_ISSUE 1178 if (prev_fail) 1179 my_stdout_error ("close_stdout", "error pending on entry!"); 1180 errno = 0; SetLastError (0); 1181 #endif 1163 1182 int fclose_fail = fclose (stdout); 1164 1183 1165 1184 if (prev_fail || fclose_fail) 1166 1185 { 1186 #ifdef DEBUG_STDOUT_CLOSE_ISSUE 1187 if (fclose_fail) 1188 my_stdout_error ("close_stdout", "fclose failed!"); 1189 #endif 1167 1190 if (fclose_fail) 1168 1191 perror_with_name (_("write error: stdout"), ""); … … 1178 1201 output_init (struct output *out) 1179 1202 { 1203 #ifdef DEBUG_STDOUT_CLOSE_ISSUE 1204 if (STREAM_OK (stdout) && ferror (stdout)) 1205 my_stdout_error (out ? "output_init(out)" : "output_init(NULL)", "error pending entry!"); 1206 #endif 1207 1180 1208 if (out) 1181 1209 { … … 1220 1248 set_append_mode (fileno (stderr)); 1221 1249 1250 #ifdef DEBUG_STDOUT_CLOSE_ISSUE 1251 if (ferror (stdout)) 1252 my_stdout_error ("output_init", "error pending on exit!"); 1253 #endif 1222 1254 #ifdef HAVE_ATEXIT 1223 1255 if (STREAM_OK (stdout)) … … 1263 1295 if (output_context && output_context->syncout) 1264 1296 if (combined_output < 0) 1265 combined_output = sync_init (); 1297 { 1298 combined_output = 0; 1299 combined_output = sync_init (); 1300 } 1266 1301 #else 1267 1302 #ifndef NO_OUTPUT_SYNC
Note:
See TracChangeset
for help on using the changeset viewer.