Compare commits

...

3 Commits

Author SHA1 Message Date
Bananymous 991ae4383a Kernel/LibC: Implement fchmod 2024-08-25 15:07:42 +03:00
Bananymous 2ce7205c80 Kernel: Add command line option to disable debug printing
The whole system can crash when debug output and tty output are done at
the same time. This patch is just a hack to prevent the crash :D
2024-08-25 15:02:15 +03:00
Bananymous bec3e8654f Shell: Implement escaping quotes in quoted strings 2024-08-24 17:13:50 +03:00
7 changed files with 37 additions and 4 deletions

View File

@ -119,8 +119,9 @@ namespace Kernel
BAN::ErrorOr<long> sys_pread(int fd, void* buffer, size_t count, off_t offset); BAN::ErrorOr<long> sys_pread(int fd, void* buffer, size_t count, off_t offset);
BAN::ErrorOr<long> sys_chmod(const char*, mode_t); BAN::ErrorOr<long> sys_chmod(const char* path, mode_t mode);
BAN::ErrorOr<long> sys_chown(const char*, uid_t, gid_t); BAN::ErrorOr<long> sys_fchmod(int fildes, mode_t mode);
BAN::ErrorOr<long> sys_chown(const char* path, uid_t uid, gid_t gid);
BAN::ErrorOr<long> sys_socket(int domain, int type, int protocol); BAN::ErrorOr<long> sys_socket(int domain, int type, int protocol);
BAN::ErrorOr<long> sys_getsockname(int socket, sockaddr* address, socklen_t* address_len); BAN::ErrorOr<long> sys_getsockname(int socket, sockaddr* address, socklen_t* address_len);

View File

@ -8,6 +8,7 @@
#include <ctype.h> #include <ctype.h>
bool g_disable_debug = false;
extern Kernel::TerminalDriver* g_terminal_driver; extern Kernel::TerminalDriver* g_terminal_driver;
namespace Debug namespace Debug
@ -70,6 +71,9 @@ namespace Debug
{ {
using namespace Kernel; using namespace Kernel;
if (g_disable_debug)
return;
if (Kernel::Serial::has_devices()) if (Kernel::Serial::has_devices())
return Kernel::Serial::putchar_any(ch); return Kernel::Serial::putchar_any(ch);
if (Kernel::TTY::is_initialized()) if (Kernel::TTY::is_initialized())

View File

@ -1103,6 +1103,18 @@ namespace Kernel
return 0; return 0;
} }
BAN::ErrorOr<long> Process::sys_fchmod(int fildes, mode_t mode)
{
if (mode & S_IFMASK)
return BAN::Error::from_errno(EINVAL);
LockGuard _(m_process_lock);
auto inode = TRY(m_open_file_descriptors.inode_of(fildes));
TRY(inode->chmod(mode));
return 0;
}
BAN::ErrorOr<long> Process::sys_chown(const char* path, uid_t uid, gid_t gid) BAN::ErrorOr<long> Process::sys_chown(const char* path, uid_t uid, gid_t gid)
{ {
LockGuard _(m_process_lock); LockGuard _(m_process_lock);

View File

@ -65,6 +65,7 @@ static bool should_disable_serial(BAN::StringView full_command_line)
return false; return false;
} }
extern bool g_disable_debug;
static ParsedCommandLine cmdline; static ParsedCommandLine cmdline;
static void parse_command_line() static void parse_command_line()
@ -81,6 +82,8 @@ static void parse_command_line()
cmdline.disable_smp = true; cmdline.disable_smp = true;
else if (argument == "nousb") else if (argument == "nousb")
cmdline.disable_usb = true; cmdline.disable_usb = true;
else if (argument == "nodebug")
g_disable_debug = true;
else if (argument.starts_with("ps2=")) else if (argument.starts_with("ps2="))
{ {
if (argument.size() != 5 || !isdigit(argument[4])) if (argument.size() != 5 || !isdigit(argument[4]))

View File

@ -55,6 +55,7 @@ __BEGIN_DECLS
O(SYS_TTY_CTRL, tty_ctrl) \ O(SYS_TTY_CTRL, tty_ctrl) \
O(SYS_POWEROFF, poweroff) \ O(SYS_POWEROFF, poweroff) \
O(SYS_CHMOD, chmod) \ O(SYS_CHMOD, chmod) \
O(SYS_FCHMOD, fchmod) \
O(SYS_CREATE, create) \ O(SYS_CREATE, create) \
O(SYS_CREATE_DIR, create_dir) \ O(SYS_CREATE_DIR, create_dir) \
O(SYS_UNLINK, unlink) \ O(SYS_UNLINK, unlink) \

View File

@ -13,9 +13,9 @@ int chmod(const char* path, mode_t mode)
return syscall(SYS_CHMOD, path, mode); return syscall(SYS_CHMOD, path, mode);
} }
int fchmod(int, mode_t) int fchmod(int fildes, mode_t mode)
{ {
ASSERT_NOT_REACHED(); return syscall(SYS_FCHMOD, fildes, mode);
} }
int fstat(int fildes, struct stat* buf) int fstat(int fildes, struct stat* buf)

View File

@ -197,6 +197,18 @@ BAN::Vector<BAN::Vector<BAN::String>> parse_command(BAN::StringView command_view
{ {
char c = command_view[i]; char c = command_view[i];
if (i + 1 < command_view.size() && c == '\\')
{
char next = command_view[i + 1];
if (next == '\'' || next == '"')
{
if (i + 1 < command_view.size())
MUST(current_arg.push_back(next));
i++;
continue;
}
}
switch (state) switch (state)
{ {
case State::Normal: case State::Normal: