diff options
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | build_config/linux.config (renamed from config/linux.config) | 0 | ||||
| -rw-r--r-- | build_config/syslinux.cfg (renamed from config/syslinux.cfg) | 0 | ||||
| -rw-r--r-- | config/banner (renamed from etc/banner) | 0 | ||||
| -rw-r--r-- | config/env | 2 | ||||
| -rw-r--r-- | core/env.c | 20 | ||||
| -rw-r--r-- | etc/env | 1 | ||||
| -rw-r--r-- | lib/io/io.c | 48 | ||||
| -rw-r--r-- | lib/io/io.h | 1 | ||||
| -rw-r--r-- | lib/sys/types.h | 2 | ||||
| -rw-r--r-- | smash/main.c | 47 | ||||
| -rwxr-xr-x | utils/init | 4 | ||||
| -rwxr-xr-x | utils/rtm | 2 |
13 files changed, 72 insertions, 65 deletions
@@ -34,12 +34,12 @@ target: initramfs: target core smash @echo Installing Initramfs - @mkdir -p ${INITRAMFS}/bin ${INITRAMFS}/etc ${INITRAMFS}/shr/man + @mkdir -p ${INITRAMFS}/bin ${INITRAMFS}/system/config ${INITRAMFS}/system/manual @cp core/objects/* ${INITRAMFS}/bin/ - @cp man/* ${INITRAMFS}/shr/man/ + @cp man/* ${INITRAMFS}/system/manual/ @cp smash/smash ${INITRAMFS}/bin/ @cp utils/* ${INITRAMFS}/bin/ - @cp etc/* ${INITRAMFS}/etc/ + @cp config/* ${INITRAMFS}/system/config @mv ${INITRAMFS}/bin/init ${INITRAMFS}/init @echo Building Initramfs @cd ${INITRAMFS} && find . | cpio -o --quiet --format=newc > ../initramfs.img @@ -50,7 +50,7 @@ ${TARGET}/kernel: @echo Extracting Kernel @tar -xf ${TARGET}/kernel.tar.gz @mv linux-${KERNEL_VERSION} ${TARGET}/kernel-src - @cp config/linux.config ${TARGET}/kernel-src/.config + @cp build_config/linux.config ${TARGET}/kernel-src/.config @echo Building Kernel @$(MAKE) -C ${TARGET}/kernel-src > /dev/null @cp ${TARGET}/kernel-src/arch/x86_64/boot/bzImage ${TARGET}/kernel @@ -68,7 +68,7 @@ rootfs: target initramfs ${TARGET}/syslinux ${TARGET}/kernel @mkdir -p ${ROOTFS}/syslinux ${ROOTFS}/images/rex/ @cp ${TARGET}/initramfs.img ${ROOTFS}/images/rex/boot.img @cp ${TARGET}/kernel ${ROOTFS}/images/rex/kernel - @cp config/syslinux.cfg ${ROOTFS}/syslinux/syslinux.cfg + @cp build_config/syslinux.cfg ${ROOTFS}/syslinux/syslinux.cfg @cp ${TARGET}/syslinux/bios/core/isolinux.bin \ ${TARGET}/syslinux/bios/com32/elflink/ldlinux/ldlinux.c32 \ ${TARGET}/syslinux/bios/com32/libutil/libutil.c32 \ diff --git a/config/linux.config b/build_config/linux.config index 367246f..367246f 100644 --- a/config/linux.config +++ b/build_config/linux.config diff --git a/config/syslinux.cfg b/build_config/syslinux.cfg index 5e0dbeb..5e0dbeb 100644 --- a/config/syslinux.cfg +++ b/build_config/syslinux.cfg diff --git a/etc/banner b/config/banner index 655aa5b..655aa5b 100644 --- a/etc/banner +++ b/config/banner diff --git a/config/env b/config/env new file mode 100644 index 0000000..6ae1b6f --- /dev/null +++ b/config/env @@ -0,0 +1,2 @@ +PATH=/bin/ +MANUALS=/system/manual/ @@ -2,13 +2,14 @@ #include "../lib/sys/sizes.h" #include "../lib/sys/execve.h" #include "../lib/env/env.h" +#include "../lib/sys/types.h" +#include "../lib/cstr/cstr.h" -#define BUFSIZ 1024 char buf[BUFSIZ] = ""; - void add_to_env(char *line, u64 linenumber) { + char *begin = line; char *key; char *value; @@ -17,7 +18,7 @@ void add_to_env(char *line, u64 linenumber) while (*line != '=' && *line) ++line; if (!*line) { - wff(STDERR_FD, "error: %i no valid environment line\n", linenumber); + wff(STDERR_FD, "error: '%s' %i no valid environment line\n", begin, linenumber); return; } @@ -46,7 +47,7 @@ int main(int argc, const char **argv) } u64 fd = STDIN_FD; - u64 size; + i64 size; char *p; u64 linenumber = 1; const char **execargv = argv + 1; @@ -65,13 +66,10 @@ int main(int argc, const char **argv) } } - while ((size = read(fd, buf, BUFSIZ - 1))) { - p = buf; - - while (p < buf + BUFSIZ && *p != '\n') ++p; - *(++p) = 0; - - add_to_env(buf, linenumber++); + while ((size = get_next_line_from_fd(fd, buf)) >= 0) { + if (cstr_length(buf)) { + add_to_env(buf, linenumber++); + } } execve(execargv[0], execargv, getenvp()); diff --git a/etc/env b/etc/env deleted file mode 100644 index 9448162..0000000 --- a/etc/env +++ /dev/null @@ -1 +0,0 @@ -PATH=/bin/ diff --git a/lib/io/io.c b/lib/io/io.c index 2aefe1a..d8e8d18 100644 --- a/lib/io/io.c +++ b/lib/io/io.c @@ -2,6 +2,7 @@ #include "../cstr/cstr.h" #include "../aec/aec.h" +#include "../sys/types.h" void __wstdn(const char *buf, u64 n) { @@ -92,6 +93,53 @@ void wff__(unsigned int fd, const char *buf, const void **args) write(fd, start, buf - start); } + +char __buf[BUFSIZ] = { 0 }; + +int get_next_line_from_fd(unsigned int fd, char *linebuf) +{ + u64 size = 0; + char *line = __buf; + + while (*line && *line != '\n') line++; + + if (!*line) { + size = cstr_length(__buf); + i64 s = read(fd, __buf + size, BUFSIZ - size - 1); + + if (s == 0 && size == 0) { + return -1; + } else if (s == 0) { + for (int i = 0; i < size; ++i) linebuf[i] = __buf[i]; + __buf[0] = 0; + return size; + } + + __buf[s] = 0; + while (*line && *line != '\n') line++; + + if (!*line) { + return -2; + } + } + + *line = 0; + ++line; + + size = cstr_length(__buf); + for (int i = 0; __buf[i]; ++i) linebuf[i] = __buf[i]; + linebuf[size] = 0; + + int i = 0; + for (; *line; ++i) { + __buf[i] = *line; + ++line; + } + __buf[i] = 0; + + return size; +} + #ifdef IO_LIB_UNIT_TEST int main() { wstdf("%s %S%F%s%S\n", "hallo", SGR_UNDERLINE, COLOR_RED, "welt", SGR_RESET); diff --git a/lib/io/io.h b/lib/io/io.h index 6bf0a3b..887d911 100644 --- a/lib/io/io.h +++ b/lib/io/io.h @@ -7,6 +7,7 @@ void wstd(const char *buf); unsigned long rstd(char *buf, unsigned long count); void wf(unsigned int fd, char *buf); void putchar(const char c); +int get_next_line_from_fd(unsigned int fd, char *buf); void wstdf__(const char *buf, const void **args); void wff__(unsigned int fd, const char *buf, const void **args); diff --git a/lib/sys/types.h b/lib/sys/types.h index 0aafec5..de8ce80 100644 --- a/lib/sys/types.h +++ b/lib/sys/types.h @@ -3,6 +3,8 @@ #include "sizes.h" +#define BUFSIZ 16384 + typedef u64 dev_t; typedef u32 mode_t; diff --git a/smash/main.c b/smash/main.c index 645f4eb..e36744d 100644 --- a/smash/main.c +++ b/smash/main.c @@ -7,54 +7,11 @@ #include "../lib/sys/dup2.h" #include "../lib/sys/exit.h" #include "../lib/malloc/malloc.h" +#include "../lib/sys/types.h" #include "../lib/io/io.h" #include "../lib/sys/errno.h" -#define BUFSIZ 16384 - -char buf[BUFSIZ] = {0}; -int io_getline(int fd, char *linebuf) -{ - u64 size = 0; - char *line = buf; - - while (*line && *line != '\n') line++; - - if (!*line) { - u64 s = cstr_length(buf); - s = read(fd, buf + s, BUFSIZ - s - 1); - - if (s == 0) { - return -1; - } - - buf[s] = 0; - while (*line && *line != '\n') line++; - - if (!*line) { - wf(STDERR_FD, "line too long to handle, exiting.\n"); - exit(-1); - } - } - - *line = 0; - ++line; - - size = cstr_length(buf); - for (int i = 0; buf[i]; ++i) linebuf[i] = buf[i]; - linebuf[size] = 0; - - buf[0] = 0; - for (int i = 0; *line; ++i) { - buf[i] = *line; - buf[i + 1] = 0; - ++line; - } - - return size; -} - int main(int argc, char *argv[]) { char prompt[] = "$ "; @@ -78,7 +35,7 @@ int main(int argc, char *argv[]) if (fd == STDIN_FD) wstd(prompt); - line_length = io_getline(fd, linebuf); + line_length = get_next_line_from_fd(fd, linebuf); if (line_length == -1) { break; @@ -1,5 +1,5 @@ #!/bin/smash /bin/clear -/bin/read /etc/banner | /bin/mdv -/bin/env -f /etc/env /bin/smash +/bin/read /system/config/banner | /bin/mdv +/bin/env -f /system/config/env /bin/smash /bin/powerctl poweroff @@ -1,2 +1,2 @@ #!/bin/smash -read /shr/man/$[1].md | mdv | pager +read $[MANUALS]/$[1].md | mdv | pager |