mirror of
https://github.com/openharmony/js_sys_module.git
synced 2026-07-01 22:04:01 -04:00
@@ -31,7 +31,9 @@ namespace OHOS::Js_sys_module::Dfx {
|
||||
char *tempStr = nullptr;
|
||||
size_t tempStrsize = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &tempStrsize);
|
||||
tempStr = new char[tempStrsize + 1];
|
||||
if (tempStrsize > 0) {
|
||||
tempStr = new char[tempStrsize + 1];
|
||||
}
|
||||
napi_get_value_string_utf8(env, argv[0], tempStr, tempStrsize + 1, &tempStrsize);
|
||||
std::string pathStr = tempStr;
|
||||
bool isVmMode = true;
|
||||
@@ -88,7 +90,9 @@ namespace OHOS::Js_sys_module::Dfx {
|
||||
char *tempStr = nullptr;
|
||||
size_t tempStrsize = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &tempStrsize);
|
||||
tempStr = new char[tempStrsize + 1];
|
||||
if (tempStrsize > 0) {
|
||||
tempStr = new char[tempStrsize + 1];
|
||||
}
|
||||
napi_get_value_string_utf8(env, argv[0], tempStr, tempStrsize + 1, &tempStrsize);
|
||||
std::string filePath = tempStr;
|
||||
delete []tempStr;
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace OHOS::Js_sys_module::Process {
|
||||
stdErrInfo_->isNeedRun = &isNeedRun_;
|
||||
stdErrInfo_->fd = stdErrFd_[0];
|
||||
stdErrInfo_->pid = optionsInfo_->pid;
|
||||
stdErrInfo_->maxBuffSize = optionsInfo_->maxBuffer;
|
||||
stdErrInfo_->maxBuffSize = static_cast<size_t>(optionsInfo_->maxBuffer);
|
||||
napi_create_string_utf8(env_, "ReadStdErr", NAPI_AUTO_LENGTH, &resourceName);
|
||||
napi_create_async_work(env_, nullptr, resourceName, ReadStdErr, EndStdErr,
|
||||
reinterpret_cast<void*>(stdErrInfo_), &stdErrInfo_->worker);
|
||||
@@ -327,7 +327,7 @@ namespace OHOS::Js_sys_module::Process {
|
||||
|
||||
void ChildProcess::Kill(const napi_value signo)
|
||||
{
|
||||
size_t signal = GetValidSignal(signo);
|
||||
int signal = GetValidSignal(signo);
|
||||
std::vector<int32_t> signalType = {SIGINT, SIGQUIT, SIGKILL, SIGTERM};
|
||||
if (!kill(optionsInfo_->pid, signal)) {
|
||||
auto res = std::find(signalType.begin(), signalType.end(), static_cast<int32_t>(signal));
|
||||
@@ -359,7 +359,7 @@ namespace OHOS::Js_sys_module::Process {
|
||||
auto temp = reinterpret_cast<OptionsInfo*>(data);
|
||||
int32_t timeout = temp->timeout * TIME_EXCHANGE;
|
||||
if (timeout > 0) {
|
||||
usleep(timeout);
|
||||
usleep(static_cast<size_t>(timeout));
|
||||
if (*(temp->isNeedRun)) {
|
||||
if (!kill(temp->pid, temp->killSignal)) {
|
||||
auto res = std::find(signalType.begin(), signalType.end(), temp->killSignal);
|
||||
|
||||
+8
-24
@@ -87,7 +87,7 @@ namespace OHOS::Js_sys_module::Process {
|
||||
if (progroups == -1) {
|
||||
napi_throw_error(env_, "-1", "getgroups");
|
||||
}
|
||||
pgrous.resize(progroups);
|
||||
pgrous.resize(static_cast<size_t>(progroups));
|
||||
gid_t proegid = getegid();
|
||||
if (std::find(pgrous.begin(), pgrous.end(), proegid) == pgrous.end()) {
|
||||
pgrous.push_back(proegid);
|
||||
@@ -408,32 +408,16 @@ namespace OHOS::Js_sys_module::Process {
|
||||
if (res1 != 0) {
|
||||
return 0;
|
||||
}
|
||||
double whenpro = ConvertTime(timespro.tv_sec, timespro.tv_nsec);
|
||||
double whensys = ConvertTime(timessys.tv_sec, timessys.tv_nsec);
|
||||
int whenpro = ConvertTime(timespro.tv_sec, timespro.tv_nsec);
|
||||
int whensys = ConvertTime(timessys.tv_sec, timessys.tv_nsec);
|
||||
auto timedif = (whensys - whenpro);
|
||||
napi_create_double(env_, timedif, &result);
|
||||
napi_create_int32(env_, timedif, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value Process::GetAvailableCores() const
|
||||
int Process::ConvertTime(time_t tvsec, long tvnsec) const
|
||||
{
|
||||
napi_value result = nullptr;
|
||||
auto numcpus = static_cast<int32_t>(sysconf(_SC_NPROCESSORS_ONLN));
|
||||
NAPI_CALL(env_, napi_create_array(env_, &result));
|
||||
for (int i = 0; i <= numcpus; i++) {
|
||||
napi_value numvalue = nullptr;
|
||||
napi_create_uint32(env_, i, &numvalue);
|
||||
napi_status status = napi_set_element(env_, result, i, numvalue);
|
||||
if (status != napi_ok) {
|
||||
HILOG_ERROR("set element error");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
double Process::ConvertTime(time_t tvsec, long tvnsec) const
|
||||
{
|
||||
return double(tvsec * 1000) + double(tvnsec / 1000000); // 98999:Only converttime numbers is 1000 and 1000000.
|
||||
return int(tvsec * 1000) + int(tvnsec / 1000000); // 98999:Only converttime numbers is 1000 and 1000000.
|
||||
}
|
||||
|
||||
napi_value Process::GetPastCputime() const
|
||||
@@ -444,8 +428,8 @@ namespace OHOS::Js_sys_module::Process {
|
||||
if (res != 0) {
|
||||
return 0;
|
||||
}
|
||||
double when = ConvertTime(times.tv_sec, times.tv_nsec);
|
||||
napi_create_double(env_, when, &result);
|
||||
int when = ConvertTime(times.tv_sec, times.tv_nsec);
|
||||
napi_create_int32(env_, when, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,13 +54,12 @@ namespace OHOS::Js_sys_module::Process {
|
||||
napi_value GetStartRealtime() const;
|
||||
napi_value GetPastCputime() const;
|
||||
napi_value GetSystemConfig(napi_value name) const;
|
||||
napi_value GetAvailableCores() const;
|
||||
napi_value GetEnvironmentVar(napi_value name) const;
|
||||
napi_value SetRejectionCallback() const;
|
||||
|
||||
static void ClearReference(napi_env env);
|
||||
private:
|
||||
double ConvertTime(time_t tvsec, long tvnsec) const;
|
||||
int ConvertTime(time_t tvsec, long tvnsec) const;
|
||||
private:
|
||||
napi_env env_ { nullptr };
|
||||
int FIRST_APPLICATION_UID = 10000;
|
||||
|
||||
@@ -500,12 +500,6 @@ namespace OHOS::Js_sys_module::Process {
|
||||
return object.GetEnvironmentVar(args);
|
||||
}
|
||||
|
||||
static napi_value GetAvailableCores(napi_env env, napi_callback_info info)
|
||||
{
|
||||
Process object(env);
|
||||
return object.GetAvailableCores();
|
||||
}
|
||||
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
Process object(env);
|
||||
@@ -529,7 +523,6 @@ namespace OHOS::Js_sys_module::Process {
|
||||
DECLARE_NAPI_FUNCTION("exit", Exit),
|
||||
DECLARE_NAPI_GETTER("tid", GetTid),
|
||||
DECLARE_NAPI_FUNCTION("getStartRealtime", GetStartRealtime),
|
||||
DECLARE_NAPI_FUNCTION("getAvailableCores", GetAvailableCores),
|
||||
DECLARE_NAPI_FUNCTION("getPastCputime", GetPastCputime),
|
||||
DECLARE_NAPI_FUNCTION("isIsolatedProcess", IsIsolatedProcess),
|
||||
DECLARE_NAPI_FUNCTION("is64Bit", Is64Bit),
|
||||
|
||||
Reference in New Issue
Block a user