feat: capability list to enable greater flexibility of devices
[lunaix-os.git] / lunaix-os / usr / init / init.c
index 1b80f495d05770b7dca832831a5b625f6f8733d5..0a2f5418a9de84eca57dcd9af649b7360ed167c7 100644 (file)
@@ -2,6 +2,7 @@
 #include <fcntl.h>
 #include <lunaix/lunaix.h>
 #include <lunaix/mount.h>
+#include <termios.h>
 #include <stdio.h>
 #include <unistd.h>
 
         }                                                                      \
     } while (0)
 
+#define check(statement)                                      \
+    do {                                                                       \
+        int err = 0;                                                           \
+        if ((err = (statement))) {                            \
+            syslog(2, #statement " failed: %d", err);   \
+            return err;                                                        \
+        }                                                                      \
+    } while (0)
+
+int
+init_termios(int fd) {
+    struct termios term;
+
+    check(tcgetattr(fd, &term));
+
+    term.c_lflag = ICANON | IEXTEN | ISIG | ECHO | ECHOE | ECHONL;
+    term.c_iflag = ICRNL | IGNBRK;
+    term.c_oflag = ONLCR | OPOST;
+    term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
+    term.c_cc[VERASE] = 0x08;
+
+    check(tcsetattr(fd, 0, &term));
+
+    return 0;
+}
+
 int
 main(int argc, const char** argv)
 {
@@ -32,6 +59,8 @@ main(int argc, const char** argv)
         return err;
     }
 
+    check(init_termios(err));
+
     if ((err = dup(err)) < 0) {
         syslog(2, "fail to setup tty i/o (%d)\n", errno);
         return err;