Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 47 additions & 11 deletions dvtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,19 +1657,10 @@ get_cmd_by_name(const char *name) {
}

static void
handle_cmdfifo(void) {
int r;
char *p, *s, cmdbuf[512], c;
process_cmdbuf(char *p) {
char *s, c;
Cmd *cmd;

r = read(cmdfifo.fd, cmdbuf, sizeof cmdbuf - 1);
if (r <= 0) {
cmdfifo.fd = -1;
return;
}

cmdbuf[r] = '\0';
p = cmdbuf;
while (*p) {
/* find the command name */
for (; *p == ' ' || *p == '\n'; p++);
Expand Down Expand Up @@ -1751,6 +1742,51 @@ handle_cmdfifo(void) {
}
}

static void
handle_cmdfifo(void) {
static char buf[4096];
static size_t len;
static bool skipping;
ssize_t r;
size_t end;

r = read(cmdfifo.fd, buf + len, sizeof buf - 1 - len);
if (r < 0 && (errno == EINTR || errno == EAGAIN))
return;
if (r <= 0) {
cmdfifo.fd = -1;
return;
}
len += r;

if (skipping) {
char *nl = memchr(buf, '\n', len);
if (!nl) {
len = 0;
return;
}
len -= nl + 1 - buf;
memmove(buf, nl + 1, len);
skipping = false;
}

for (end = len; end > 0 && buf[end - 1] != '\n'; end--);
if (!end) {
if (len == sizeof buf - 1) {
len = 0;
skipping = true;
}
return;
}

char next = buf[end];
buf[end] = '\0';
process_cmdbuf(buf);
buf[end] = next;
memmove(buf, buf + end, len - end);
len -= end;
}

static void
handle_mouse(void) {
#ifdef CONFIG_MOUSE
Expand Down
14 changes: 14 additions & 0 deletions test/test_dvtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ def test_cmd_fifo(self):
self.p.expect_exact('title-x')
self.p.expect_exact('from-42')

def test_cmd_fifo_split_writes(self):
fd = os.open(self.cmdfifo, os.O_WRONLY)
os.write(fd, b"create 'echo split-$((6*7)); sleep 60' ti")
time.sleep(0.5)
os.write(fd, b"tle-y\n")
os.close(fd)
self.p.expect_exact('title-y')
self.p.expect_exact('split-42')

def test_cmd_fifo_long_input(self):
with open(self.cmdfifo, 'w') as f:
f.write("create 'echo ok-$((6*7)); sleep 60' " + 'x' * 600 + '\n')
self.p.expect_exact('ok-42')

def test_status_fifo(self):
with open(self.status, 'w') as f:
f.write('hello-status\n')
Expand Down
Loading