pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch to fix winrunasservice on Windows 32bit-only machines, 2025-08-29
Posted by Anonymous on Fri 29th Aug 2025 11:59
raw | new post

  1. From d7c68c12b5338e8d6c38b3ac9298bc7d2de63815 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Fri, 29 Aug 2025 12:16:07 +0200
  4. Subject: [PATCH] tests: winrunassystem.exe on a 32bit-only machine should not
  5.  look for C:\cygwin64\bin\bash.exe
  6.  
  7. winrunassystem.exe on a Windows 32bit-only machine should not look for
  8. C:\cygwin64\bin\bash.exe.
  9. We just replace the bash/cat copy with native Win32 code, so we do not have to
  10. rely on bash.exe anymore.
  11.  
  12. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  13. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  14. ---
  15. tests/winrunassystem/winrunassystem.c | 85 +++++++++++++++++++--------
  16.  1 file changed, 60 insertions(+), 25 deletions(-)
  17.  
  18. diff --git a/tests/winrunassystem/winrunassystem.c b/tests/winrunassystem/winrunassystem.c
  19. index 6ccae1b..07b166d 100644
  20. --- a/tests/winrunassystem/winrunassystem.c
  21. +++ b/tests/winrunassystem/winrunassystem.c
  22. @@ -154,23 +154,6 @@ int remove_fmt(const char *fmt, ...)
  23.      return retval;
  24.  }
  25.  
  26. -static
  27. -int system_fmt(const char *fmt, ...)
  28. -{
  29. -    int retval;
  30. -    char buffer[16384];
  31. -
  32. -    va_list args;
  33. -    va_start(args, fmt);
  34. -
  35. -    (void)vsnprintf(buffer, sizeof(buffer), fmt, args);
  36. -    retval = system(buffer);
  37. -
  38. -    va_end(args);
  39. -
  40. -    return retval;
  41. -}
  42. -
  43.  static
  44.  void LaunchInteractiveProcess(void)
  45.  {
  46. @@ -540,6 +523,55 @@ bool readfilecontentsintobuffer(const wchar_t *filename,
  47.      return retval;
  48.  }
  49.  
  50. +static
  51. +bool CopyFileToHANDLE(wchar_t *filename, HANDLE hDest)
  52. +{
  53. +    HANDLE hSrc = INVALID_HANDLE_VALUE;
  54. +    BYTE buffer[4096];
  55. +    DWORD dwBytesRead = 0;
  56. +    DWORD dwBytesWritten = 0;
  57. +    BOOL bSuccess = FALSE;
  58. +    bool retval = false;
  59. +
  60. +    hSrc = CreateFileW(filename,
  61. +        GENERIC_READ,
  62. +        FILE_SHARE_READ,
  63. +        NULL,
  64. +        OPEN_EXISTING,
  65. +        FILE_ATTRIBUTE_NORMAL,
  66. +        NULL);
  67. +    if (hSrc == INVALID_HANDLE_VALUE) {
  68. +        (void)fwprintf(stderr,
  69. +            L"Unable to open source file '%ls', lasterr=%d\n",
  70. +            filename, (int)GetLastError());
  71. +        return false;
  72. +    }
  73. +
  74. +    while (ReadFile(hSrc, buffer, sizeof(buffer), &dwBytesRead, NULL) &&
  75. +        (dwBytesRead > 0)) {
  76. +        bSuccess = WriteFile(hDest,
  77. +            buffer,
  78. +            dwBytesRead,
  79. +            &dwBytesWritten,
  80. +            NULL);
  81. +
  82. +        if (!bSuccess || (dwBytesRead != dwBytesWritten)) {
  83. +            (void)fwprintf(stderr,
  84. +                L"Failed to write to the destination file, lasterr=%d\n",
  85. +                (int)GetLastError());
  86. +            retval = false;
  87. +            goto done;
  88. +        }
  89. +    }
  90. +
  91. +    retval = true;
  92. +
  93. +done:
  94. +    (void)CloseHandle(hSrc);
  95. +
  96. +    return retval;
  97. +}
  98. +
  99.  static
  100.  void usage(const wchar_t *av0)
  101.  {
  102. @@ -590,25 +622,28 @@ int wmain(int argc, wchar_t *argv[])
  103.  
  104.      /* Install and Start */
  105.      if (InstallService(argc, argv)) {
  106. +        wchar_t filenamebuff[MAX_PATH+1];
  107. +
  108.          /* Stop and Uninstall */
  109.          UninstallService();
  110.  
  111.          /* Get child stdout+stderr */
  112. -        (void)system_fmt("C:\\cygwin64\\bin\\bash.exe -c "
  113. -            "'cat \"/cygdrive/c/Windows/Temp/%ls_stderr\" 1>&2'",
  114. +        (void)swprintf(filenamebuff, sizeof(filenamebuff),
  115. +            L"C:\\Windows\\Temp\\%ls_stderr",
  116.              service_name_buffer);
  117. -        (void)system_fmt("C:\\cygwin64\\bin\\bash.exe -c "
  118. -            "'cat \"/cygdrive/c/Windows/Temp/%ls_stdout\"'",
  119. +        (void)CopyFileToHANDLE(filenamebuff, GetStdHandle(STD_ERROR_HANDLE));
  120. +        (void)swprintf(filenamebuff, sizeof(filenamebuff),
  121. +            L"C:\\Windows\\Temp\\%ls_stdout",
  122.              service_name_buffer);
  123. +        (void)CopyFileToHANDLE(filenamebuff, GetStdHandle(STD_OUTPUT_HANDLE));
  124.  
  125.          /* Read child return value */
  126. -        wchar_t statusfilenamebuff[MAX_PATH+1];
  127.          char statusvalue[256];
  128.          size_t numbytesread = 0UL;
  129. -        (void)swprintf(statusfilenamebuff, sizeof(statusfilenamebuff),
  130. +        (void)swprintf(filenamebuff, sizeof(filenamebuff),
  131.              L"C:\\Windows\\Temp\\%ls_status",
  132.              service_name_buffer);
  133. -        if (readfilecontentsintobuffer(statusfilenamebuff,
  134. +        if (readfilecontentsintobuffer(filenamebuff,
  135.              statusvalue, sizeof(statusvalue), &numbytesread)) {
  136.              statusvalue[numbytesread] = '\0';
  137.              retval = atoi(statusvalue);
  138. @@ -616,7 +651,7 @@ int wmain(int argc, wchar_t *argv[])
  139.          else {
  140.              (void)fwprintf(stderr,
  141.                  L"%ls: Cannot read child status from file '%ls'\n",
  142. -                argv[0], statusfilenamebuff);
  143. +                argv[0], filenamebuff);
  144.              retval = EXIT_FAILURE;
  145.          }
  146.  
  147. --
  148. 2.45.4

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at