|
22 | 22 | #include "fe_utils/string_utils.h"
|
23 | 23 |
|
24 | 24 |
|
| 25 | +/* |
| 26 | + * Write a simple string to stderr --- must be safe in a signal handler. |
| 27 | + * We ignore the write() result since there's not much we could do about it. |
| 28 | + * Certain compilers make that harder than it ought to be. |
| 29 | + */ |
| 30 | +#define write_stderr(str) \ |
| 31 | + do { \ |
| 32 | + const char *str_ = (str); \ |
| 33 | + int rc_; \ |
| 34 | + rc_ = write(fileno(stderr), str_, strlen(str_)); \ |
| 35 | + (void) rc_; \ |
| 36 | + } while (0) |
| 37 | + |
25 | 38 | #define PQmblenBounded(s, e) strnlen(s, PQmblen(s, e))
|
26 | 39 |
|
27 | 40 | static PGcancel *volatile cancelConn = NULL;
|
@@ -489,10 +502,13 @@ handle_sigint(SIGNAL_ARGS)
|
489 | 502 | if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
|
490 | 503 | {
|
491 | 504 | CancelRequested = true;
|
492 |
| - fprintf(stderr, _("Cancel request sent\n")); |
| 505 | + write_stderr("Cancel request sent\n"); |
493 | 506 | }
|
494 | 507 | else
|
495 |
| - fprintf(stderr, _("Could not send cancel request: %s"), errbuf); |
| 508 | + { |
| 509 | + write_stderr("Could not send cancel request: "); |
| 510 | + write_stderr(errbuf); |
| 511 | + } |
496 | 512 | }
|
497 | 513 | else
|
498 | 514 | CancelRequested = true;
|
@@ -526,11 +542,14 @@ consoleHandler(DWORD dwCtrlType)
|
526 | 542 | {
|
527 | 543 | if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
|
528 | 544 | {
|
529 |
| - fprintf(stderr, _("Cancel request sent\n")); |
530 | 545 | CancelRequested = true;
|
| 546 | + write_stderr("Cancel request sent\n"); |
531 | 547 | }
|
532 | 548 | else
|
533 |
| - fprintf(stderr, _("Could not send cancel request: %s"), errbuf); |
| 549 | + { |
| 550 | + write_stderr("Could not send cancel request: "); |
| 551 | + write_stderr(errbuf); |
| 552 | + } |
534 | 553 | }
|
535 | 554 | else
|
536 | 555 | CancelRequested = true;
|
|
0 commit comments