aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--build_config/linux.config4
-rw-r--r--config/env1
-rwxr-xr-xconfig/init.hooks/devfs3
-rwxr-xr-xconfig/init.hooks/procfs3
-rwxr-xr-xconfig/init.hooks/shell6
-rwxr-xr-xconfig/init.hooks/start8
-rwxr-xr-xconfig/init.hooks/stop2
-rwxr-xr-xconfig/init.hooks/sysfs3
-rw-r--r--core/for.c45
-rwxr-xr-xcore/init5
-rw-r--r--core/mount.c2
-rw-r--r--core/unmount.c12
-rw-r--r--lib/exec/exec.c38
-rw-r--r--lib/exec/exec.h6
-rw-r--r--lib/sys/unmount.h11
-rw-r--r--smash/exec.c39
-rw-r--r--smash/exec.h2
-rw-r--r--smash/main.c2
-rwxr-xr-xutils/init4
20 files changed, 161 insertions, 50 deletions
diff --git a/Makefile b/Makefile
index d90bcc9..1d26ad3 100644
--- a/Makefile
+++ b/Makefile
@@ -34,13 +34,20 @@ target:
initramfs: target core smash
@echo Installing Initramfs
- @mkdir -p ${INITRAMFS}/system/config ${INITRAMFS}/system/manual ${INITRAMFS}/system/core ${INITRAMFS}/system/utils ${INITRAMFS}/system/scripts ${INITRAMFS}/system/devices
+ @mkdir -p ${INITRAMFS}/system/config \
+ ${INITRAMFS}/system/manual \
+ ${INITRAMFS}/system/core \
+ ${INITRAMFS}/system/utils \
+ ${INITRAMFS}/system/scripts \
+ ${INITRAMFS}/system/devices \
+ ${INITRAMFS}/system/info \
+ ${INITRAMFS}/system/process
@cp core/objects/* ${INITRAMFS}/system/core/
- @cp core/init ${INITRAMFS}/system/core/
+ @cp utils/init ${INITRAMFS}/system/core/
@cp smash/smash ${INITRAMFS}/system/core/
@cp utils/* ${INITRAMFS}/system/utils/
@cp man/* ${INITRAMFS}/system/manual/
- @cp config/* ${INITRAMFS}/system/config/
+ @cp -r config/* ${INITRAMFS}/system/config/
@echo Building Initramfs
@cd ${INITRAMFS} && find . | cpio -o --quiet --format=newc > ../initramfs.img
@@ -52,7 +59,7 @@ ${TARGET}/kernel:
@mv linux-${KERNEL_VERSION} ${TARGET}/kernel-src
@cp build_config/linux.config ${TARGET}/kernel-src/.config
@echo Building Kernel
- @$(MAKE) -C ${TARGET}/kernel-src
+ $(MAKE) -C ${TARGET}/kernel-src
@cp ${TARGET}/kernel-src/arch/x86_64/boot/bzImage ${TARGET}/kernel
${TARGET}/syslinux:
diff --git a/build_config/linux.config b/build_config/linux.config
index da8ec37..96eaddd 100644
--- a/build_config/linux.config
+++ b/build_config/linux.config
@@ -1432,9 +1432,9 @@ CONFIG_PCCARD_NONSTATIC=y
#
CONFIG_AUXILIARY_BUS=y
# CONFIG_UEVENT_HELPER is not set
-CONFIG_DEVTMPFS=n
+CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=n
-CONFIG_DEVTMPFS_SAFE=n
+CONFIG_DEVTMPFS_SAFE=y
CONFIG_STANDALONE=y
CONFIG_PREVENT_FIRMWARE_BUILD=y
diff --git a/config/env b/config/env
index fd9169d..001b63e 100644
--- a/config/env
+++ b/config/env
@@ -1,2 +1,3 @@
PATH=/system/core:/system/utils:/system/scripts
MANUALS=/system/manual/
+HOME=/
diff --git a/config/init.hooks/devfs b/config/init.hooks/devfs
new file mode 100755
index 0000000..77ec1cf
--- /dev/null
+++ b/config/init.hooks/devfs
@@ -0,0 +1,3 @@
+#!/system/core/smash
+
+mount devtmpfs none /system/devices
diff --git a/config/init.hooks/procfs b/config/init.hooks/procfs
new file mode 100755
index 0000000..2376461
--- /dev/null
+++ b/config/init.hooks/procfs
@@ -0,0 +1,3 @@
+#!/system/core/smash
+
+mount proc none /system/process
diff --git a/config/init.hooks/shell b/config/init.hooks/shell
new file mode 100755
index 0000000..be975f4
--- /dev/null
+++ b/config/init.hooks/shell
@@ -0,0 +1,6 @@
+#!/system/core/smash
+cd $[HOME]
+
+clear
+read /system/config/banner | mdv
+smash
diff --git a/config/init.hooks/start b/config/init.hooks/start
new file mode 100755
index 0000000..49ed1af
--- /dev/null
+++ b/config/init.hooks/start
@@ -0,0 +1,8 @@
+#!/system/core/smash
+
+cd /system/config/init.hooks/
+
+./devfs
+./sysfs
+./procfs
+./shell
diff --git a/config/init.hooks/stop b/config/init.hooks/stop
new file mode 100755
index 0000000..159fdcb
--- /dev/null
+++ b/config/init.hooks/stop
@@ -0,0 +1,2 @@
+#!/system/core/smash
+poweroff
diff --git a/config/init.hooks/sysfs b/config/init.hooks/sysfs
new file mode 100755
index 0000000..f54d57c
--- /dev/null
+++ b/config/init.hooks/sysfs
@@ -0,0 +1,3 @@
+#!/system/core/smash
+
+mount sysfs none /system/info
diff --git a/core/for.c b/core/for.c
new file mode 100644
index 0000000..d576bf8
--- /dev/null
+++ b/core/for.c
@@ -0,0 +1,45 @@
+#include "../lib/exec/exec.h"
+#include "../lib/sys/fork.h"
+#include "../lib/sys/wait4.h"
+#include "../lib/io/io.h"
+#include "../lib/sys/types.h"
+#include "../lib/cstr/cstr.h"
+
+char line[BUFSIZ];
+
+
+void replace_args(char **argv, char *rep)
+{
+ for (; *argv; ++argv) {
+ if (cstr_compare(*argv, "%") == 0) {
+ *argv = rep;
+ }
+ }
+}
+
+
+int main(int argc, char **argv)
+{
+ if (argc <= 1) {
+ wff(STDERR_FD, "for command [args...] % [args...]")
+ return -1;
+ }
+
+ i64 size;
+ int pid;
+
+ while ((size = get_next_line_from_fd(STDIN_FD, line)) >= 0) {
+
+ pid = fork();
+ if (pid == 0) {
+ replace_args(argv + 1, line);
+ exec((const char**)(argv + 1));
+ wff(STDERR_FD, "command not found: %s", argv[1]);
+ return -1;
+ }
+
+ wait4(pid, 0, 0);
+ }
+
+ return 0;
+}
diff --git a/core/init b/core/init
deleted file mode 100755
index 5802b36..0000000
--- a/core/init
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/system/core/smash
-/system/core/clear
-/system/core/read /system/config/banner | /system/core/mdv
-/system/core/env -f /system/config/env /system/core/smash
-/system/core/powerctl poweroff
diff --git a/core/mount.c b/core/mount.c
index a7a4527..3bbf52b 100644
--- a/core/mount.c
+++ b/core/mount.c
@@ -12,7 +12,7 @@ int main(int argc, char **argv)
int err;
if ((err = mount(argv[2], argv[3], argv[1], 0, 0))) {
- wff(STDERR_FD, "error: %s", errstr[-err]);
+ wff(STDERR_FD, "error: %s\n", errstr[-err]);
return err;
}
diff --git a/core/unmount.c b/core/unmount.c
new file mode 100644
index 0000000..81103d9
--- /dev/null
+++ b/core/unmount.c
@@ -0,0 +1,12 @@
+#include "../lib/io/io.h"
+#include "../lib/sys/unmount.h"
+
+int main(int argc, char **argv)
+{
+ if (argc != 2) {
+ wff(STDERR_FD, "unmount <path>\n");
+ return -1;
+ }
+
+ return unmount(argv[1], 9);
+}
diff --git a/lib/exec/exec.c b/lib/exec/exec.c
new file mode 100644
index 0000000..42fd2c1
--- /dev/null
+++ b/lib/exec/exec.c
@@ -0,0 +1,38 @@
+#include "exec.h"
+#include "../sys/execve.h"
+#include "../env/env.h"
+#include "../cstr/cstr.h"
+#include "../malloc/malloc.h"
+
+int exec(const char **argv)
+{
+ const char *path = getenv("PATH");
+ const char *end;
+ char *filename;
+
+ while (*path) {
+ end = path;
+
+ while (*end && *end != ':') ++end;
+
+ filename = malloc((end - path) + cstr_length(argv[0]) + 2);
+
+ for (int i = 0; i < end - path; ++i)
+ filename[i] = path[i];
+
+ filename[end - path] = '/';
+
+ for (int i = 0; i < cstr_length(argv[0]) + 1; ++i)
+ filename[(end - path) + i + 1] = argv[0][i];
+
+ execve(filename, argv, getenvp());
+ free(filename);
+
+ path = end;
+
+ if (*path == ':')
+ ++path;
+ }
+
+ return execve(argv[0], argv, getenvp());
+}
diff --git a/lib/exec/exec.h b/lib/exec/exec.h
new file mode 100644
index 0000000..fe7e811
--- /dev/null
+++ b/lib/exec/exec.h
@@ -0,0 +1,6 @@
+#ifndef EXEC_H
+#define EXEC_H
+
+int exec(const char **argv);
+
+#endif
diff --git a/lib/sys/unmount.h b/lib/sys/unmount.h
new file mode 100644
index 0000000..1331e65
--- /dev/null
+++ b/lib/sys/unmount.h
@@ -0,0 +1,11 @@
+#ifndef UNMOUNT_H
+#define UNMOUNT_H
+
+#include "syscalls.h"
+
+int unmount(char *pathname, int flags)
+{
+ return syscall(UMOUNT2, pathname, flags);
+}
+
+#endif
diff --git a/smash/exec.c b/smash/exec.c
index 779fccd..8c20126 100644
--- a/smash/exec.c
+++ b/smash/exec.c
@@ -3,7 +3,6 @@
#include "builtin.h"
#include "variable.h"
-#include "../lib/sys/execve.h"
#include "../lib/sys/fork.h"
#include "../lib/sys/wait4.h"
#include "../lib/sys/pipe.h"
@@ -15,6 +14,7 @@
#include "../lib/env/env.h"
#include "../lib/malloc/malloc.h"
#include "../lib/list/list.h"
+#include "../lib/exec/exec.h"
void print_call(char **argv)
{
@@ -25,40 +25,7 @@ void print_call(char **argv)
}
}
-void __execenv(const char **argv)
-{
- const char *path = getenv("PATH");
- const char *end;
- char *filename;
-
- while (*path) {
- end = path;
-
- while (*end && *end != ':') ++end;
-
- filename = malloc((end - path) + cstr_length(argv[0]) + 2);
-
- for (int i = 0; i < end - path; ++i)
- filename[i] = path[i];
-
- filename[end - path] = '/';
-
- for (int i = 0; i < cstr_length(argv[0]) + 1; ++i)
- filename[(end - path) + i + 1] = argv[0][i];
-
- execve(filename, argv, getenvp());
- free(filename);
-
- path = end;
-
- if (*path == ':')
- ++path;
- }
-
- execve(argv[0], argv, getenvp());
-}
-
-void exec(char *line)
+void execute_line(char *line)
{
expression_list_t *exps = new_expression_from_line(line);
expression_list_t *exp = exps;
@@ -96,7 +63,7 @@ void exec(char *line)
close(pipefd[1][PIPE_OUT]);
close(pipefd[1][PIPE_IN]);
- __execenv((const char **)argv);
+ exec((const char **)argv);
wff(STDERR_FD, "command not found: %s\n", argv[0]);
exit(-1);
}
diff --git a/smash/exec.h b/smash/exec.h
index 74780b0..83f826f 100644
--- a/smash/exec.h
+++ b/smash/exec.h
@@ -1,6 +1,6 @@
#ifndef EXEC_H
#define EXEC_H
-void exec(char *line);
+void execute_line(char *line);
#endif
diff --git a/smash/main.c b/smash/main.c
index cf5f47f..efc7bd1 100644
--- a/smash/main.c
+++ b/smash/main.c
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
line_length = cstr_length(line_exec);
if (line_length > 0) {
- exec(line_exec);
+ execute_line(line_exec);
}
cleanup_variable_line_context();
diff --git a/utils/init b/utils/init
new file mode 100755
index 0000000..04dfeed
--- /dev/null
+++ b/utils/init
@@ -0,0 +1,4 @@
+#!/system/core/smash
+
+/system/core/env -f /system/config/env /system/config/init.hooks/start
+/system/core/env -f /system/config/env /system/config/init.hooks/stop