Compare commits
No commits in common. "bf01b935bd480a80be5389b9938a722917efd94d" and "c77ad5fb34b69a72043830b95e4bdf5fb977603a" have entirely different histories.
bf01b935bd
...
c77ad5fb34
|
@ -97,7 +97,7 @@ namespace Kernel
|
||||||
BAN::ErrorOr<BAN::String> link_target();
|
BAN::ErrorOr<BAN::String> link_target();
|
||||||
|
|
||||||
// Socket API
|
// Socket API
|
||||||
BAN::ErrorOr<long> accept(sockaddr* address, socklen_t* address_len, int flags);
|
BAN::ErrorOr<long> accept(sockaddr* address, socklen_t* address_len);
|
||||||
BAN::ErrorOr<void> bind(const sockaddr* address, socklen_t address_len);
|
BAN::ErrorOr<void> bind(const sockaddr* address, socklen_t address_len);
|
||||||
BAN::ErrorOr<void> connect(const sockaddr* address, socklen_t address_len);
|
BAN::ErrorOr<void> connect(const sockaddr* address, socklen_t address_len);
|
||||||
BAN::ErrorOr<void> listen(int backlog);
|
BAN::ErrorOr<void> listen(int backlog);
|
||||||
|
@ -131,7 +131,7 @@ namespace Kernel
|
||||||
virtual BAN::ErrorOr<BAN::String> link_target_impl() { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<BAN::String> link_target_impl() { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
|
||||||
// Socket API
|
// Socket API
|
||||||
virtual BAN::ErrorOr<long> accept_impl(sockaddr*, socklen_t*, int) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<long> accept_impl(sockaddr*, socklen_t*) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
virtual BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
virtual BAN::ErrorOr<void> listen_impl(int) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<void> listen_impl(int) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) { return BAN::Error::from_errno(ENOTSUP); }
|
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace Kernel
|
||||||
virtual void add_protocol_header(BAN::ByteSpan packet, uint16_t dst_port, PseudoHeader) override;
|
virtual void add_protocol_header(BAN::ByteSpan packet, uint16_t dst_port, PseudoHeader) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BAN::ErrorOr<long> accept_impl(sockaddr*, socklen_t*, int) override;
|
virtual BAN::ErrorOr<long> accept_impl(sockaddr*, socklen_t*) override;
|
||||||
virtual BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) override;
|
virtual BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) override;
|
||||||
virtual BAN::ErrorOr<void> listen_impl(int) override;
|
virtual BAN::ErrorOr<void> listen_impl(int) override;
|
||||||
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) override;
|
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) override;
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace Kernel
|
||||||
static BAN::ErrorOr<BAN::RefPtr<UnixDomainSocket>> create(Socket::Type, const Socket::Info&);
|
static BAN::ErrorOr<BAN::RefPtr<UnixDomainSocket>> create(Socket::Type, const Socket::Info&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual BAN::ErrorOr<long> accept_impl(sockaddr*, socklen_t*, int) override;
|
virtual BAN::ErrorOr<long> accept_impl(sockaddr*, socklen_t*) override;
|
||||||
virtual BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) override;
|
virtual BAN::ErrorOr<void> connect_impl(const sockaddr*, socklen_t) override;
|
||||||
virtual BAN::ErrorOr<void> listen_impl(int) override;
|
virtual BAN::ErrorOr<void> listen_impl(int) override;
|
||||||
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) override;
|
virtual BAN::ErrorOr<void> bind_impl(const sockaddr*, socklen_t) override;
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace Kernel
|
||||||
BAN::ErrorOr<long> sys_getsockopt(int socket, int level, int option_name, void* option_value, socklen_t* option_len);
|
BAN::ErrorOr<long> sys_getsockopt(int socket, int level, int option_name, void* option_value, socklen_t* option_len);
|
||||||
BAN::ErrorOr<long> sys_setsockopt(int socket, int level, int option_name, const void* option_value, socklen_t option_len);
|
BAN::ErrorOr<long> sys_setsockopt(int socket, int level, int option_name, const void* option_value, socklen_t option_len);
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_accept(int socket, sockaddr* address, socklen_t* address_len, int flags);
|
BAN::ErrorOr<long> sys_accept(int socket, sockaddr* address, socklen_t* address_len);
|
||||||
BAN::ErrorOr<long> sys_bind(int socket, const sockaddr* address, socklen_t address_len);
|
BAN::ErrorOr<long> sys_bind(int socket, const sockaddr* address, socklen_t address_len);
|
||||||
BAN::ErrorOr<long> sys_connect(int socket, const sockaddr* address, socklen_t address_len);
|
BAN::ErrorOr<long> sys_connect(int socket, const sockaddr* address, socklen_t address_len);
|
||||||
BAN::ErrorOr<long> sys_listen(int socket, int backlog);
|
BAN::ErrorOr<long> sys_listen(int socket, int backlog);
|
||||||
|
|
|
@ -110,12 +110,12 @@ namespace Kernel
|
||||||
return link_target_impl();
|
return link_target_impl();
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> Inode::accept(sockaddr* address, socklen_t* address_len, int flags)
|
BAN::ErrorOr<long> Inode::accept(sockaddr* address, socklen_t* address_len)
|
||||||
{
|
{
|
||||||
LockGuard _(m_mutex);
|
LockGuard _(m_mutex);
|
||||||
if (!mode().ifsock())
|
if (!mode().ifsock())
|
||||||
return BAN::Error::from_errno(ENOTSOCK);
|
return BAN::Error::from_errno(ENOTSOCK);
|
||||||
return accept_impl(address, address_len, flags);
|
return accept_impl(address, address_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> Inode::bind(const sockaddr* address, socklen_t address_len)
|
BAN::ErrorOr<void> Inode::bind(const sockaddr* address, socklen_t address_len)
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace Kernel
|
||||||
dprintln_if(DEBUG_TCP, "Socket destroyed");
|
dprintln_if(DEBUG_TCP, "Socket destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> TCPSocket::accept_impl(sockaddr* address, socklen_t* address_len, int flags)
|
BAN::ErrorOr<long> TCPSocket::accept_impl(sockaddr* address, socklen_t* address_len)
|
||||||
{
|
{
|
||||||
if (m_state != State::Listen)
|
if (m_state != State::Listen)
|
||||||
return BAN::Error::from_errno(EINVAL);
|
return BAN::Error::from_errno(EINVAL);
|
||||||
|
@ -123,7 +123,7 @@ namespace Kernel
|
||||||
memcpy(address, &connection.target.address, *address_len);
|
memcpy(address, &connection.target.address, *address_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRY(Process::current().open_inode(return_inode, O_RDWR | flags));
|
return TRY(Process::current().open_inode(return_inode, O_RDWR));
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> TCPSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
BAN::ErrorOr<void> TCPSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace Kernel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> UnixDomainSocket::accept_impl(sockaddr* address, socklen_t* address_len, int flags)
|
BAN::ErrorOr<long> UnixDomainSocket::accept_impl(sockaddr* address, socklen_t* address_len)
|
||||||
{
|
{
|
||||||
if (!m_info.has<ConnectionInfo>())
|
if (!m_info.has<ConnectionInfo>())
|
||||||
return BAN::Error::from_errno(EOPNOTSUPP);
|
return BAN::Error::from_errno(EOPNOTSUPP);
|
||||||
|
@ -104,7 +104,7 @@ namespace Kernel
|
||||||
strncpy(sockaddr_un.sun_path, pending->m_bound_path.data(), copy_len);
|
strncpy(sockaddr_un.sun_path, pending->m_bound_path.data(), copy_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRY(Process::current().open_inode(return_inode, O_RDWR | flags));
|
return TRY(Process::current().open_inode(return_inode, O_RDWR));
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> UnixDomainSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
BAN::ErrorOr<void> UnixDomainSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
||||||
|
|
|
@ -106,13 +106,6 @@ namespace Kernel
|
||||||
return BAN::Error::from_errno(EPROTOTYPE);
|
return BAN::Error::from_errno(EPROTOTYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int extra_flags = 0;
|
|
||||||
if (type & SOCK_NONBLOCK)
|
|
||||||
extra_flags |= O_NONBLOCK;
|
|
||||||
if (type & SOCK_CLOEXEC)
|
|
||||||
extra_flags |= O_CLOEXEC;
|
|
||||||
type &= ~(SOCK_NONBLOCK | SOCK_CLOEXEC);
|
|
||||||
|
|
||||||
Socket::Type sock_type;
|
Socket::Type sock_type;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
@ -140,7 +133,7 @@ namespace Kernel
|
||||||
auto socket = TRY(NetworkManager::get().create_socket(sock_domain, sock_type, 0777, m_credentials.euid(), m_credentials.egid()));
|
auto socket = TRY(NetworkManager::get().create_socket(sock_domain, sock_type, 0777, m_credentials.euid(), m_credentials.egid()));
|
||||||
|
|
||||||
int fd = TRY(get_free_fd());
|
int fd = TRY(get_free_fd());
|
||||||
m_open_files[fd] = TRY(BAN::RefPtr<OpenFileDescription>::create(socket, "<socket>"_sv, 0, O_RDWR | extra_flags));
|
m_open_files[fd] = TRY(BAN::RefPtr<OpenFileDescription>::create(socket, "no-path"_sv, 0, O_RDWR));
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1192,14 +1192,12 @@ namespace Kernel
|
||||||
return BAN::Error::from_errno(ENOTSUP);
|
return BAN::Error::from_errno(ENOTSUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> Process::sys_accept(int socket, sockaddr* address, socklen_t* address_len, int flags)
|
BAN::ErrorOr<long> Process::sys_accept(int socket, sockaddr* address, socklen_t* address_len)
|
||||||
{
|
{
|
||||||
if (address && !address_len)
|
if (address && !address_len)
|
||||||
return BAN::Error::from_errno(EINVAL);
|
return BAN::Error::from_errno(EINVAL);
|
||||||
if (!address && address_len)
|
if (!address && address_len)
|
||||||
return BAN::Error::from_errno(EINVAL);
|
return BAN::Error::from_errno(EINVAL);
|
||||||
if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC))
|
|
||||||
return BAN::Error::from_errno(EINVAL);
|
|
||||||
|
|
||||||
LockGuard _(m_process_lock);
|
LockGuard _(m_process_lock);
|
||||||
if (address)
|
if (address)
|
||||||
|
@ -1212,13 +1210,7 @@ namespace Kernel
|
||||||
if (!inode->mode().ifsock())
|
if (!inode->mode().ifsock())
|
||||||
return BAN::Error::from_errno(ENOTSOCK);
|
return BAN::Error::from_errno(ENOTSOCK);
|
||||||
|
|
||||||
int open_flags = 0;
|
return TRY(inode->accept(address, address_len));
|
||||||
if (flags & SOCK_NONBLOCK)
|
|
||||||
open_flags |= O_NONBLOCK;
|
|
||||||
if (flags & SOCK_CLOEXEC)
|
|
||||||
open_flags |= O_CLOEXEC;
|
|
||||||
|
|
||||||
return TRY(inode->accept(address, address_len, open_flags));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> Process::sys_bind(int socket, const sockaddr* address, socklen_t address_len)
|
BAN::ErrorOr<long> Process::sys_bind(int socket, const sockaddr* address, socklen_t address_len)
|
||||||
|
|
|
@ -71,8 +71,6 @@ struct linger
|
||||||
#define SOCK_RAW 2
|
#define SOCK_RAW 2
|
||||||
#define SOCK_SEQPACKET 3
|
#define SOCK_SEQPACKET 3
|
||||||
#define SOCK_STREAM 4
|
#define SOCK_STREAM 4
|
||||||
#define SOCK_CLOEXEC 0x10
|
|
||||||
#define SOCK_NONBLOCK 0x20
|
|
||||||
|
|
||||||
#define SOL_SOCKET 1
|
#define SOL_SOCKET 1
|
||||||
|
|
||||||
|
@ -139,7 +137,6 @@ struct sys_recvfrom_t
|
||||||
};
|
};
|
||||||
|
|
||||||
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
|
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
|
||||||
int accept4(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len, int flags);
|
|
||||||
int bind(int socket, const struct sockaddr* address, socklen_t address_len);
|
int bind(int socket, const struct sockaddr* address, socklen_t address_len);
|
||||||
int connect(int socket, const struct sockaddr* address, socklen_t address_len);
|
int connect(int socket, const struct sockaddr* address, socklen_t address_len);
|
||||||
int getpeername(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
|
int getpeername(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
|
||||||
|
|
|
@ -4,12 +4,7 @@
|
||||||
|
|
||||||
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||||
{
|
{
|
||||||
return accept4(socket, address, address_len, 0);
|
return syscall(SYS_ACCEPT, socket, address, address_len);
|
||||||
}
|
|
||||||
|
|
||||||
int accept4(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len, int flags)
|
|
||||||
{
|
|
||||||
return syscall(SYS_ACCEPT, socket, address, address_len, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int bind(int socket, const struct sockaddr* address, socklen_t address_len)
|
int bind(int socket, const struct sockaddr* address, socklen_t address_len)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
Framebuffer open_framebuffer()
|
Framebuffer open_framebuffer()
|
||||||
{
|
{
|
||||||
int framebuffer_fd = open("/dev/fb0", O_RDWR | O_CLOEXEC);
|
int framebuffer_fd = open("/dev/fb0", O_RDWR);
|
||||||
if (framebuffer_fd == -1)
|
if (framebuffer_fd == -1)
|
||||||
{
|
{
|
||||||
perror("open");
|
perror("open");
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
WindowServer::WindowServer(Framebuffer& framebuffer)
|
WindowServer::WindowServer(Framebuffer& framebuffer)
|
||||||
: m_framebuffer(framebuffer)
|
: m_framebuffer(framebuffer)
|
||||||
, m_cursor({ framebuffer.width / 2, framebuffer.height / 2 })
|
, m_cursor({ framebuffer.width / 2, framebuffer.height / 2 })
|
||||||
|
@ -137,27 +135,13 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop WindowServer with mod+shift+E
|
// Quick hack to stop the window server
|
||||||
if (m_is_mod_key_held && event.pressed() && event.shift() && event.key == LibInput::Key::E)
|
if (event.pressed() && event.key == LibInput::Key::Escape)
|
||||||
{
|
{
|
||||||
m_is_stopped = true;
|
m_is_stopped = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start terminal with mod+Enter
|
|
||||||
if (m_is_mod_key_held && event.pressed() && event.key == LibInput::Key::Enter)
|
|
||||||
{
|
|
||||||
pid_t pid = fork();
|
|
||||||
if (pid == 0)
|
|
||||||
{
|
|
||||||
execl("/usr/bin/Terminal", "Terminal", nullptr);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (pid == -1)
|
|
||||||
perror("fork");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kill window with mod+Q
|
// Kill window with mod+Q
|
||||||
if (m_is_mod_key_held && event.pressed() && event.key == LibInput::Key::Q)
|
if (m_is_mod_key_held && event.pressed() && event.key == LibInput::Key::Q)
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,7 +104,7 @@ int open_server_fd()
|
||||||
if (stat(LibGUI::s_window_server_socket.data(), &st) != -1)
|
if (stat(LibGUI::s_window_server_socket.data(), &st) != -1)
|
||||||
unlink(LibGUI::s_window_server_socket.data());
|
unlink(LibGUI::s_window_server_socket.data());
|
||||||
|
|
||||||
int server_fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
|
int server_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
|
||||||
if (server_fd == -1)
|
if (server_fd == -1)
|
||||||
{
|
{
|
||||||
perror("socket");
|
perror("socket");
|
||||||
|
@ -158,11 +158,11 @@ int main()
|
||||||
MUST(LibInput::KeyboardLayout::initialize());
|
MUST(LibInput::KeyboardLayout::initialize());
|
||||||
MUST(LibInput::KeyboardLayout::get().load_from_file("/usr/share/keymaps/us.keymap"_sv));
|
MUST(LibInput::KeyboardLayout::get().load_from_file("/usr/share/keymaps/us.keymap"_sv));
|
||||||
|
|
||||||
int keyboard_fd = open("/dev/keyboard", O_RDONLY | O_CLOEXEC);
|
int keyboard_fd = open("/dev/keyboard", O_RDONLY);
|
||||||
if (keyboard_fd == -1)
|
if (keyboard_fd == -1)
|
||||||
perror("open");
|
perror("open");
|
||||||
|
|
||||||
int mouse_fd = open("/dev/mouse", O_RDONLY | O_CLOEXEC);
|
int mouse_fd = open("/dev/mouse", O_RDONLY);
|
||||||
if (mouse_fd == -1)
|
if (mouse_fd == -1)
|
||||||
perror("open");
|
perror("open");
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ int main()
|
||||||
|
|
||||||
if (FD_ISSET(server_fd, &fds))
|
if (FD_ISSET(server_fd, &fds))
|
||||||
{
|
{
|
||||||
int window_fd = accept4(server_fd, nullptr, nullptr, SOCK_CLOEXEC);
|
int window_fd = accept(server_fd, nullptr, nullptr);
|
||||||
if (window_fd == -1)
|
if (window_fd == -1)
|
||||||
{
|
{
|
||||||
dwarnln("accept: {}", strerror(errno));
|
dwarnln("accept: {}", strerror(errno));
|
||||||
|
|
|
@ -114,12 +114,7 @@ int main()
|
||||||
setenv("HOME", pwd->pw_dir, 1);
|
setenv("HOME", pwd->pw_dir, 1);
|
||||||
chdir(pwd->pw_dir);
|
chdir(pwd->pw_dir);
|
||||||
|
|
||||||
char shell_path[PATH_MAX];
|
execl(pwd->pw_shell, pwd->pw_shell, nullptr);
|
||||||
strcpy(shell_path, pwd->pw_shell);
|
|
||||||
|
|
||||||
endpwent();
|
|
||||||
|
|
||||||
execl(shell_path, shell_path, nullptr);
|
|
||||||
perror("execl");
|
perror("execl");
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Reference in New Issue