Compare commits

...

5 Commits

6 changed files with 29 additions and 9 deletions

View File

@ -1,7 +1,7 @@
# LuPI2 Makefile
# Default compiler settings.
PREFIX?=x86_64-linux-musl
PREFIX?=powerpc-linux-musl
CC = $(PREFIX)-gcc
CFLAGS?=-O2 -std=c99 -fdata-sections -ffunction-sections -pthread
@ -67,10 +67,10 @@ web: iso bin/web
####
ISOKERNEL=linux-4.5.2
ISOKERNEL=linux-5.12.1
dependencies/$(ISOKERNEL).tar.xz:
cd dependencies && wget https://cdn.kernel.org/pub/linux/kernel/v4.x/$(ISOKERNEL).tar.xz
cd dependencies && wget https://cdn.kernel.org/pub/linux/kernel/v5.x/$(ISOKERNEL).tar.xz
dependencies/$(ISOKERNEL)/arch/x86/boot/bzImage: $(BUILD)lupi.cpio dependencies/$(ISOKERNEL).tar.xz
rm -rf dependencies/$(ISOKERNEL)/

View File

@ -38,6 +38,10 @@ case "$1" in
TOOL=i686-w64-mingw32
OUT=$TOOL
;;
powerpc )
TOOL=powerpc-linux-musl
OUT=$TOOL
;;
*) echo "Invalid target!" ; exit 1
;;
esac

View File

@ -11,6 +11,7 @@ void lupi_init() {
if(getpid() == 1) {
mount(NULL, "/sys", "sysfs", 0, NULL);
mount(NULL, "/proc", "procfs", 0, NULL);
mount(NULL, "/tmp", "tmpfs", 0, NULL);
}
struct statvfs fsstat;
@ -21,4 +22,4 @@ void lupi_init() {
void lupi_init() {
}
#endif
#endif

View File

@ -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},

View File

@ -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

View File

@ -123,7 +123,7 @@ function filesystem.register(basePath, uuid)
end
function fs.list(path)
checkArg(1, path, "string")
return native.fs_list(realpath(path)) --TODO: Test, check if dirs get / at end
return native.fs_list(realpath(path)) or {} --TODO: Test, check if dirs get / at end
end
function fs.lastModified(path)
checkArg(1, path, "string")
@ -159,4 +159,4 @@ function filesystem.register(basePath, uuid)
return modules.component.api.register(uuid, "filesystem", fs)
end
return filesystem
return filesystem