PostgreSQL Source Code git master
Loading...
Searching...
No Matches
cancel.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include "common/connect.h"
#include "fe_utils/cancel.h"
#include "fe_utils/string_utils.h"
Include dependency graph for cancel.c:

Go to the source code of this file.

Macros

#define write_stderr(str)
 

Functions

void SetCancelConn (PGconn *conn)
 
void ResetCancelConn (void)
 
static void handle_sigint (SIGNAL_ARGS)
 
void setup_cancel_handler (void(*query_cancel_callback)(void))
 

Variables

static PGcancel *volatile cancelConn = NULL
 
static const charcancel_sent_msg = NULL
 
static const charcancel_not_sent_msg = NULL
 
volatile sig_atomic_t CancelRequested = false
 
static void(* cancel_callback )(void) = NULL
 

Macro Definition Documentation

◆ write_stderr

#define write_stderr (   str)
Value:
do { \
const char *str_ = (str); \
rc_ = write(fileno(stderr), str_, strlen(str_)); \
(void) rc_; \
} while (0)
const char * str
#define write(a, b, c)
Definition win32.h:14
static int fb(int x)

Definition at line 61 of file cancel.c.

62 { \
63 const char *str_ = (str); \
64 ssize_t rc_; \
65 rc_ = write(fileno(stderr), str_, strlen(str_)); \
66 (void) rc_; \
67 } while (0)

Function Documentation

◆ handle_sigint()

static void handle_sigint ( SIGNAL_ARGS  )
static

Definition at line 183 of file cancel.c.

184{
185 char errbuf[256];
186
187 CancelRequested = true;
188
189 if (cancel_callback != NULL)
191
192 /* Send QueryCancel if we are processing a database query */
193 if (cancelConn != NULL)
194 {
195 if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
196 {
198 }
199 else
200 {
202 write_stderr(errbuf);
203 }
204 }
205}
volatile sig_atomic_t CancelRequested
Definition cancel.c:89
static void(* cancel_callback)(void)
Definition cancel.c:98
static const char * cancel_sent_msg
Definition cancel.c:79
static PGcancel *volatile cancelConn
Definition cancel.c:73
#define write_stderr(str)
Definition cancel.c:61
static const char * cancel_not_sent_msg
Definition cancel.c:80
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
Definition fe-cancel.c:548

References cancel_callback, cancel_not_sent_msg, cancel_sent_msg, cancelConn, CancelRequested, fb(), PQcancel(), and write_stderr.

Referenced by setup_cancel_handler().

◆ ResetCancelConn()

void ResetCancelConn ( void  )

Definition at line 137 of file cancel.c.

138{
140
141#ifdef WIN32
143#endif
144
146
147 /* be sure handle_sigint doesn't use pointer while freeing */
149
150 if (oldCancelConn != NULL)
152
153#ifdef WIN32
155#endif
156}
void PQfreeCancel(PGcancel *cancel)
Definition fe-cancel.c:502

References cancelConn, fb(), and PQfreeCancel().

Referenced by CheckConnection(), consumeQueryResult(), do_connect(), do_lo_export(), do_lo_import(), do_lo_unlink(), executeMaintenanceCommand(), HandleCopyResult(), PSQLexec(), PSQLexecWatch(), runInitSteps(), SendQuery(), and wait_on_slots().

◆ SetCancelConn()

void SetCancelConn ( PGconn conn)

Definition at line 107 of file cancel.c.

108{
110
111#ifdef WIN32
113#endif
114
115 /* Free the old one if we have one */
117
118 /* be sure handle_sigint doesn't use pointer while freeing */
120
121 if (oldCancelConn != NULL)
123
125
126#ifdef WIN32
128#endif
129}
PGcancel * PQgetCancel(PGconn *conn)
Definition fe-cancel.c:368
PGconn * conn
Definition streamutil.c:52

References cancelConn, conn, fb(), PQfreeCancel(), and PQgetCancel().

Referenced by consumeQueryResult(), do_lo_export(), do_lo_import(), do_lo_unlink(), executeMaintenanceCommand(), HandleCopyResult(), PSQLexec(), PSQLexecWatch(), runInitSteps(), SendQuery(), and wait_on_slots().

◆ setup_cancel_handler()

void setup_cancel_handler ( void(*)(void query_cancel_callback)

Definition at line 213 of file cancel.c.

214{
216 cancel_sent_msg = _("Cancel request sent\n");
217 cancel_not_sent_msg = _("Could not send cancel request: ");
218
220}
static void handle_sigint(SIGNAL_ARGS)
Definition cancel.c:183
#define _(x)
Definition elog.c:96
#define pqsignal
Definition port.h:548

References _, cancel_callback, cancel_not_sent_msg, cancel_sent_msg, fb(), handle_sigint(), and pqsignal.

Referenced by main(), psql_setup_cancel_handler(), runInitSteps(), and vacuuming_main().

Variable Documentation

◆ cancel_callback

void(* cancel_callback) (void) ( void  ) = NULL
static

Definition at line 98 of file cancel.c.

Referenced by handle_sigint(), and setup_cancel_handler().

◆ cancel_not_sent_msg

const char* cancel_not_sent_msg = NULL
static

Definition at line 80 of file cancel.c.

Referenced by handle_sigint(), and setup_cancel_handler().

◆ cancel_sent_msg

const char* cancel_sent_msg = NULL
static

Definition at line 79 of file cancel.c.

Referenced by handle_sigint(), and setup_cancel_handler().

◆ cancelConn

◆ CancelRequested