From: hniksic Date: Tue, 4 Nov 2003 13:37:14 +0000 (-0800) Subject: [svn] Only set a flag in the SIGWINCH handler. X-Git-Tag: v1.13~1500 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=f4cbba565e8a0e88e396f4215559b41efa4521ca [svn] Only set a flag in the SIGWINCH handler. --- diff --git a/ChangeLog b/ChangeLog index 29fe44ef..4a470d3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-11-04 Hrvoje Niksic + + * configure.in: Check whether volatile is supported. Don't check + for gethostname and uname, which are not used. + 2003-11-04 Hrvoje Niksic * configure.in: Move some checks into aclocal.m4. Check whether diff --git a/configure.in b/configure.in index be2f9ffe..85234e80 100644 --- a/configure.in +++ b/configure.in @@ -149,14 +149,21 @@ dnl AM_C_PROTOTYPES dnl -dnl Checks for typedefs, structures, and compiler characteristics. +dnl Checks for basic compiler characteristics. dnl AC_C_CONST AC_C_INLINE -AC_TYPE_SIZE_T -AC_TYPE_PID_T +AC_C_VOLATILE AC_C_BIGENDIAN +dnl +dnl Checks for headers +dnl +AC_CHECK_HEADERS(string.h stdarg.h unistd.h sys/time.h utime.h sys/utime.h) +AC_CHECK_HEADERS(termios.h sys/ioctl.h sys/select.h sys/utsname.h) +AC_CHECK_HEADERS(inttypes.h signal.h setjmp.h pwd.h) +AC_HEADER_TIME + dnl dnl Check integral type sizes. dnl @@ -164,16 +171,25 @@ AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) -AC_CHECK_HEADERS(inttypes.h) -AC_CHECK_TYPES(uint32_t) dnl -dnl Checks for headers +dnl Checks for system-specific types. dnl -AC_CHECK_HEADERS(string.h stdarg.h unistd.h sys/time.h utime.h sys/utime.h pwd.h) -AC_CHECK_HEADERS(termios.h sys/ioctl.h sys/select.h sys/utsname.h) -AC_CHECK_HEADERS(signal.h setjmp.h) -AC_HEADER_TIME +AC_TYPE_SIZE_T +AC_TYPE_PID_T +AC_CHECK_TYPES(uint32_t) +AC_CHECK_TYPES(sig_atomic_t, [], [], [ +#include +#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_SIGNAL_H +# include +#endif +]) dnl dnl Return type of signal-handlers @@ -187,8 +203,7 @@ AC_FUNC_ALLOCA AC_FUNC_MMAP AC_CHECK_FUNCS(strdup strstr strcasecmp strncasecmp strpbrk memmove) AC_CHECK_FUNCS(gettimeofday mktime strptime strerror snprintf vsnprintf) -AC_CHECK_FUNCS(select sigblock sigsetjmp signal symlink access isatty) -AC_CHECK_FUNCS(uname gethostname usleep) +AC_CHECK_FUNCS(usleep select sigblock sigsetjmp signal symlink access isatty) dnl dnl Call Wget's local macros defined in aclocal. diff --git a/src/ChangeLog b/src/ChangeLog index 4352716f..59f0c8c4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2003-11-04 Hrvoje Niksic + * progress.c (progress_handle_sigwinch): Don't call + determine_screen_width() from the signal handler. Instead, just + set a volatile variable. + (bar_create): Check whether SIGWINCH was received. + (bar_update): Ditto. + * sysdep.h: Define SYSTEM_FNMATCH only if HAVE_FNMATCH_H is true. 2003-11-03 Hrvoje Niksic diff --git a/src/config.h.in b/src/config.h.in index abfbb8d8..45990416 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -64,6 +64,9 @@ char *alloca (); /* Define to empty or __inline__ or __inline. */ #undef inline +/* Define `volatile' to be empty if the compiler doesn't support it. */ +#undef volatile + /* Define to `unsigned' if doesn't define. */ #undef size_t @@ -116,15 +119,9 @@ char *alloca (); /* Define if you have struct utimbuf. */ #undef HAVE_STRUCT_UTIMBUF -/* Define if you have the uname function. */ -#undef HAVE_UNAME - /* Define if you have a working version of mmap. */ #undef HAVE_MMAP -/* Define if you have the gethostname function. */ -#undef HAVE_GETHOSTNAME - /* Define if you have the select function. */ #undef HAVE_SELECT @@ -287,6 +284,9 @@ char *alloca (); /* Define if you have uint32_t. */ #undef HAVE_UINT32_T +/* Define if you have sig_atomic_t. */ +#undef HAVE_SIG_ATOMIC_T + /* Some autoconf-unrelated preprocessor magic that cannot be in sysdep.h because it must be done before including the system headers. */ diff --git a/src/progress.c b/src/progress.c index 99bdd5b6..8ae09c32 100644 --- a/src/progress.c +++ b/src/progress.c @@ -408,7 +408,13 @@ dot_set_params (const char *params) create_image will overflow the buffer. */ #define MINIMUM_SCREEN_WIDTH 45 -static int screen_width = DEFAULT_SCREEN_WIDTH; +/* The last known screen width. This can be updated by the code that + detects that SIGWINCH was received (but it's never updated from the + signal handler). */ +static int screen_width; + +/* A flag that, when set, means SIGWINCH was received. */ +static volatile sig_atomic_t received_sigwinch; /* Size of the download speed history ring. */ #define DLSPEED_HISTORY_SIZE 20 @@ -484,6 +490,18 @@ bar_create (long initial, long total) bp->initial_length = initial; bp->total_length = total; + /* Initialize screen_width if this hasn't been done or if it might + have changed, as indicated by receiving SIGWINCH. */ + if (!screen_width || received_sigwinch) + { + screen_width = determine_screen_width (); + if (!screen_width) + screen_width = DEFAULT_SCREEN_WIDTH; + else if (screen_width < MINIMUM_SCREEN_WIDTH) + screen_width = MINIMUM_SCREEN_WIDTH; + received_sigwinch = 0; + } + /* - 1 because we don't want to use the last screen column. */ bp->width = screen_width - 1; /* + 1 for the terminating zero. */ @@ -517,11 +535,23 @@ bar_update (void *progress, long howmuch, double dltime) update_speed_ring (bp, howmuch, dltime); - if (screen_width - 1 != bp->width) + /* If SIGWINCH (the window size change signal) been received, + determine the new screen size and update the screen. */ + if (received_sigwinch) { - bp->width = screen_width - 1; - bp->buffer = xrealloc (bp->buffer, bp->width + 1); - force_screen_update = 1; + int old_width = screen_width; + screen_width = determine_screen_width (); + if (!screen_width) + screen_width = DEFAULT_SCREEN_WIDTH; + else if (screen_width < MINIMUM_SCREEN_WIDTH) + screen_width = MINIMUM_SCREEN_WIDTH; + if (screen_width != old_width) + { + bp->width = screen_width - 1; + bp->buffer = xrealloc (bp->buffer, bp->width + 1); + force_screen_update = 1; + } + received_sigwinch = 0; } if (dltime - bp->last_screen_update < 200 && !force_screen_update) @@ -844,7 +874,6 @@ display_image (char *buf) static void bar_set_params (const char *params) { - int sw; char *term = getenv ("TERM"); if (params @@ -877,19 +906,13 @@ bar_set_params (const char *params) set_progress_implementation (FALLBACK_PROGRESS_IMPLEMENTATION); return; } - - sw = determine_screen_width (); - if (sw && sw >= MINIMUM_SCREEN_WIDTH) - screen_width = sw; } #ifdef SIGWINCH RETSIGTYPE progress_handle_sigwinch (int sig) { - int sw = determine_screen_width (); - if (sw && sw >= MINIMUM_SCREEN_WIDTH) - screen_width = sw; + received_sigwinch = 1; signal (SIGWINCH, progress_handle_sigwinch); } #endif diff --git a/src/sysdep.h b/src/sysdep.h index e58daf33..3275ad4c 100644 --- a/src/sysdep.h +++ b/src/sysdep.h @@ -252,6 +252,11 @@ void *memcpy (); int fnmatch (); #endif +/* Provide sig_atomic_t if the system doesn't. */ +#ifndef HAVE_SIG_ATOMIC_T +typedef int sig_atomic_t; +#endif + /* Provide uint32_t on the platforms that don't define it. Although most code should be agnostic about integer sizes, some code really does need a 32-bit integral type. Such code should use uint32_t.