Commit Graph

17 Commits

Author SHA1 Message Date
Andreas Kling
beda478821 Kernel: Make syscalls that take a buffer size use ssize_t instead of size_t.
Dealing with the unsigned overflow propagation here just seems unreasonably
error prone. Let's limit ourselves to 2GB buffer sizes instead.
2019-02-25 21:21:12 +01:00
Andreas Kling
0aaec6b19a Support resizing the Terminal app.
I set it up so that TIOCSWINSZ on a master PTY gets forwarded to the slave.
This feels intuitively right. Terminal can then use that to inform the shell
or whoever is inside the slave that the window size has changed.

TIOCSWINSZ also triggers the generation of a SIGWINCH signal. :^)
2019-02-20 23:38:20 +01:00
Andreas Kling
0669ef8977 Kernel: Writing to a slave PTY should yield EIO if the master is closed. 2019-02-05 13:09:01 +01:00
Andreas Kling
2a0700af9a Kernel: Closing a MasterPTY should generate a TTY hangup. 2019-02-05 12:55:19 +01:00
Andreas Kling
378e20c535 Kernel: Reading from a slave PTY should give EOF if master PTY is closed. 2019-02-05 12:27:32 +01:00
Andreas Kling
34e745b0b4 Add uid and gid to CharacterDevices.
The vast majority of them will be owned by 0:0 (the default.)
However, PTY pairs will now be owned by the uid:gid of the opening process.
2019-01-31 05:55:30 +01:00
Andreas Kling
2b4374d08e Let the slave PTY keep the master PTY alive.
This ownership model is a bit confusing. There's a retain cycle between
MasterPTY and SlavePTY, but it's broken when the SlavePTY is closed, meaning
that there are no more FileDescriptors referring to it.
2019-01-30 19:05:59 +01:00
Andreas Kling
b4e478aa50 Deallocate PTY's when they close.
This required a fair bit of plumbing. The CharacterDevice::close() virtual
will now be closed by ~FileDescriptor(), allowing device implementations to
do custom cleanup at that point.

One big problem remains: if the master PTY is closed before the slave PTY,
we go into crashy land.
2019-01-30 18:47:18 +01:00
Andreas Kling
027d26cd5d Add a String::format() and use that in place of ksprintf() in the Kernel.
You're never gonna be right 100% of the time when guessing how much buffer
space you need. This avoids having to make that type of decision in a bunch
of cases. :^)
2019-01-30 16:28:51 +01:00
Andreas Kling
e9b948103d Add a /dev/pts filesystem and make PTY allocation dynamic.
You can now open as many PTY pairs as you like. Well, it's actually capped
at 8 for now, but it's just a constant and trivial to change.

Unregistering a PTY pair is untested because I didn't want to start
mucking with that in Terminal right now.
2019-01-30 00:49:20 +01:00
Andreas Kling
b896d4b237 PTY: Disallow infinite writing to slaves.
This way we don't buffer ungodly amounts of output in the kernel when doing
e.g "cat /dev/random" on a PTY.
2019-01-25 00:13:54 +01:00
Andreas Kling
ccf3fc4618 TTY: MasterPTY's are always writable when open.
This should probably have some limitations eventually, but for now let's just
say we always accept data for shoveling over to SlavePTY.
2019-01-24 21:23:46 +01:00
Andreas Kling
310a5f4199 Let each MasterPTY create its slave. 2019-01-16 02:11:50 +01:00
Andreas Kling
bd3e77cc16 Pass the process to CharacterDevice::read/write.
This is much nicer than grabbing directly at 'current' inside a read().
2019-01-16 00:20:38 +01:00
Andreas Kling
08bfe518f9 Rename CharacterDevice::has_data_available_for_reading() -> can_read(). 2019-01-16 00:10:13 +01:00
Andreas Kling
e452303c66 Allow character devices to block write attempts until there is more space. 2019-01-15 09:17:22 +01:00
Andreas Kling
2f74c2f430 Add basic PTY support.
For now, there are four hard-coded PTYs: /dev/pt{m,s}[0123]
Use this in the Terminal to open a pty pair and spawn a shell.
2019-01-15 06:30:19 +01:00