Compare commits
No commits in common. "bab61702f3c65f9b5c3370756e4adb7d4c743372" and "da24b330e0eed316d7fad4035a15a8fa9363951b" have entirely different histories.
bab61702f3
...
da24b330e0
8 changed files with 35 additions and 74 deletions
|
@ -25,7 +25,6 @@
|
||||||
#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>
|
||||||
|
@ -271,14 +270,6 @@ 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, "");
|
||||||
|
@ -288,13 +279,6 @@ 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,22 +353,12 @@ 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 };
|
||||||
struct timespec timeout = { .tv_sec = 0 };
|
do editor_input_process_byte(editor_input, editor);
|
||||||
struct timespec* timeout_ptr = NULL;
|
while ( poll(&pfd, 1, 0) == 1 );
|
||||||
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,19 +102,7 @@ void update_terminal(FILE* fp,
|
||||||
struct terminal_state* desired,
|
struct terminal_state* desired,
|
||||||
struct terminal_state* current)
|
struct terminal_state* current)
|
||||||
{
|
{
|
||||||
if ( desired->width != current->width ||
|
// TODO: If terminal size has changed!
|
||||||
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,11 +52,13 @@ namespace NetFS {
|
||||||
class Manager;
|
class Manager;
|
||||||
class StreamSocket;
|
class StreamSocket;
|
||||||
|
|
||||||
class Manager : public Refcountable
|
class Manager : public AbstractInode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Manager();
|
Manager(uid_t owner, gid_t group, mode_t mode);
|
||||||
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);
|
||||||
|
@ -112,7 +114,6 @@ 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;
|
||||||
|
@ -188,7 +189,6 @@ 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,19 +476,20 @@ int StreamSocket::getsockname(ioctx_t* ctx, uint8_t* addr, size_t* addrsize)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::Manager()
|
Manager::Manager(uid_t owner, gid_t group, mode_t mode)
|
||||||
{
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
|
@ -497,10 +498,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -665,11 +664,24 @@ 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());
|
manager = Ref<Manager>(new Manager(0, 0, 0600));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Inode> Socket(int type, int protocol)
|
Ref<Inode> Socket(int type, int protocol)
|
||||||
|
|
|
@ -656,7 +656,6 @@ 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,27 +314,16 @@ 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 < foreground_pgid )
|
if ( 0 < sid )
|
||||||
{
|
{
|
||||||
Process* process = CurrentProcess()->GetPTable()->Get(foreground_pgid);
|
Process* process = CurrentProcess()->GetPTable()->Get(sid);
|
||||||
if ( process )
|
if ( process )
|
||||||
process->DeliverGroupSignal(SIGHUP);
|
process->DeliverSessionSignal(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,7 +78,6 @@ 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 )
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
if ( sh_read_command.eof_condition )
|
if ( sh_read_command.eof_condition )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue