Commit 20e57195 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 4d0557a2
...@@ -77,14 +77,29 @@ static void message(const char* fmt, ...) ...@@ -77,14 +77,29 @@ static void message(const char* fmt, ...)
static void die(const char* fmt, ...) static void die(const char* fmt, ...)
{ {
DWORD last_err= GetLastError();
va_list args; va_list args;
fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name); fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name);
va_start(args, fmt); va_start(args, fmt);
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
va_end(args); va_end(args);
if (int last_err= GetLastError()) if (last_err)
fprintf(stderr, "error: %d, %s\n", last_err, strerror(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); fflush(stderr);
exit(1); 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