AI automatically translates all comments in the code into English (#3917)

This commit is contained in:
alex
2024-09-19 14:53:50 +08:00
committed by GitHub
parent 046de691cb
commit 4152dcd409
279 changed files with 10602 additions and 3038 deletions

View File

@@ -35,12 +35,15 @@ using namespace toolkit;
#ifndef _WIN32
static void setupChildProcess() {
//取消cpu亲和性设置防止FFmpeg进程cpu占用率不能超过100%的问题
// 取消cpu亲和性设置防止FFmpeg进程cpu占用率不能超过100%的问题 [AUTO-TRANSLATED:d168129d]
// Cancel CPU affinity settings to prevent FFmpeg process from exceeding 100% CPU usage.
setThreadAffinity(-1);
//子进程关闭core文件生成
// 子进程关闭core文件生成 [AUTO-TRANSLATED:721d2925]
// Disable core file generation for child processes.
struct rlimit rlim = { 0, 0 };
setrlimit(RLIMIT_CORE, &rlim);
//子进程恢复默认信号处理
// 子进程恢复默认信号处理 [AUTO-TRANSLATED:1bc7387b]
// Restore default signal handling for child processes.
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
@@ -52,7 +55,8 @@ static int runChildProcess(string cmd, string log_file) {
setupChildProcess();
if (log_file.empty()) {
//未指定子进程日志文件时,重定向至/dev/null
// 未指定子进程日志文件时,重定向至/dev/null [AUTO-TRANSLATED:dd0c9853]
// Redirect child process logs to /dev/null if no log file is specified.
log_file = "/dev/null";
} else {
log_file = StrPrinter << log_file << "." << getpid();
@@ -64,7 +68,8 @@ static int runChildProcess(string cmd, string log_file) {
open("/dev/null", O_RDONLY, 0666); /* will be fd 0 (STDIN_FILENO) */
}
//重定向shell日志至文件
// 重定向shell日志至文件 [AUTO-TRANSLATED:3480502b]
// Redirect shell logs to file.
auto fp = File::create_file(log_file, "ab");
if (!fp) {
fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), get_uv_error(), get_uv_errmsg());
@@ -77,7 +82,8 @@ static int runChildProcess(string cmd, string log_file) {
if (dup2(log_fd, STDERR_FILENO) < 0) {
fprintf(stderr, "dup2 stderr file %s failed:%d(%s)\r\n", log_file.data(), get_uv_error(), get_uv_errmsg());
}
// 关闭日志文件
// 关闭日志文件 [AUTO-TRANSLATED:9fb6e256]
// Close log file.
::fclose(fp);
}
fprintf(stderr, "\r\n\r\n#### pid=%d,cmd=%s #####\r\n\r\n", getpid(), cmd.data());
@@ -114,13 +120,15 @@ void Process::run(const string &cmd, string log_file) {
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
if (log_file.empty()) {
//未指定子进程日志文件时,重定向至/dev/null
// 未指定子进程日志文件时,重定向至/dev/null [AUTO-TRANSLATED:dd0c9853]
// Redirect child process logs to /dev/null if no log file is specified.
log_file = "NUL";
} else {
log_file = StrPrinter << log_file << "." << getCurrentMillisecond();
}
//重定向shell日志至文件
// 重定向shell日志至文件 [AUTO-TRANSLATED:3480502b]
// Redirect shell logs to file.
auto fp = File::create_file(log_file, "ab");
if (!fp) {
fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), get_uv_error(), get_uv_errmsg());
@@ -137,7 +145,8 @@ void Process::run(const string &cmd, string log_file) {
LPTSTR lpDir = const_cast<char *>(cmd.data());
if (CreateProcess(NULL, lpDir, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) {
//下面两行关闭句柄,解除本进程和新进程的关系,不然有可能 不小心调用TerminateProcess函数关掉子进程
// 下面两行关闭句柄,解除本进程和新进程的关系,不然有可能 不小心调用TerminateProcess函数关掉子进程 [AUTO-TRANSLATED:d50fada2]
// The following two lines close the handle and break the relationship between the current process and the new process. Otherwise, the TerminateProcess function may accidentally close the child process.
CloseHandle(pi.hThread);
_pid = pi.dwProcessId;
_handle = pi.hProcess;
@@ -165,12 +174,14 @@ void Process::run(const string &cmd, string log_file) {
throw std::runtime_error(StrPrinter << "fork child process failed, cmd: " << cmd << ",err:" << get_uv_errmsg());
}
if (_pid == 0) {
//子进程
// 子进程 [AUTO-TRANSLATED:3f793797]
// Child process.
exit(runChildProcess(cmd, log_file));
}
#endif
if (log_file.empty()) {
//未指定子进程日志文件时,重定向至/dev/null
// 未指定子进程日志文件时,重定向至/dev/null [AUTO-TRANSLATED:dd0c9853]
// Redirect child process logs to /dev/null if no log file is specified.
log_file = "/dev/null";
} else {
log_file = StrPrinter << log_file << "." << _pid;
@@ -185,6 +196,13 @@ void Process::run(const string &cmd, string log_file) {
* @param exit_code_ptr 进程返回代码
* @param block 是否阻塞等待
* @return 进程是否还在运行
* Get the process's alive status.
* @param pid Process ID
* @param exit_code_ptr Process return code
* @param block Whether to block and wait
* @return Whether the process is still running
* [AUTO-TRANSLATED:ef80ff17]
*/
static bool s_wait(pid_t pid, void *handle, int *exit_code_ptr, bool block) {
if (pid <= 0) {
@@ -193,14 +211,16 @@ static bool s_wait(pid_t pid, void *handle, int *exit_code_ptr, bool block) {
#ifdef _WIN32
DWORD code = 0;
if (block) {
//一直等待
// 一直等待 [AUTO-TRANSLATED:ca8a5e14]
// Wait indefinitely.
code = WaitForSingleObject(handle, INFINITE);
} else {
code = WaitForSingleObject(handle, 0);
}
if (code == WAIT_FAILED || code == WAIT_OBJECT_0) {
//子进程已经退出了,获取子进程退出代码
// 子进程已经退出了,获取子进程退出代码 [AUTO-TRANSLATED:c39663b2]
// The child process has exited, get the child process exit code.
DWORD exitCode = 0;
if (exit_code_ptr && GetExitCodeProcess(handle, &exitCode)) {
*exit_code_ptr = exitCode;
@@ -209,10 +229,12 @@ static bool s_wait(pid_t pid, void *handle, int *exit_code_ptr, bool block) {
}
if (code == WAIT_TIMEOUT) {
//子进程还在线
// 子进程还在线 [AUTO-TRANSLATED:3d32ef56]
// The child process is still online.
return true;
}
//不太可能运行到此处
// 不太可能运行到此处 [AUTO-TRANSLATED:b1fde65d]
// It is unlikely to run to this point.
WarnL << "WaitForSingleObject ret:" << code;
return false;
#else
@@ -268,42 +290,52 @@ bool signalCtrl(DWORD dwProcessId, DWORD dwCtrlEvent) {
static void s_kill(pid_t pid, void *handle, int max_delay, bool force) {
if (pid <= 0) {
// pid无效
// pid无效 [AUTO-TRANSLATED:6665d7a0]
// Invalid pid.
return;
}
#ifdef _WIN32
// windows下目前没有比较好的手段往子进程发送SIGTERM或信号
//所以杀死子进程的方式全部强制为立即关闭
// windows下目前没有比较好的手段往子进程发送SIGTERM或信号 [AUTO-TRANSLATED:cd32ad25]
// Currently, there is no good way to send SIGTERM or signals to child processes under Windows.
// 所以杀死子进程的方式全部强制为立即关闭 [AUTO-TRANSLATED:2fc31f2b]
// Therefore, all methods of killing child processes are forced to be immediate closure.
force = true;
if (force) {
//强制关闭子进程
// 强制关闭子进程 [AUTO-TRANSLATED:f3c712f6]
// Force close the child process.
TerminateProcess(handle, 0);
} else {
//非强制关闭发送Ctr+C信号
// 非强制关闭发送Ctr+C信号 [AUTO-TRANSLATED:fe9bf53f]
// Non-forced closure, send Ctrl+C signal.
signalCtrl(pid, CTRL_C_EVENT);
}
#else
if (::kill(pid, force ? SIGKILL : SIGTERM) == -1) {
//进程可能已经退出了
// 进程可能已经退出了 [AUTO-TRANSLATED:682a8b61]
// The process may have already exited.
WarnL << "kill process " << pid << " failed:" << get_uv_errmsg();
return;
}
#endif // _WIN32
if (force) {
//发送SIGKILL信号后阻塞等待退出
// 发送SIGKILL信号后阻塞等待退出 [AUTO-TRANSLATED:4fc03dae]
// After sending the SIGKILL signal, block and wait for exit.
s_wait(pid, handle, nullptr, true);
DebugL << "force kill " << pid << " success!";
return;
}
//发送SIGTERM信号后2秒后检查子进程是否已经退出
// 发送SIGTERM信号后2秒后检查子进程是否已经退出 [AUTO-TRANSLATED:b9878b28]
// After sending the SIGTERM signal, check if the child process has exited after 2 seconds.
EventPollerPool::Instance().getPoller()->doDelayTask(max_delay, [pid, handle]() {
if (!s_wait(pid, handle, nullptr, false)) {
//进程已经退出了
// 进程已经退出了 [AUTO-TRANSLATED:ad02bb63]
// The process has exited.
return 0;
}
//进程还在运行
// 进程还在运行 [AUTO-TRANSLATED:b1aa9ba4]
// The process is still running.
WarnL << "process still working,force kill it:" << pid;
s_kill(pid, handle, 0, true);
return 0;