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