]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
uid: add utmp syscalls and integrate with login
authorTulio A M Mendes <[email protected]>
Thu, 11 Jun 2026 02:58:29 +0000 (23:58 -0300)
committerTulio A M Mendes <[email protected]>
Thu, 11 Jun 2026 02:58:29 +0000 (23:58 -0300)
Implement UID Infrastructure: integração utmp/wtmp (completed).

Added syscalls for utmp management:
- SYSCALL_UTMP_LOGIN (145): register login session
- SYSCALL_UTMP_LOGOUT (146): register logout
- SYSCALL_UTMP_DEAD (147): register process death

Updated kernel syscall.c to handle utmp syscalls.
Updated kernel include/syscall.h with new syscall numbers.
Updated userspace include/syscall.h with new syscall numbers.
Updated userspace include/utmp.h with utmp_login/logout/dead declarations.
Updated userspace src/utmp.c with syscall wrappers.
Updated login command to call utmp_login() with TTY name and hostname.

Test: make test-battery PASS (157/157)

include/syscall.h
src/kernel/syscall.c
user/cmds/login/login.c
user/ulibc/include/syscall.h
user/ulibc/include/utmp.h
user/ulibc/src/utmp.c

index 69a2676e098bdc406380af58b7739eed95439d44..bae5153df60eba08c32e88984466cf7f02ecf44e 100644 (file)
@@ -186,6 +186,9 @@ enum {
     SYSCALL_MADVISE      = 142,
     SYSCALL_EXECVEAT     = 143,
     SYSCALL_REBOOT       = 144,
+    SYSCALL_UTMP_LOGIN   = 145,
+    SYSCALL_UTMP_LOGOUT  = 146,
+    SYSCALL_UTMP_DEAD    = 147,
 };
 
 #endif
index 7bdce47145c2ff8c4f98d5641ca083c10aeeee1d..6735f42f5190f29d9162b3f78667a15a65a59ebb 100644 (file)
@@ -41,6 +41,7 @@
 #include "arch_syscall.h"
 #include "arch_process.h"
 #include "rtc.h"
+#include "utmp.h"
 
 #include <stddef.h>
 
@@ -4447,6 +4448,32 @@ void syscall_handler(struct registers* regs) {
         return;
     }
 
+    if (syscall_no == SYSCALL_UTMP_LOGIN) {
+        /* utmp_login(pid, line, user, host) */
+        uint32_t pid = sc_arg0(regs);
+        const char* line = (const char*)sc_arg1(regs);
+        const char* user = (const char*)sc_arg2(regs);
+        const char* host = (const char*)sc_arg3(regs);
+        sc_ret(regs) = (uint32_t)utmp_login(pid, line, user, host);
+        return;
+    }
+
+    if (syscall_no == SYSCALL_UTMP_LOGOUT) {
+        /* utmp_logout(pid, line) */
+        uint32_t pid = sc_arg0(regs);
+        const char* line = (const char*)sc_arg1(regs);
+        sc_ret(regs) = (uint32_t)utmp_logout(pid, line);
+        return;
+    }
+
+    if (syscall_no == SYSCALL_UTMP_DEAD) {
+        /* utmp_dead(pid, exit_status) */
+        uint32_t pid = sc_arg0(regs);
+        int exit_status = (int)sc_arg1(regs);
+        sc_ret(regs) = (uint32_t)utmp_dead(pid, exit_status);
+        return;
+    }
+
     if (syscall_no == SYSCALL_MPROTECT) {
         uintptr_t addr = (uintptr_t)sc_arg0(regs);
         uint32_t  len  = sc_arg1(regs);
index 851247ce17ede3b6566dd5450286e02fba9bc9a2..dffddceb7a4d09b5e056ae13b76e2fa4e8501199 100644 (file)
@@ -14,6 +14,8 @@
 #include <pwd.h>
 #include <termios.h>
 #include <sys/types.h>
+#include <utmp.h>
+#include <sys/utsname.h>
 
 /* Simple login command */
 int main(int argc, char** argv) {
@@ -25,6 +27,19 @@ int main(int argc, char** argv) {
     while (1) {
         char username[64];
         char password[64];
+        char tty_name[32] = "ttyS0";  /* Default TTY */
+
+        /* Get TTY name from environment or default */
+        char* tty = ttyname(STDIN_FILENO);
+        if (tty) {
+            /* Strip /dev/ prefix if present */
+            if (strncmp(tty, "/dev/", 5) == 0) {
+                strncpy(tty_name, tty + 5, sizeof(tty_name) - 1);
+            } else {
+                strncpy(tty_name, tty, sizeof(tty_name) - 1);
+            }
+            tty_name[sizeof(tty_name) - 1] = '\0';
+        }
 
         /* Prompt for username */
         printf("login: ");
@@ -93,6 +108,15 @@ int main(int argc, char** argv) {
                     chdir(pw->pw_dir);
                 }
 
+                /* Register login in utmp */
+                struct utsname uts;
+                char hostname[64] = "localhost";
+                if (uname(&uts) == 0) {
+                    strncpy(hostname, uts.nodename, sizeof(hostname) - 1);
+                    hostname[sizeof(hostname) - 1] = '\0';
+                }
+                utmp_login(getpid(), tty_name, username, hostname);
+
                 /* Execute shell */
                 char* shell = pw->pw_shell;
                 if (!shell || shell[0] == '\0') {
index c0b27e8ad47ee4fb83431512a8d0ef7e25406060..01b21499c0a7c13c56fcf4dcbccc2155d8d3166f 100644 (file)
@@ -156,6 +156,9 @@ enum {
     SYS_MADVISE = 142,
     SYS_EXECVEAT = 143,
     SYS_REBOOT   = 144,
+    SYS_UTMP_LOGIN  = 145,
+    SYS_UTMP_LOGOUT = 146,
+    SYS_UTMP_DEAD   = 147,
 };
 
 /* Raw syscall wrappers — up to 5 args via INT 0x80 */
index b36b9d93a7dbe108f29a897b954290a766f81b94..7ae5db69cfc0c18e5a6b0b8b89a97a66fd86328d 100644 (file)
@@ -45,4 +45,9 @@ struct utmp*   pututline(const struct utmp* ut);
 void           endutent(void);
 void           utmpname(const char* file);
 
+/* Syscall wrappers for utmp management */
+int utmp_login(uint32_t pid, const char* line, const char* user, const char* host);
+int utmp_logout(uint32_t pid, const char* line);
+int utmp_dead(uint32_t pid, int exit_status);
+
 #endif
index adc56aaff2bf7bdc60e05da6341026e77af18113..147610005b62bac8e51b7b3775c37812cdff5f02 100644 (file)
@@ -8,6 +8,8 @@
  */
 
 #include "utmp.h"
+#include "syscall.h"
+#include "errno.h"
 #include <stddef.h>
 
 /* Stub implementation — AdrOS does not maintain utmp/wtmp records yet.
@@ -46,3 +48,16 @@ void endutent(void) {
 void utmpname(const char* file) {
     (void)file;
 }
+
+/* Syscall wrappers for utmp management */
+int utmp_login(uint32_t pid, const char* line, const char* user, const char* host) {
+    return _syscall4(SYS_UTMP_LOGIN, (int)pid, (int)line, (int)user, (int)host);
+}
+
+int utmp_logout(uint32_t pid, const char* line) {
+    return _syscall2(SYS_UTMP_LOGOUT, (int)pid, (int)line);
+}
+
+int utmp_dead(uint32_t pid, int exit_status) {
+    return _syscall2(SYS_UTMP_DEAD, (int)pid, exit_status);
+}