@@ -66,7 +66,7 @@ static bool do_edit(const char *filename_arg, PQExpBuffer query_buf,
66
66
int lineno , bool * edited );
67
67
static bool do_connect (char * dbname , char * user , char * host , char * port );
68
68
static bool do_shell (const char * command );
69
- static bool do_watch (PQExpBuffer query_buf , long sleep );
69
+ static bool do_watch (PQExpBuffer query_buf , double sleep );
70
70
static bool lookup_object_oid (EditableObjectType obj_type , const char * desc ,
71
71
Oid * obj_oid );
72
72
static bool get_create_object_cmd (EditableObjectType obj_type , Oid oid ,
@@ -1577,12 +1577,12 @@ exec_command(const char *cmd,
1577
1577
{
1578
1578
char * opt = psql_scan_slash_option (scan_state ,
1579
1579
OT_NORMAL , NULL , true);
1580
- long sleep = 2 ;
1580
+ double sleep = 2 ;
1581
1581
1582
1582
/* Convert optional sleep-length argument */
1583
1583
if (opt )
1584
1584
{
1585
- sleep = strtol (opt , NULL , 10 );
1585
+ sleep = strtod (opt , NULL );
1586
1586
if (sleep <= 0 )
1587
1587
sleep = 1 ;
1588
1588
free (opt );
@@ -3017,8 +3017,9 @@ do_shell(const char *command)
3017
3017
* onto a bunch of exec_command's variables to silence stupider compilers.
3018
3018
*/
3019
3019
static bool
3020
- do_watch (PQExpBuffer query_buf , long sleep )
3020
+ do_watch (PQExpBuffer query_buf , double sleep )
3021
3021
{
3022
+ long sleep_ms = (long ) (sleep * 1000 );
3022
3023
printQueryOpt myopt = pset .popt ;
3023
3024
const char * user_title ;
3024
3025
char * title ;
@@ -3064,10 +3065,10 @@ do_watch(PQExpBuffer query_buf, long sleep)
3064
3065
asctimebuf [i ] = '\0' ;
3065
3066
3066
3067
if (user_title )
3067
- snprintf (title , title_len , _ ("%s\t%s (every %lds )\n" ),
3068
+ snprintf (title , title_len , _ ("%s\t%s (every %gs )\n" ),
3068
3069
user_title , asctimebuf , sleep );
3069
3070
else
3070
- snprintf (title , title_len , _ ("%s (every %lds )\n" ),
3071
+ snprintf (title , title_len , _ ("%s (every %gs )\n" ),
3071
3072
asctimebuf , sleep );
3072
3073
myopt .title = title ;
3073
3074
@@ -3091,15 +3092,19 @@ do_watch(PQExpBuffer query_buf, long sleep)
3091
3092
3092
3093
/*
3093
3094
* Enable 'watch' cancellations and wait a while before running the
3094
- * query again. Break the sleep into short intervals since pg_usleep
3095
- * isn't interruptible on some platforms.
3095
+ * query again. Break the sleep into short intervals (at most 1s)
3096
+ * since pg_usleep isn't interruptible on some platforms.
3096
3097
*/
3097
3098
sigint_interrupt_enabled = true;
3098
- for (i = 0 ; i < sleep ; i ++ )
3099
+ i = sleep_ms ;
3100
+ while (i > 0 )
3099
3101
{
3100
- pg_usleep (1000000L );
3102
+ long s = Min (i , 1000L );
3103
+
3104
+ pg_usleep (s * 1000L );
3101
3105
if (cancel_pressed )
3102
3106
break ;
3107
+ i -= s ;
3103
3108
}
3104
3109
sigint_interrupt_enabled = false;
3105
3110
}
0 commit comments