Compare commits
6 commits
da24b330e0
...
bab61702f3
Author | SHA1 | Date | |
---|---|---|---|
|
bab61702f3 | ||
|
bf1d15957e | ||
|
ecd5217da8 | ||
|
735dffd029 | ||
|
8b0911c672 | ||
|
b6f2333bdd |
8 changed files with 74 additions and 35 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -270,6 +271,14 @@ bool editor_save_file(struct editor* editor, const char* path)
|
||||||
return fclose(fp) != EOF;
|
return fclose(fp) != EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile sig_atomic_t had_sigwinch = 0;
|
||||||
|
|
||||||
|
static void sigwinch(int signum)
|
||||||
|
{
|
||||||
|
(void) signum;
|
||||||
|
had_sigwinch = 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
@ -279,6 +288,13 @@ int main(int argc, char* argv[])
|
||||||
if ( !isatty(1) )
|
if ( !isatty(1) )
|
||||||
err(1, "standard output");
|
err(1, "standard output");
|
||||||
|
|
||||||
|
sigset_t sigwinch_set;
|
||||||
|
sigemptyset(&sigwinch_set);
|
||||||
|
sigaddset(&sigwinch_set, SIGWINCH);
|
||||||
|
sigprocmask(SIG_BLOCK, &sigwinch_set, NULL);
|
||||||
|
struct sigaction sa = { .sa_handler = sigwinch };
|
||||||
|
sigaction(SIGWINCH, &sa, NULL);
|
||||||
|
|
||||||
struct editor editor;
|
struct editor editor;
|
||||||
initialize_editor(&editor);
|
initialize_editor(&editor);
|
||||||
|
|
||||||
|
|
|
@ -353,12 +353,22 @@ void editor_input_process_byte(struct editor_input* editor_input,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern volatile sig_atomic_t had_sigwinch;
|
||||||
|
|
||||||
void editor_input_process(struct editor_input* editor_input,
|
void editor_input_process(struct editor_input* editor_input,
|
||||||
struct editor* editor)
|
struct editor* editor)
|
||||||
{
|
{
|
||||||
|
sigset_t sigset;
|
||||||
|
sigemptyset(&sigset);
|
||||||
struct pollfd pfd = { .fd = 0, .events = POLLIN };
|
struct pollfd pfd = { .fd = 0, .events = POLLIN };
|
||||||
do editor_input_process_byte(editor_input, editor);
|
struct timespec timeout = { .tv_sec = 0 };
|
||||||
while ( poll(&pfd, 1, 0) == 1 );
|
struct timespec* timeout_ptr = NULL;
|
||||||
|
while ( !had_sigwinch && ppoll(&pfd, 1, timeout_ptr, &sigset) == 1 )
|
||||||
|
{
|
||||||
|
editor_input_process_byte(editor_input, editor);
|
||||||
|
timeout_ptr = &timeout;
|
||||||
|
}
|
||||||
|
had_sigwinch = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void editor_input_end(struct editor_input* editor_input)
|
void editor_input_end(struct editor_input* editor_input)
|
||||||
|
|
|
@ -102,7 +102,19 @@ void update_terminal(FILE* fp,
|
||||||
struct terminal_state* desired,
|
struct terminal_state* desired,
|
||||||
struct terminal_state* current)
|
struct terminal_state* current)
|
||||||
{
|
{
|
||||||
// TODO: If terminal size has changed!
|
if ( desired->width != current->width ||
|
||||||
|
desired->height != current->height )
|
||||||
|
{
|
||||||
|
current->width = desired->width;
|
||||||
|
current->height = desired->height;
|
||||||
|
size_t data_length = current->width * current->height;
|
||||||
|
size_t data_size = sizeof(struct terminal_datum) * data_length;
|
||||||
|
current->data = (struct terminal_datum*) malloc(data_size);
|
||||||
|
for ( size_t i = 0; i < data_length; i++ )
|
||||||
|
current->data[i].character = L' ',
|
||||||
|
current->data[i].vgacolor = 0;
|
||||||
|
reset_terminal_state(fp, current);
|
||||||
|
}
|
||||||
for ( int y = 0; y < current->height; y++ )
|
for ( int y = 0; y < current->height; y++ )
|
||||||
{
|
{
|
||||||
for ( int x = 0; x < current->width; x++ )
|
for ( int x = 0; x < current->width; x++ )
|
||||||
|
|
|
@ -52,13 +52,11 @@ namespace NetFS {
|
||||||
class Manager;
|
class Manager;
|
||||||
class StreamSocket;
|
class StreamSocket;
|
||||||
|
|
||||||
class Manager : public AbstractInode
|
class Manager : public Refcountable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Manager(uid_t owner, gid_t group, mode_t mode);
|
Manager();
|
||||||
virtual ~Manager() { }
|
virtual ~Manager();
|
||||||
virtual Ref<Inode> open(ioctx_t* ctx, const char* filename, int flags,
|
|
||||||
mode_t mode);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool Bind(StreamSocket* socket, struct sockaddr_un* addr, size_t addrsize);
|
bool Bind(StreamSocket* socket, struct sockaddr_un* addr, size_t addrsize);
|
||||||
|
@ -114,6 +112,7 @@ public:
|
||||||
public: /* For use by Manager. */
|
public: /* For use by Manager. */
|
||||||
PollChannel accept_poll_channel;
|
PollChannel accept_poll_channel;
|
||||||
Ref<Manager> manager;
|
Ref<Manager> manager;
|
||||||
|
Ref<Descriptor> root;
|
||||||
PipeEndpoint incoming;
|
PipeEndpoint incoming;
|
||||||
PipeEndpoint outgoing;
|
PipeEndpoint outgoing;
|
||||||
StreamSocket* prev_socket;
|
StreamSocket* prev_socket;
|
||||||
|
@ -189,6 +188,7 @@ StreamSocket::StreamSocket(uid_t owner, gid_t group, mode_t mode,
|
||||||
this->is_connected = false;
|
this->is_connected = false;
|
||||||
this->is_refused = false;
|
this->is_refused = false;
|
||||||
this->manager = manager;
|
this->manager = manager;
|
||||||
|
this->root = CurrentProcess()->GetRoot();
|
||||||
this->socket_lock = KTHREAD_MUTEX_INITIALIZER;
|
this->socket_lock = KTHREAD_MUTEX_INITIALIZER;
|
||||||
this->pending_cond = KTHREAD_COND_INITIALIZER;
|
this->pending_cond = KTHREAD_COND_INITIALIZER;
|
||||||
this->accepted_cond = KTHREAD_COND_INITIALIZER;
|
this->accepted_cond = KTHREAD_COND_INITIALIZER;
|
||||||
|
@ -476,20 +476,19 @@ int StreamSocket::getsockname(ioctx_t* ctx, uint8_t* addr, size_t* addrsize)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::Manager(uid_t owner, gid_t group, mode_t mode)
|
Manager::Manager()
|
||||||
{
|
{
|
||||||
inode_type = INODE_TYPE_UNKNOWN;
|
|
||||||
dev = (dev_t) this;
|
|
||||||
ino = 0;
|
|
||||||
this->type = S_IFDIR;
|
|
||||||
this->stat_uid = owner;
|
|
||||||
this->stat_gid = group;
|
|
||||||
this->stat_mode = (mode & S_SETABLE) | this->type;
|
|
||||||
this->manager_lock = KTHREAD_MUTEX_INITIALIZER;
|
this->manager_lock = KTHREAD_MUTEX_INITIALIZER;
|
||||||
this->first_server = NULL;
|
this->first_server = NULL;
|
||||||
this->last_server = NULL;
|
this->last_server = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Manager::~Manager()
|
||||||
|
{
|
||||||
|
assert(!first_server);
|
||||||
|
assert(!last_server);
|
||||||
|
}
|
||||||
|
|
||||||
static int CompareAddress(const struct sockaddr_un* a,
|
static int CompareAddress(const struct sockaddr_un* a,
|
||||||
const struct sockaddr_un* b)
|
const struct sockaddr_un* b)
|
||||||
{
|
{
|
||||||
|
@ -498,8 +497,10 @@ static int CompareAddress(const struct sockaddr_un* a,
|
||||||
|
|
||||||
StreamSocket* Manager::LookupServer(struct sockaddr_un* address)
|
StreamSocket* Manager::LookupServer(struct sockaddr_un* address)
|
||||||
{
|
{
|
||||||
|
Ref<Descriptor> root = CurrentProcess()->GetRoot();
|
||||||
for ( StreamSocket* iter = first_server; iter; iter = iter->next_socket )
|
for ( StreamSocket* iter = first_server; iter; iter = iter->next_socket )
|
||||||
if ( CompareAddress(iter->name, address) == 0 )
|
if ( CompareAddress(iter->name, address) == 0 &&
|
||||||
|
iter->root->dev == root->dev && iter->root->ino == root->ino )
|
||||||
return iter;
|
return iter;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -664,24 +665,11 @@ bool Manager::Connect(StreamSocket* socket,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Support a poll method in Manager.
|
|
||||||
|
|
||||||
Ref<Inode> Manager::open(ioctx_t* /*ctx*/, const char* filename,
|
|
||||||
int /*flags*/, mode_t /*mode*/)
|
|
||||||
{
|
|
||||||
if ( !strcmp(filename, "stream") )
|
|
||||||
{
|
|
||||||
StreamSocket* socket = new StreamSocket(0, 0, 0666, Ref<Manager>(this));
|
|
||||||
return Ref<StreamSocket>(socket);
|
|
||||||
}
|
|
||||||
return errno = ENOENT, Ref<Inode>(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Ref<Manager> manager;
|
static Ref<Manager> manager;
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
manager = Ref<Manager>(new Manager(0, 0, 0600));
|
manager = Ref<Manager>(new Manager());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Inode> Socket(int type, int protocol)
|
Ref<Inode> Socket(int type, int protocol)
|
||||||
|
|
|
@ -656,6 +656,7 @@ int PTY::master_ioctl(ioctx_t* ctx, int cmd, uintptr_t arg)
|
||||||
const struct winsize* user_ws = (const struct winsize*) arg;
|
const struct winsize* user_ws = (const struct winsize*) arg;
|
||||||
if ( !ctx->copy_from_src(&ws, user_ws, sizeof(ws)) )
|
if ( !ctx->copy_from_src(&ws, user_ws, sizeof(ws)) )
|
||||||
return -1;
|
return -1;
|
||||||
|
winch();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ioctl(ctx, cmd, arg);
|
return ioctl(ctx, cmd, arg);
|
||||||
|
|
|
@ -314,16 +314,27 @@ void TTY::hup()
|
||||||
ScopedLock lock(&termlock);
|
ScopedLock lock(&termlock);
|
||||||
ScopedLock family_lock(&process_family_lock);
|
ScopedLock family_lock(&process_family_lock);
|
||||||
hungup = true;
|
hungup = true;
|
||||||
if ( 0 < sid )
|
if ( 0 < foreground_pgid )
|
||||||
{
|
{
|
||||||
Process* process = CurrentProcess()->GetPTable()->Get(sid);
|
Process* process = CurrentProcess()->GetPTable()->Get(foreground_pgid);
|
||||||
if ( process )
|
if ( process )
|
||||||
process->DeliverSessionSignal(SIGHUP);
|
process->DeliverGroupSignal(SIGHUP);
|
||||||
}
|
}
|
||||||
kthread_cond_broadcast(&datacond);
|
kthread_cond_broadcast(&datacond);
|
||||||
poll_channel.Signal(POLLHUP);
|
poll_channel.Signal(POLLHUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TTY::winch() // termlock taken
|
||||||
|
{
|
||||||
|
ScopedLock family_lock(&process_family_lock);
|
||||||
|
if ( 0 < foreground_pgid )
|
||||||
|
{
|
||||||
|
Process* process = CurrentProcess()->GetPTable()->Get(foreground_pgid);
|
||||||
|
if ( process )
|
||||||
|
process->DeliverGroupSignal(SIGWINCH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TTY::ProcessUnicode(uint32_t unicode)
|
void TTY::ProcessUnicode(uint32_t unicode)
|
||||||
{
|
{
|
||||||
mbstate_t ps;
|
mbstate_t ps;
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void hup();
|
void hup();
|
||||||
|
void winch();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void tty_output(const char* str)
|
void tty_output(const char* str)
|
||||||
|
|
2
sh/sh.c
2
sh/sh.c
|
@ -2042,7 +2042,7 @@ static int run(FILE* fp,
|
||||||
read_command_non_interactive(&sh_read_command, fp);
|
read_command_non_interactive(&sh_read_command, fp);
|
||||||
|
|
||||||
if ( sh_read_command.abort_condition )
|
if ( sh_read_command.abort_condition )
|
||||||
continue;
|
break;
|
||||||
|
|
||||||
if ( sh_read_command.eof_condition )
|
if ( sh_read_command.eof_condition )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue