ajout de Sheebr + support de shutdown + auto install kernel
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#include <sys/syscall.h> /* Definition of SYS_* constants */
|
||||
#include <sys/reboot.h>
|
||||
#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();
|
||||
|
||||
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();
|
||||
syscall(argsValue);
|
||||
}
|
||||
|
||||
void nodeHalt(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
reboot(BMAGIC_HALT);
|
||||
}
|
||||
|
||||
void nodeReboot(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
reboot(BMAGIC_REBOOT);
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user