Skip to content

Commit 19972f3

Browse files
authored
Merge pull request #157 from hartwork/fix-for-o1
Fix crash with `-O1` on Ctrl+C + address `-O1` warnings + make CI compile with `-O1`
2 parents 375d195 + aa919c9 commit 19972f3

6 files changed

Lines changed: 20 additions & 13 deletions

File tree

.github/workflows/linux_and_macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
125125
${MAKE} --version 2>/dev/null || true
126126
127-
CFLAGS="-std=gnu99 -pedantic -Werror ${sanitizer}" LDFLAGS="${as_needed} ${sanitizer}" ${MAKE}
127+
CFLAGS="-std=gnu99 -pedantic -Werror ${sanitizer} -O1" LDFLAGS="${as_needed} ${sanitizer}" ${MAKE}
128128
129129
- name: 'Install'
130130
env:

recordings/expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
| │ |
2020
| └─────────────────────────────────────────────────────────────────────────────────────> |
2121
| X Thu Jan 1 00:00:00 1970 |
22-
|   https://github.com/tenox7/ttyplot 1.6.0 |
22+
|   https://github.com/tenox7/ttyplot 1.6.1 |
2323
+------------------------------------------------------------------------------------------+
2424

2525
[90x20] Frame 2:
@@ -43,7 +43,7 @@
4343
| │ XX |
4444
| └─────────────────────────────────────────────────────────────────────────────────────> |
4545
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
46-
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.0 |
46+
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.1 |
4747
+------------------------------------------------------------------------------------------+
4848

4949
[90x20] Frame 3:
@@ -67,6 +67,6 @@
6767
| │ XX |
6868
| └─────────────────────────────────────────────────────────────────────────────────────> |
6969
| X last=3.0 min=1.0 max=3.0 avg=2.0 Thu Jan 1 00:00:00 1970 |
70-
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.0 |
70+
|   last=4.0 min=2.0 max=4.0 avg=3.0 https://github.com/tenox7/ttyplot 1.6.1 |
7171
+------------------------------------------------------------------------------------------+
7272

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: ttyplot
2-
version: 1.6.0
2+
version: 1.6.1
33
summary: realtime plotting utility for terminal/console with data input from stdin
44
description: |
55
takes data from standard input / unix pipeline,

stresstest.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,20 @@ int main(int argc, char *argv[]) {
8383
size_t send_pos = 0;
8484
while (buffer_pos - send_pos >= 16) {
8585
const size_t bytes_to_send = 1 + rand() % 16; // 1..16
86-
write(STDOUT_FILENO, buffer + send_pos, bytes_to_send);
86+
const ssize_t bytes_sent = write(STDOUT_FILENO, buffer + send_pos, bytes_to_send);
8787
usleep(50); // let ttyplot read this before proceeding
88-
send_pos += bytes_to_send;
88+
if (bytes_sent > 0)
89+
send_pos += bytes_sent;
8990
}
9091
if (send_pos > 0 && send_pos < buffer_pos)
9192
memmove(buffer, buffer + send_pos, buffer_pos - send_pos);
9293
buffer_pos -= send_pos;
9394
} else {
94-
write(STDOUT_FILENO, buffer, buffer_pos);
95-
buffer_pos = 0;
95+
const ssize_t bytes_sent = write(STDOUT_FILENO, buffer, buffer_pos);
96+
if ((bytes_sent > 0) && ((size_t)bytes_sent < buffer_pos))
97+
memmove(buffer, buffer + bytes_sent, buffer_pos - bytes_sent);
98+
if (bytes_sent > 0)
99+
buffer_pos -= bytes_sent;
96100
}
97101
usleep(delay);
98102
}

ttyplot.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.Dd November 27, 2023
1+
.Dd December 25, 2023
22
.Dt TTYPLOT 1
33
.Os
44
.Sh NAME

ttyplot.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define STR(x) STR_(x)
4040
#define VERSION_MAJOR 1
4141
#define VERSION_MINOR 6
42-
#define VERSION_PATCH 0
42+
#define VERSION_PATCH 1
4343
#define VERSION_STR STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_PATCH)
4444

4545
#define T_RARR '>'
@@ -282,7 +282,10 @@ static void paint_plot(void) {
282282
// (Related: https://stackoverflow.com/q/62315082)
283283
static void signal_handler(int signum) {
284284
const unsigned char signal_number = (unsigned char) signum; // signum is either 2 (SIGINT) or 28 (SIGWINCH)
285-
write(signal_write_fd, &signal_number, 1);
285+
ssize_t write_res;
286+
do {
287+
write_res = write(signal_write_fd, &signal_number, 1);
288+
} while ((write_res == -1) && (errno == EINTR));
286289
}
287290

288291
static void redraw_screen(const char * errstr) {
@@ -478,7 +481,7 @@ static int wait_for_events(int signal_read_fd, int tty, bool stdin_is_open, stru
478481
ret |= EVENT_SIGNAL_READABLE;
479482
}
480483

481-
if (FD_ISSET(tty, &read_fds)) {
484+
if ((tty != -1) && FD_ISSET(tty, &read_fds)) {
482485
ret |= EVENT_TTY_READABLE;
483486
}
484487

0 commit comments

Comments
 (0)