@@ -66,7 +66,7 @@ static bool do_edit(const char *filename_arg, PQExpBuffer query_buf,
6666 int lineno , bool * edited );
6767static bool do_connect (char * dbname , char * user , char * host , char * port );
6868static 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 );
7070static bool lookup_object_oid (EditableObjectType obj_type , const char * desc ,
7171 Oid * obj_oid );
7272static bool get_create_object_cmd (EditableObjectType obj_type , Oid oid ,
@@ -1577,12 +1577,12 @@ exec_command(const char *cmd,
15771577 {
15781578 char * opt = psql_scan_slash_option (scan_state ,
15791579 OT_NORMAL , NULL , true);
1580- long sleep = 2 ;
1580+ double sleep = 2 ;
15811581
15821582 /* Convert optional sleep-length argument */
15831583 if (opt )
15841584 {
1585- sleep = strtol (opt , NULL , 10 );
1585+ sleep = strtod (opt , NULL );
15861586 if (sleep <= 0 )
15871587 sleep = 1 ;
15881588 free (opt );
@@ -3017,8 +3017,9 @@ do_shell(const char *command)
30173017 * onto a bunch of exec_command's variables to silence stupider compilers.
30183018 */
30193019static bool
3020- do_watch (PQExpBuffer query_buf , long sleep )
3020+ do_watch (PQExpBuffer query_buf , double sleep )
30213021{
3022+ long sleep_ms = (long ) (sleep * 1000 );
30223023 printQueryOpt myopt = pset .popt ;
30233024 const char * user_title ;
30243025 char * title ;
@@ -3064,10 +3065,10 @@ do_watch(PQExpBuffer query_buf, long sleep)
30643065 asctimebuf [i ] = '\0' ;
30653066
30663067 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" ),
30683069 user_title , asctimebuf , sleep );
30693070 else
3070- snprintf (title , title_len , _ ("%s (every %lds )\n" ),
3071+ snprintf (title , title_len , _ ("%s (every %gs )\n" ),
30713072 asctimebuf , sleep );
30723073 myopt .title = title ;
30733074
@@ -3091,15 +3092,19 @@ do_watch(PQExpBuffer query_buf, long sleep)
30913092
30923093 /*
30933094 * 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.
30963097 */
30973098 sigint_interrupt_enabled = true;
3098- for (i = 0 ; i < sleep ; i ++ )
3099+ i = sleep_ms ;
3100+ while (i > 0 )
30993101 {
3100- pg_usleep (1000000L );
3102+ long s = Min (i , 1000L );
3103+
3104+ pg_usleep (s * 1000L );
31013105 if (cancel_pressed )
31023106 break ;
3107+ i -= s ;
31033108 }
31043109 sigint_interrupt_enabled = false;
31053110 }
0 commit comments