Skip to content

Commit 20792b9

Browse files
committed
Always read the stdin preamble in wixnative
When the wixnative.exe exits before the C# code sends the preamble, we'll get an exception that the stdin pipe is already closed. Turns out some commands did not wait for the preamble, so make them all wait to remove the race condition.
1 parent 8a24574 commit 20792b9

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/wix/wixnative/certhashes.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ HRESULT CertificateHashesCommand(
2727
LPWSTR sczPublicKeyIdentifier = NULL;
2828
LPWSTR sczThumbprint = NULL;
2929

30-
hr = WixNativeReadStdinPreamble();
31-
ExitOnFailure(hr, "Failed to read stdin preamble before reading paths to get certificate hashes");
32-
3330
// Get the hash for each provided file.
3431
for (;;)
3532
{

src/wix/wixnative/precomp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "cabcutil.h"
1818
#include "cabutil.h"
1919

20-
HRESULT WixNativeReadStdinPreamble();
2120
HRESULT CertificateHashesCommand(__in int argc, __in_ecount(argc) LPWSTR argv[]);
2221
HRESULT SmartCabCommand(__in int argc, __in_ecount(argc) LPWSTR argv[]);
2322
HRESULT EnumCabCommand(__in int argc, __in_ecount(argc) LPWSTR argv[]);

src/wix/wixnative/smartcab.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ HRESULT SmartCabCommand(
6969

7070
if (uiFileCount > 0)
7171
{
72-
hr = WixNativeReadStdinPreamble();
73-
ExitOnFailure(hr, "failed to read stdin preamble before smartcabbing");
74-
7572
hr = CompressFiles(hCab, &sczFirstFileToken);
7673
ExitOnFailure(hr, "failed to compress files into cabinet: %ls", sczCabPath);
7774

src/wix/wixnative/wixnative.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#include "precomp.h"
44

5+
static HRESULT WixNativeReadStdinPreamble();
6+
7+
58
int __cdecl wmain(int argc, LPWSTR argv[])
69
{
710
HRESULT hr = E_INVALIDARG;
@@ -11,8 +14,14 @@ int __cdecl wmain(int argc, LPWSTR argv[])
1114
if (argc < 2)
1215
{
1316
ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Must specify a command");
17+
18+
ExitFunction();
1419
}
15-
else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"smartcab", -1))
20+
21+
hr = WixNativeReadStdinPreamble();
22+
ExitOnFailure(hr, "failed to read stdin preamble");
23+
24+
if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"smartcab", -1))
1625
{
1726
hr = SmartCabCommand(argc - 2, argv + 2);
1827
}
@@ -33,11 +42,12 @@ int __cdecl wmain(int argc, LPWSTR argv[])
3342
ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Unknown command: %ls", argv[1]);
3443
}
3544

45+
LExit:
3646
ConsoleUninitialize();
3747
return HRESULT_CODE(hr);
3848
}
3949

40-
HRESULT WixNativeReadStdinPreamble()
50+
static HRESULT WixNativeReadStdinPreamble()
4151
{
4252
HRESULT hr = S_OK;
4353
LPWSTR sczLine = NULL;

0 commit comments

Comments
 (0)