Commit 0a397bfe authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Bug#42709: safe_process_win.cc does not print correct system error messages.

Fix: use FormatMessage() to output system errors , not strerror()
parent 5d2a707d
......@@ -77,14 +77,29 @@ static void message(const char* fmt, ...)
static void die(const char* fmt, ...)
{
DWORD last_err= GetLastError();
va_list args;
fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
if (int last_err= GetLastError())
fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err));
if (last_err)
{
char *message_text;
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_err , 0, (LPSTR)&message_text,
0, NULL))
{
fprintf(stderr,"error: %d, %s\n",last_err, message_text);
LocalFree(message_text);
}
else
{
/* FormatMessage failed, print error code only */
fprintf(stderr,"error:%d\n", last_err);
}
}
fflush(stderr);
exit(1);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment