hopefully implement shutdown
This commit is contained in:
parent
2d386f1276
commit
7ad9f21182
@ -13,6 +13,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -151,7 +152,7 @@ static int l_fs_spaceUsed (lua_State *L) {
|
||||
#ifndef _WIN32
|
||||
struct statvfs s;
|
||||
if( statvfs(fname, &s) != -1 ) {
|
||||
lua_pushnumber(L, s.f_bsize * s.f_bfree);
|
||||
lua_pushnumber(L, s.f_bsize * (s.f_blocks - s.f_bfree));
|
||||
} else {
|
||||
lua_pushnumber(L, -1);
|
||||
}
|
||||
@ -377,6 +378,18 @@ static int l_uptime (lua_State *L) { /* Return ms */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_shutdown(lua_State *L) {
|
||||
int shutdownmode = lua_toboolean(L, 1);
|
||||
sync();
|
||||
printf("%i", shutdownmode);
|
||||
int rebootcmd = LINUX_REBOOT_CMD_POWER_OFF;
|
||||
if (shutdownmode == 1) {
|
||||
rebootcmd = LINUX_REBOOT_CMD_RESTART;
|
||||
}
|
||||
reboot(rebootcmd);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int l_totalMemory (lua_State *L) {
|
||||
#if defined(_WIN32) && (defined(__CYGWIN__) || defined(__CYGWIN32__))
|
||||
MEMORYSTATUS status;
|
||||
@ -492,6 +505,7 @@ void luanative_start(lua_State *L) {
|
||||
{"towupper", l_towupper},
|
||||
{"beep", l_beep},
|
||||
{"uptime", l_uptime},
|
||||
{"shutdown", l_shutdown},
|
||||
{"totalMemory", l_totalMemory},
|
||||
{"freeMemory", l_freeMemory},
|
||||
{"pull", l_pull},
|
||||
|
@ -166,7 +166,7 @@ function api.totalMemory()
|
||||
return native.totalMemory()
|
||||
end
|
||||
|
||||
function api.shutdown()
|
||||
function api.shutdown(reboot)
|
||||
--TODO: Longjmp to init somehow?
|
||||
print("Running shutdown hooks")
|
||||
for k, hook in ipairs(deadhooks) do
|
||||
@ -178,7 +178,8 @@ function api.shutdown()
|
||||
end
|
||||
print("Hooks executed: " .. #deadhooks)
|
||||
|
||||
native.shutdown(reboot)
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
return computer
|
||||
return computer
|
||||
|
Loading…
Reference in New Issue
Block a user