Fix env + refacto/opti shutdown + gitignore comp

This commit is contained in:
Marc
2021-11-27 17:26:49 +01:00
parent f1b67891e1
commit ec95675837
7 changed files with 72 additions and 30 deletions
+9 -22
View File
@@ -3,18 +3,6 @@
#include <unistd.h>
#include <node.h>
#ifdef RB_HALT_SYSTEM
# define BMAGIC_HALT RB_HALT_SYSTEM
#else
# define BMAGIC_HALT RB_HALT
#endif
#define BMAGIC_REBOOT RB_AUTOBOOT
#define BMAGIC_POWEROFF RB_POWER_OFF
namespace syscallNode {
void nodeSyscall(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
@@ -29,23 +17,22 @@ namespace syscallNode {
syscall(argsValue);
}
void nodeHalt(const v8::FunctionCallbackInfo<v8::Value>& args) {
reboot(BMAGIC_HALT);
}
void nodeReboot(const v8::FunctionCallbackInfo<v8::Value>& args) {
reboot(BMAGIC_REBOOT);
v8::Isolate* isolate = args.GetIsolate();
if (!args[0]->IsNumber()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a number").ToLocalChecked()));
return;
}
long argsValue = args[0].As<v8::Number>()->Value();
reboot(argsValue);
}
void nodePoweroff(const v8::FunctionCallbackInfo<v8::Value>& args) {
reboot(BMAGIC_POWEROFF);
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "halt", nodeHalt);
NODE_SET_METHOD(exports, "reboot", nodeReboot);
NODE_SET_METHOD(exports, "syscall", nodeSyscall);
NODE_SET_METHOD(exports, "poweroff", nodePoweroff);
}
NODE_MODULE(syscall_api, Initialize)