VirtualBox

Changeset 3664 in kBuild for trunk


Ignore:
Timestamp:
Feb 21, 2025 11:33:59 AM (2 months ago)
Author:
bird
Message:

kmk/output.c: More debugging code for the mysterious 'kmk: write error: stdout' problem...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/output.c

    r3662 r3664  
    6161
    6262#if defined(KMK) && defined(KBUILD_OS_WINDOWS) && 1
     63# define DEBUG_STDOUT_CLOSE_ISSUE
    6364/* fflush wrapper w/ error checking + reporting for stdout.
    6465   This is to debug the mysterious 'kmk: write error: stdout' errors. */
    6566int g_fStdOutError = 0;
    6667
     68static 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
    6779static int my_fflush (FILE *pFile)
    6880{
     
    7284        {
    7385          int rcRet = fflush (pFile);
    74           g_fStdOutError = ferror(g_fStdOutError);
     86          g_fStdOutError = ferror (pFile);
    7587          if (rcRet != EOF && !g_fStdOutError)
    7688            { /* likely */ }
    7789          else if (rcRet == EOF)
    78             fprintf (stderr, "kmk: fflush(stdout): flush failed! errno=%d\n", errno);
     90            my_stdout_error ("fflush(stdout)", "flush failed!");
    7991          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!");
    8193
    8294          return rcRet;
     
    8496      else
    8597        {
    86           fprintf (stderr, "kmk: fflush(stdout): error pending on entry! errno=%d\n", errno);
     98          my_stdout_error ("fflush(stdout)", "error pending on entry!");
    8799          g_fStdOutError = 1;
    88100        }
     
    93105
    94106# undef  fflush
    95 # undef fflush(a_pFile) my_fflush(a_pFile)
     107# define fflush(a_pFile) my_fflush(a_pFile)
    96108
    97109#endif
     
    275287      /* Exit the critical section.  */
    276288# 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);
    279293# endif
    280294      if (sem)
     
    571585      while (len > 0)
    572586        {
    573           const char *nl = memchr ( src, '\n', len);
     587          const char *nl = memchr (src, '\n', len);
    574588          size_t line_len = nl ? nl - src : len;
    575589          output_write_bin (out, is_err, src, line_len);
     
    980994}
    981995
    982 #endif /* CONFIG_WITH_OUTPUT_IN_MEMORY */
     996#endif /* !CONFIG_WITH_OUTPUT_IN_MEMORY */
    983997
    984998/* Synchronize the output of jobs in -j mode to keep the results of
     
    11611175{
    11621176  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
    11631182  int fclose_fail = fclose (stdout);
    11641183
    11651184  if (prev_fail || fclose_fail)
    11661185    {
     1186#ifdef DEBUG_STDOUT_CLOSE_ISSUE
     1187      if (fclose_fail)
     1188        my_stdout_error ("close_stdout", "fclose failed!");
     1189#endif
    11671190      if (fclose_fail)
    11681191        perror_with_name (_("write error: stdout"), "");
     
    11781201output_init (struct output *out)
    11791202{
     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
    11801208  if (out)
    11811209    {
     
    12201248  set_append_mode (fileno (stderr));
    12211249
     1250#ifdef DEBUG_STDOUT_CLOSE_ISSUE
     1251  if (ferror (stdout))
     1252    my_stdout_error ("output_init", "error pending on exit!");
     1253#endif
    12221254#ifdef HAVE_ATEXIT
    12231255  if (STREAM_OK (stdout))
     
    12631295  if (output_context && output_context->syncout)
    12641296    if (combined_output < 0)
    1265       combined_output = sync_init ();
     1297      {
     1298        combined_output = 0;
     1299        combined_output = sync_init ();
     1300      }
    12661301#else
    12671302#ifndef NO_OUTPUT_SYNC
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette