Compare commits

..

4 Commits

Author SHA1 Message Date
27eacac19c
kernel: Add a blinking cursor to the terminal
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-04 11:44:35 +02:00
c5e11bb6cf
apps+base+libc: Use /usr/bin paths instead of /bin everywhere 2023-09-04 11:44:10 +02:00
3c9b2c49aa
init: Fix wrong log message 2023-09-04 11:43:36 +02:00
1528c772fd
kernel: Store the full command line of a process 2023-09-04 11:43:11 +02:00
14 changed files with 85 additions and 20 deletions

View File

@ -261,7 +261,7 @@ static Result<void> load_service(const os::Path& path)
if (service.command.is_empty())
{
do_log("[init] service file is missing 'Command' or 'Script' entry, aborting!\n");
do_log("[init] service file is missing 'Command' entry, aborting!\n");
return {};
}

View File

@ -45,7 +45,7 @@ Result<int> luna_main(int argc, char** argv)
username = name.view();
}
execl("/bin/su", "login", "-lp", "--", username.chars(), nullptr);
execl("/usr/bin/su", "login", "-lp", "--", username.chars(), nullptr);
perror("su");
return 1;

View File

@ -72,10 +72,9 @@ int main()
// Now, mount the /dev file system on the new root.
mount_devfs();
setenv("PATH", "/sbin:/usr/bin", 1);
char* argv[] = { "init", nullptr };
char* argv[] = { "/usr/bin/init", nullptr };
char* envp[] = { nullptr };
execvpe(argv[0], argv, envp);
execve(argv[0], argv, envp);
fail_errno("Failed to execute init");

View File

@ -127,7 +127,7 @@ Result<int> luna_main(int argc, char** argv)
{
chdir(entry->pw_dir);
clearenv();
setenv("PATH", "/bin:/sbin", 1);
setenv("PATH", "/usr/bin:/usr/local/bin", 1);
setpgid(0, 0);
}

View File

@ -1,2 +1,2 @@
root:toor:0:0:Administrator:/:/bin/sh
selene:moon:1000:1000:User:/home/selene:/bin/sh
root:toor:0:0:Administrator:/:/usr/bin/sh
selene:moon:1000:1000:User:/home/selene:/usr/bin/sh

View File

@ -161,7 +161,11 @@ void io_thread()
static void timer_interrupt(Registers* regs, void*)
{
Timer::tick();
if (should_invoke_scheduler()) Scheduler::invoke(regs);
if (should_invoke_scheduler())
{
Scheduler::invoke(regs);
TextConsole::tick_cursor();
}
}
static void keyboard_interrupt(Registers*, void*)

View File

@ -246,6 +246,9 @@ Result<u64> ConsoleDevice::ioctl(int request, void* arg)
}
case TTYSETGFX: {
s_is_in_graphical_mode = (bool)arg;
if (!s_is_in_graphical_mode) TextConsole::enable_cursor();
else
TextConsole::disable_cursor();
return 0;
}
default: return err(EINVAL);

View File

@ -59,6 +59,8 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
Vector<String> envp;
if (args[2]) envp = TRY(copy_string_vector_from_userspace(args[2]));
String cmdline = TRY(String::join(argv, " "));
if ((calculate_userspace_stack_size(argv) + calculate_userspace_stack_size(envp)) > MAX_ARGV_STACK_SIZE)
return err(E2BIG);
@ -115,7 +117,7 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
if (is_setuid) current->auth.euid = current->auth.suid = inode->metadata().uid;
if (is_setgid) current->auth.egid = current->auth.sgid = inode->metadata().gid;
current->name = path.chars();
current->cmdline = cmdline.chars();
image->apply(current);
@ -159,7 +161,7 @@ Result<u64> sys_fork(Registers* regs, SyscallArgs)
thread->state = ThreadState::Runnable;
thread->is_kernel = false;
thread->fp_data.save();
thread->name = current->name;
thread->cmdline = current->cmdline;
thread->auth = current->auth;
thread->current_directory = current->current_directory;
thread->current_directory_path = move(current_directory_path);

View File

@ -35,7 +35,7 @@ Result<u64> sys_pstat(Registers*, SyscallArgs args)
set_timespec(proc.ps_time, thread->user_ticks_self + thread->kernel_ticks_self);
set_timespec(proc.ps_ktime, thread->kernel_ticks_self);
set_timespec(proc.ps_utime, thread->kernel_ticks_children);
strlcpy(proc.ps_name, thread->name.chars(), sizeof(proc.ps_name));
strlcpy(proc.ps_name, thread->cmdline.chars(), sizeof(proc.ps_name));
strlcpy(proc.ps_cwd, thread->current_directory_path.is_empty() ? "/" : thread->current_directory_path.chars(),
sizeof(proc.ps_cwd));

View File

