MDEV-16430: mysql_upgrade_service does not write log file.
Fixed CreateFile() for the log file - TRUNCATE_EXISTING does not create a new file, use CREATE_ALWAYS - Make log file handle inheritable
This commit is contained in:
parent
55abcfa7b7
commit
141bc58ac9
@ -146,6 +146,11 @@ static void die(const char *fmt, ...)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define WRITE_LOG(fmt,...) {\
|
||||||
|
char log_buf[1024]; \
|
||||||
|
snprintf(log_buf,sizeof(log_buf), fmt, __VA_ARGS__);\
|
||||||
|
WriteFile(logfile_handle,log_buf, strlen(log_buf), 0 , 0);\
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
spawn-like function to run subprocesses.
|
spawn-like function to run subprocesses.
|
||||||
@ -187,17 +192,22 @@ static intptr_t run_tool(int wait_flag, const char *program,...)
|
|||||||
{
|
{
|
||||||
char tmpdir[FN_REFLEN];
|
char tmpdir[FN_REFLEN];
|
||||||
GetTempPath(FN_REFLEN, tmpdir);
|
GetTempPath(FN_REFLEN, tmpdir);
|
||||||
sprintf_s(logfile_path, "%s\\mysql_upgrade_service.%s.log", tmpdir,
|
sprintf_s(logfile_path, "%smysql_upgrade_service.%s.log", tmpdir,
|
||||||
opt_service);
|
opt_service);
|
||||||
logfile_handle= CreateFile(logfile_path, GENERIC_WRITE, FILE_SHARE_READ,
|
SECURITY_ATTRIBUTES attr= {0};
|
||||||
NULL, TRUNCATE_EXISTING, 0, NULL);
|
attr.nLength= sizeof(SECURITY_ATTRIBUTES);
|
||||||
if (!logfile_handle)
|
attr.bInheritHandle= TRUE;
|
||||||
|
logfile_handle= CreateFile(logfile_path, FILE_APPEND_DATA,
|
||||||
|
FILE_SHARE_READ|FILE_SHARE_WRITE, &attr, CREATE_ALWAYS, 0, NULL);
|
||||||
|
if (logfile_handle == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
die("Cannot open log file %s, windows error %u",
|
die("Cannot open log file %s, windows error %u",
|
||||||
logfile_path, GetLastError());
|
logfile_path, GetLastError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WRITE_LOG("Executing %s\r\n", cmdline);
|
||||||
|
|
||||||
/* Start child process */
|
/* Start child process */
|
||||||
STARTUPINFO si= {0};
|
STARTUPINFO si= {0};
|
||||||
si.cb= sizeof(si);
|
si.cb= sizeof(si);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user