Bugzilla – Attachment 3228 Details for
Bug 2434
scp can send arbitrary control characters / escape sequences to the terminal
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Move progressmeter formatting out of signal handler.
openssh-progressmeter.patch (text/plain), 6.11 KB, created by
Darren Tucker
on 2019-01-23 15:11:28 AEDT
(
hide
)
Description:
Move progressmeter formatting out of signal handler.
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2019-01-23 15:11:28 AEDT
Size:
6.11 KB
patch
obsolete
>diff --git a/atomicio.c b/atomicio.c >index 5891638..3c1c647 100644 >--- a/atomicio.c >+++ b/atomicio.c >@@ -54,9 +54,15 @@ atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n, > res = (f) (fd, s + pos, n - pos); > switch (res) { > case -1: >- if (errno == EINTR) >+ switch(errno) { >+ case EINTR: >+ /* possible SIGALARM, update callback */ >+ if (cb != NULL && cb(cb_arg, 0) == -1) { >+ errno = EINTR; >+ return pos; >+ } > continue; >- if (errno == EAGAIN) { >+ case EAGAIN: > (void)poll(&pfd, 1, -1); > continue; > } >@@ -107,9 +113,15 @@ atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd, > res = (f) (fd, iov, iovcnt); > switch (res) { > case -1: >- if (errno == EINTR) >+ switch(errno) { >+ case EINTR: >+ /* possible SIGALARM, update callback */ >+ if (cb != NULL && cb(cb_arg, 0) == -1) { >+ errno = EINTR; >+ return pos; >+ } > continue; >- if (errno == EAGAIN) { >+ case EAGAIN: > (void)poll(&pfd, 1, -1); > continue; > } >diff --git a/progressmeter.c b/progressmeter.c >index 3220e2c..71c9aa4 100644 >--- a/progressmeter.c >+++ b/progressmeter.c >@@ -29,6 +29,7 @@ > > #include <errno.h> > #include <signal.h> >+#include <stdarg.h> > #include <stdio.h> > #include <string.h> > #include <time.h> >@@ -37,6 +38,7 @@ > #include "progressmeter.h" > #include "atomicio.h" > #include "misc.h" >+#include "utf8.h" > > #define DEFAULT_WINSIZE 80 > #define MAX_WINSIZE 512 >@@ -59,7 +61,7 @@ static void setscreensize(void); > void refresh_progress_meter(void); > > /* signal handler for updating the progress meter */ >-static void update_progress_meter(int); >+static void sig_alarm(int); > > static double start; /* start progress */ > static double last_update; /* last progress update */ >@@ -72,6 +74,7 @@ static long stalled; /* how long we have been stalled */ > static int bytes_per_second; /* current speed in bytes per second */ > static int win_size; /* terminal window size */ > static volatile sig_atomic_t win_resized; /* for window resizing */ >+static volatile sig_atomic_t alarm_fired; > > /* units for format_size */ > static const char unit[] = " KMGT"; >@@ -124,9 +127,17 @@ refresh_progress_meter(void) > off_t bytes_left; > int cur_speed; > int hours, minutes, seconds; >- int i, len; > int file_len; > >+ if ((!alarm_fired && !win_resized) || !can_output()) >+ return; >+ alarm_fired = 0; >+ >+ if (win_resized) { >+ setscreensize(); >+ win_resized = 0; >+ } >+ > transferred = *counter - (cur_pos ? cur_pos : start_pos); > cur_pos = *counter; > now = monotime_double(); >@@ -156,16 +167,12 @@ refresh_progress_meter(void) > > /* filename */ > buf[0] = '\0'; >- file_len = win_size - 35; >+ file_len = win_size - 36; > if (file_len > 0) { >- len = snprintf(buf, file_len + 1, "\r%s", file); >- if (len < 0) >- len = 0; >- if (len >= file_len + 1) >- len = file_len; >- for (i = len; i < file_len; i++) >- buf[i] = ' '; >- buf[file_len] = '\0'; >+ buf[0] = '\r'; >+ snmprintf(buf+1, sizeof(buf)-1 , &file_len, "%*s", >+ file_len * -1, file); >+ file_len++; > } > > /* percent of transfer done */ >@@ -226,22 +233,11 @@ refresh_progress_meter(void) > > /*ARGSUSED*/ > static void >-update_progress_meter(int ignore) >+sig_alarm(int ignore) > { >- int save_errno; >- >- save_errno = errno; >- >- if (win_resized) { >- setscreensize(); >- win_resized = 0; >- } >- if (can_output()) >- refresh_progress_meter(); >- >- signal(SIGALRM, update_progress_meter); >+ alarm_fired = 1; >+ signal(SIGALRM, sig_alarm); > alarm(UPDATE_INTERVAL); >- errno = save_errno; > } > > void >@@ -257,10 +253,9 @@ start_progress_meter(const char *f, off_t filesize, off_t *ctr) > bytes_per_second = 0; > > setscreensize(); >- if (can_output()) >- refresh_progress_meter(); >+ refresh_progress_meter(); > >- signal(SIGALRM, update_progress_meter); >+ signal(SIGALRM, sig_alarm); > signal(SIGWINCH, sig_winch); > alarm(UPDATE_INTERVAL); > } >diff --git a/progressmeter.h b/progressmeter.h >index bf179dc..bb4db83 100644 >--- a/progressmeter.h >+++ b/progressmeter.h >@@ -24,4 +24,5 @@ > */ > > void start_progress_meter(const char *, off_t, off_t *); >+void refresh_progress_meter(void); > void stop_progress_meter(void); >diff --git a/scp.c b/scp.c >index 44f064d..37d5c4e 100644 >--- a/scp.c >+++ b/scp.c >@@ -563,6 +563,7 @@ scpio(void *_cnt, size_t s) > off_t *cnt = (off_t *)_cnt; > > *cnt += s; >+ refresh_progress_meter(); > if (limit_kbps > 0) > bandwidth_limit(&bwlimit, s); > return 0; >diff --git a/sftp-client.c b/sftp-client.c >index d6dd33b..8c35f43 100644 >--- a/sftp-client.c >+++ b/sftp-client.c >@@ -88,7 +88,9 @@ sftpio(void *_bwlimit, size_t amount) > { > struct bwlimit *bwlimit = (struct bwlimit *)_bwlimit; > >- bandwidth_limit(bwlimit, amount); >+ refresh_progress_meter(); >+ if (bwlimit != NULL) >+ bandwidth_limit(bwlimit, amount); > return 0; > } > >@@ -108,8 +110,8 @@ send_msg(struct sftp_conn *conn, struct sshbuf *m) > iov[1].iov_base = (u_char *)sshbuf_ptr(m); > iov[1].iov_len = sshbuf_len(m); > >- if (atomiciov6(writev, conn->fd_out, iov, 2, >- conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_out) != >+ if (atomiciov6(writev, conn->fd_out, iov, 2, sftpio, >+ conn->limit_kbps > 0 ? &conn->bwlimit_out : NULL) != > sshbuf_len(m) + sizeof(mlen)) > fatal("Couldn't send packet: %s", strerror(errno)); > >@@ -125,8 +127,8 @@ get_msg_extended(struct sftp_conn *conn, struct sshbuf *m, int initial) > > if ((r = sshbuf_reserve(m, 4, &p)) != 0) > fatal("%s: buffer error: %s", __func__, ssh_err(r)); >- if (atomicio6(read, conn->fd_in, p, 4, >- conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in) != 4) { >+ if (atomicio6(read, conn->fd_in, p, 4, sftpio, >+ conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL) != 4) { > if (errno == EPIPE || errno == ECONNRESET) > fatal("Connection closed"); > else >@@ -144,8 +146,8 @@ get_msg_extended(struct sftp_conn *conn, struct sshbuf *m, int initial) > > if ((r = sshbuf_reserve(m, msg_len, &p)) != 0) > fatal("%s: buffer error: %s", __func__, ssh_err(r)); >- if (atomicio6(read, conn->fd_in, p, msg_len, >- conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in) >+ if (atomicio6(read, conn->fd_in, p, msg_len, sftpio, >+ conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL) > != msg_len) { > if (errno == EPIPE) > fatal("Connection closed");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
djm
:
ok+
Actions:
View
|
Diff
Attachments on
bug 2434
:
2678
|
2858
|
2942
|
2943
| 3228