X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fpty.c;h=a87b3ce6f0ba4efa6ca09b3ef26cdd7834b25c12;hb=d896ac2d2fbce41a0b11a0618a685adeaf18b8fe;hp=31123e5af20636e71476ae52043327af5e99ba5b;hpb=fb1f4170d008315cb9eabe994038977a0366ede5;p=elogind.git diff --git a/src/shared/pty.c b/src/shared/pty.c index 31123e5af..a87b3ce6f 100644 --- a/src/shared/pty.c +++ b/src/shared/pty.c @@ -44,19 +44,12 @@ #include #include -#include -#include -#include #include #include #include -#include #include -#include #include -#include #include -#include #include #include #include @@ -64,11 +57,12 @@ #include "barrier.h" #include "macro.h" -#include "pty.h" #include "ring.h" #include "util.h" +#include "signal-util.h" +#include "pty.h" -#define PTY_BUFSIZE 16384 +#define PTY_BUFSIZE 4096 enum { PTY_ROLE_UNKNOWN, @@ -195,13 +189,13 @@ int pty_get_fd(Pty *pty) { } int pty_make_child(Pty *pty) { - char slave_name[1024]; + _cleanup_free_ char *slave_name = NULL; int r, fd; assert_return(pty, -EINVAL); assert_return(pty_is_unknown(pty), -EALREADY); - r = ptsname_r(pty->fd, slave_name, sizeof(slave_name)); + r = ptsname_malloc(pty->fd, &slave_name); if (r < 0) return -errno; @@ -245,7 +239,7 @@ int pty_setup_child(Pty *pty) { assert_return(pty_is_child(pty), -EINVAL); assert_return(pty_is_open(pty), -EALREADY); - r = sigprocmask_many(SIG_SETMASK, -1); + r = reset_signal_mask(); if (r < 0) return r; @@ -306,11 +300,11 @@ static int pty_dispatch_read(Pty *pty) { /* * We're edge-triggered, means we need to read the whole queue. This, * however, might cause us to stall if the writer is faster than we - * are. Therefore, we read twice and if the second read still returned - * data, we reschedule. + * are. Therefore, try reading as much as 8 times (32KiB) and only + * bail out then. */ - for (i = 0; i < 2; ++i) { + for (i = 0; i < 8; ++i) { len = read(pty->fd, pty->in_buf, sizeof(pty->in_buf) - 1); if (len < 0) { if (errno == EINTR) @@ -551,16 +545,15 @@ int pty_signal(Pty *pty, int sig) { } int pty_resize(Pty *pty, unsigned short term_width, unsigned short term_height) { - struct winsize ws; + struct winsize ws = { + .ws_col = term_width, + .ws_row = term_height, + }; assert_return(pty, -EINVAL); assert_return(pty_is_open(pty), -ENODEV); assert_return(pty_is_parent(pty), -ENODEV); - zero(ws); - ws.ws_col = term_width; - ws.ws_row = term_height; - /* * This will send SIGWINCH to the pty slave foreground process group. * We will also get one, but we don't need it.