Fix env + refacto/opti shutdown + gitignore comp
This commit is contained in:
@@ -3,18 +3,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <node.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 {
|
namespace syscallNode {
|
||||||
void nodeSyscall(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
void nodeSyscall(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
v8::Isolate* isolate = args.GetIsolate();
|
v8::Isolate* isolate = args.GetIsolate();
|
||||||
@@ -29,23 +17,22 @@ namespace syscallNode {
|
|||||||
syscall(argsValue);
|
syscall(argsValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nodeHalt(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
||||||
reboot(BMAGIC_HALT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void nodeReboot(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nodePoweroff(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
long argsValue = args[0].As<v8::Number>()->Value();
|
||||||
reboot(BMAGIC_POWEROFF);
|
reboot(argsValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports) {
|
void Initialize(v8::Local<v8::Object> exports) {
|
||||||
NODE_SET_METHOD(exports, "halt", nodeHalt);
|
|
||||||
NODE_SET_METHOD(exports, "reboot", nodeReboot);
|
NODE_SET_METHOD(exports, "reboot", nodeReboot);
|
||||||
NODE_SET_METHOD(exports, "syscall", nodeSyscall);
|
NODE_SET_METHOD(exports, "syscall", nodeSyscall);
|
||||||
NODE_SET_METHOD(exports, "poweroff", nodePoweroff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(syscall_api, Initialize)
|
NODE_MODULE(syscall_api, Initialize)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
syscall.node
|
||||||
@@ -7,8 +7,7 @@ function panic() {
|
|||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const audio = require('./audio.js')
|
const audio = require('./audio.js')
|
||||||
//@ts-expect-error
|
const reboot = require('./reboot.js')
|
||||||
const { poweroff, halt } = require('./shutdown.js')
|
|
||||||
const input = require('./input.js')
|
const input = require('./input.js')
|
||||||
const { fHook } = require("./hook.js")
|
const { fHook } = require("./hook.js")
|
||||||
|
|
||||||
@@ -40,11 +39,12 @@ async function main() {
|
|||||||
|
|
||||||
//chainload into sheebr
|
//chainload into sheebr
|
||||||
await fHook("/usr/bin/sheebr.js")
|
await fHook("/usr/bin/sheebr.js")
|
||||||
poweroff()
|
reboot.disableCtrlAltSupr()
|
||||||
|
reboot.powerOff()
|
||||||
|
|
||||||
/*while(1){}
|
|
||||||
console.log("End of init reached")
|
console.log("End of init reached")
|
||||||
panic()*/
|
reboot.enableCtrlAltSupr()
|
||||||
|
panic()
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
panic()
|
panic()
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
//@ts-check
|
||||||
|
/* Perform a hard reset now. */
|
||||||
|
const RB_AUTOBOOT = 0x01234567
|
||||||
|
|
||||||
|
/* Halt the system. */
|
||||||
|
const RB_HALT_SYSTEM = 0xcdef0123
|
||||||
|
|
||||||
|
/* Enable reboot using Ctrl-Alt-Delete keystroke. */
|
||||||
|
const RB_ENABLE_CAD = 0x89abcdef
|
||||||
|
|
||||||
|
/* Disable reboot using Ctrl-Alt-Delete keystroke. */
|
||||||
|
const RB_DISABLE_CAD = 0
|
||||||
|
|
||||||
|
/* Stop system and switch power off if possible. */
|
||||||
|
const RB_POWER_OFF = 0x4321fedc
|
||||||
|
|
||||||
|
/* Suspend system using software suspend. */
|
||||||
|
const RB_SW_SUSPEND = 0xd000fce2
|
||||||
|
|
||||||
|
/* Reboot system into new kernel. */ //no idea how to use that but hey
|
||||||
|
const RB_KEXEC = 0x45584543
|
||||||
|
|
||||||
|
/**
|
||||||
|
@type {{
|
||||||
|
reboot: (rebootid: number) => void //https://unix.superglobalmegacorp.com/Net2/newsrc/sys/syscall.h.html
|
||||||
|
syscall: (syscallid: number) => void
|
||||||
|
}}
|
||||||
|
*///@ts-expect-error
|
||||||
|
const syscalls = require('./syscall.node')
|
||||||
|
|
||||||
|
function disableCtrlAltSupr() {
|
||||||
|
syscalls.reboot(RB_DISABLE_CAD)
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableCtrlAltSupr() {
|
||||||
|
syscalls.reboot(RB_ENABLE_CAD)
|
||||||
|
}
|
||||||
|
|
||||||
|
function halt() {
|
||||||
|
syscalls.reboot(RB_HALT_SYSTEM)
|
||||||
|
}
|
||||||
|
|
||||||
|
function reboot() {
|
||||||
|
syscalls.reboot(RB_AUTOBOOT)
|
||||||
|
}
|
||||||
|
|
||||||
|
function powerOff() {
|
||||||
|
syscalls.reboot(RB_POWER_OFF)
|
||||||
|
}
|
||||||
|
|
||||||
|
function suspend() {
|
||||||
|
syscalls.reboot(RB_SW_SUSPEND)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = { disableCtrlAltSupr, enableCtrlAltSupr, halt, reboot, powerOff, suspend }
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
syscalls = require('./syscall.node')
|
|
||||||
module.exports = syscalls
|
|
||||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
let environment = {
|
let environment = {
|
||||||
path: ["/sheebr", "/usr/bin"]
|
path: ["/usr/lib/sheebr", "/usr/bin"]
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = environment
|
module.exports = environment
|
||||||
Reference in New Issue
Block a user