summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-06-16 13:18:04 +1000
committerDamien Miller <djm@mindrot.org>2005-06-16 13:18:04 +1000
commit05656967b111a7c2b1f831eab0c31002dfac6fa9 (patch)
tree00ccc8ad688f10551743b372db71f9100548c4f6
parent488d6026180d1616ae0aaaae4ae8a658a0df817f (diff)
- (djm) OpenBSD CVS Sync
- jaredy@cvs.openbsd.org 2005/06/07 13:25:23 [progressmeter.c] catch SIGWINCH and resize progress meter accordingly; ok markus dtucker
-rw-r--r--ChangeLog9
-rw-r--r--progressmeter.c47
2 files changed, 42 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b839788d..71e7beea0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
120050616
2 - (djm) OpenBSD CVS Sync
3 - jaredy@cvs.openbsd.org 2005/06/07 13:25:23
4 [progressmeter.c]
5 catch SIGWINCH and resize progress meter accordingly; ok markus dtucker
6
7
120050609 820050609
2 - (dtucker) [cipher.c openbsd-compat/Makefile.in 9 - (dtucker) [cipher.c openbsd-compat/Makefile.in
3 openbsd-compat/openbsd-compat.h openbsd-compat/openssl-compat.{c,h}] 10 openbsd-compat/openbsd-compat.h openbsd-compat/openssl-compat.{c,h}]
@@ -2692,4 +2699,4 @@
2692 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 2699 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
2693 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 2700 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
2694 2701
2695$Id: ChangeLog,v 1.3815 2005/06/09 13:40:39 dtucker Exp $ 2702$Id: ChangeLog,v 1.3816 2005/06/16 03:18:04 djm Exp $
diff --git a/progressmeter.c b/progressmeter.c
index febe9aad5..3cda09061 100644
--- a/progressmeter.c
+++ b/progressmeter.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: progressmeter.c,v 1.23 2005/04/28 10:17:56 moritz Exp $"); 26RCSID("$OpenBSD: progressmeter.c,v 1.24 2005/06/07 13:25:23 jaredy Exp $");
27 27
28#include "progressmeter.h" 28#include "progressmeter.h"
29#include "atomicio.h" 29#include "atomicio.h"
@@ -42,6 +42,10 @@ static int can_output(void);
42static void format_size(char *, int, off_t); 42static void format_size(char *, int, off_t);
43static void format_rate(char *, int, off_t); 43static void format_rate(char *, int, off_t);
44 44
45/* window resizing */
46static void sig_winch(int);
47static void setscreensize(void);
48
45/* updates the progressmeter to reflect the current state of the transfer */ 49/* updates the progressmeter to reflect the current state of the transfer */
46void refresh_progress_meter(void); 50void refresh_progress_meter(void);
47 51
@@ -57,6 +61,7 @@ static volatile off_t *counter; /* progress counter */
57static long stalled; /* how long we have been stalled */ 61static long stalled; /* how long we have been stalled */
58static int bytes_per_second; /* current speed in bytes per second */ 62static int bytes_per_second; /* current speed in bytes per second */
59static int win_size; /* terminal window size */ 63static int win_size; /* terminal window size */
64static volatile sig_atomic_t win_resized; /* for window resizing */
60 65
61/* units for format_size */ 66/* units for format_size */
62static const char unit[] = " KMGT"; 67static const char unit[] = " KMGT";
@@ -217,6 +222,10 @@ update_progress_meter(int ignore)
217 222
218 save_errno = errno; 223 save_errno = errno;
219 224
225 if (win_resized) {
226 setscreensize();
227 win_resized = 0;
228 }
220 if (can_output()) 229 if (can_output())
221 refresh_progress_meter(); 230 refresh_progress_meter();
222 231
@@ -228,8 +237,6 @@ update_progress_meter(int ignore)
228void 237void
229start_progress_meter(char *f, off_t filesize, off_t *ctr) 238start_progress_meter(char *f, off_t filesize, off_t *ctr)
230{ 239{
231 struct winsize winsize;
232
233 start = last_update = time(NULL); 240 start = last_update = time(NULL);
234 file = f; 241 file = f;
235 end_pos = filesize; 242 end_pos = filesize;
@@ -238,20 +245,12 @@ start_progress_meter(char *f, off_t filesize, off_t *ctr)
238 stalled = 0; 245 stalled = 0;
239 bytes_per_second = 0; 246 bytes_per_second = 0;
240 247
241 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) != -1 && 248 setscreensize();
242 winsize.ws_col != 0) {
243 if (winsize.ws_col > MAX_WINSIZE)
244 win_size = MAX_WINSIZE;
245 else
246 win_size = winsize.ws_col;
247 } else
248 win_size = DEFAULT_WINSIZE;
249 win_size += 1; /* trailing \0 */
250
251 if (can_output()) 249 if (can_output())
252 refresh_progress_meter(); 250 refresh_progress_meter();
253 251
254 signal(SIGALRM, update_progress_meter); 252 signal(SIGALRM, update_progress_meter);
253 signal(SIGWINCH, sig_winch);
255 alarm(UPDATE_INTERVAL); 254 alarm(UPDATE_INTERVAL);
256} 255}
257 256
@@ -269,3 +268,25 @@ stop_progress_meter(void)
269 268
270 atomicio(vwrite, STDOUT_FILENO, "\n", 1); 269 atomicio(vwrite, STDOUT_FILENO, "\n", 1);
271} 270}
271
272static void
273sig_winch(int sig)
274{
275 win_resized = 1;
276}
277
278static void
279setscreensize(void)
280{
281 struct winsize winsize;
282
283 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) != -1 &&
284 winsize.ws_col != 0) {
285 if (winsize.ws_col > MAX_WINSIZE)
286 win_size = MAX_WINSIZE;
287 else
288 win_size = winsize.ws_col;
289 } else
290 win_size = DEFAULT_WINSIZE;
291 win_size += 1; /* trailing \0 */
292}