@ -27,7 +27,7 @@ namespace Scheduler
g_idle.state = ThreadState::Idle;
g_idle.is_kernel = true;
g_idle.parent = nullptr;
g_idle.name = "[idle]";
g_idle.cmdline = "[idle]";
g_idle.active_directory = nullptr;
g_idle.ticks_left = 1;
@ -96,7 +96,7 @@ namespace Scheduler
thread->stack = thread_stack;
thread->name = name;
thread->cmdline = name;
thread->is_kernel = true;
thread->active_directory = MMU::kernel_page_directory();
@ -148,7 +148,7 @@ namespace Scheduler
thread->is_kernel = false;
thread->id = 1;
thread->pgid = 1;
thread->name = name;
thread->cmdline = name;
thread->auth = Credentials { .uid = 0, .euid = 0, .suid = 0, .gid = 0, .egid = 0, .sgid = 0 };
Vector<String> args;
@ -374,7 +374,7 @@ namespace Scheduler
{
kdbgln("%p %c [%-20s] %4d, parent = (%-18p,%d), state = %d, ticks: (k:%04zu,u:%04zu), status = "
"%d, cwd = %s",
thread, thread->is_kernel ? 'k' : 'u', thread->name.chars(), thread->id, thread->parent,
thread, thread->is_kernel ? 'k' : 'u', thread->cmdline.chars(), thread->id, thread->parent,
thread->parent ? thread->parent->id : 0, (int)thread->state, thread->kernel_ticks_self,
thread->user_ticks_self, thread->status,
thread->current_directory_path.is_empty() ? "/" : thread->current_directory_path.chars());

View File

@ -123,7 +123,7 @@ struct Thread : public LinkedListNode<Thread>
mode_t umask { 0 };
StaticString<128> name;
StaticString<128> cmdline;
String current_directory_path = {};
SharedPtr<VFS::Inode> current_directory = {};

View File

@ -47,6 +47,11 @@ static bool bold = false;
static u32 g_x_position = 0;
static u32 g_y_position = 0;
static constexpr int CURSOR_TIMEOUT = 500;
static int current_cursor_timeout = CURSOR_TIMEOUT;
static bool cursor_activated = true;
static bool cursor_enabled = true;
static Utf8StateDecoder utf8_decoder;
static Option<EscapeSequenceParser> escape_sequence_parser;
@ -82,7 +87,7 @@ static void scroll()
static bool should_scroll()
{
return (g_y_position + FONT_HEIGHT) >= Framebuffer::height();
return g_y_position >= Framebuffer::height();
}
static void next_line()
@ -106,6 +111,11 @@ static void erase_current_char()
Framebuffer::rect(g_x_position, g_y_position, FONT_WIDTH, FONT_HEIGHT, BLACK);
}
static void draw_cursor()
{
Framebuffer::rect(g_x_position, g_y_position, FONT_WIDTH, FONT_HEIGHT, WHITE);
}
static bool at_end_of_screen()
{
return (g_x_position + FONT_WIDTH) > Framebuffer::width();
@ -323,6 +333,11 @@ namespace TextConsole
if (handle_escape_sequence(c)) return;
}
// Erase the current cursor.
if (cursor_enabled) erase_current_char();
bool should_draw_cursor = cursor_enabled;
switch (c)
{
case L'\n': {
@ -345,7 +360,10 @@ namespace TextConsole
case L'\x1b':
case L'\x9b':
case L'\x90':
case L'\x9d': escape_sequence_parser = EscapeSequenceParser { (u8)c }; break;
case L'\x9d':
escape_sequence_parser = EscapeSequenceParser { (u8)c };
should_draw_cursor = false;
break;
default: {
if (_iscntrl(c)) return;
putwchar_at(c, g_x_position, g_y_position);
@ -358,6 +376,42 @@ namespace TextConsole
break;
}
}
if (should_draw_cursor)
{
current_cursor_timeout = CURSOR_TIMEOUT;
cursor_activated = true;
draw_cursor();
}
}
void tick_cursor()
{
if (!cursor_enabled) return;
current_cursor_timeout--;
if (current_cursor_timeout == 0)
{
current_cursor_timeout = CURSOR_TIMEOUT;
cursor_activated = !cursor_activated;
if (cursor_activated) draw_cursor();
else
erase_current_char();
}
}
void disable_cursor()
{
cursor_enabled = false;
}
void enable_cursor()
{
cursor_enabled = true;
cursor_activated = true;
current_cursor_timeout = CURSOR_TIMEOUT;
draw_cursor();
}
Result<void> putchar(char c)

View File

@ -19,6 +19,9 @@ namespace TextConsole
Result<void> println(const char* str);
void wprintln(const wchar_t* str);
Result<usize> printf(const char* format, ...) _format(1, 2);
void tick_cursor();
void disable_cursor();
void enable_cursor();
u16 rows();
u16 cols();

View File

@ -23,7 +23,7 @@ static Result<int> try_execvpe(const char* name, char* const* argv, char* const*
if (strchr(name, '/')) return execve(name, argv, envp);
char* path = getenv("PATH");
if (!path) path = const_cast<char*>("/bin:/sbin");
if (!path) path = const_cast<char*>("/usr/bin:/usr/local/bin");
Vector<String> paths = TRY(StringView { path }.split(":"));