|
3 | 3 | * SSL helper functions shared by sign-file and extract-cert.
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -static void display_openssl_errors(int l) |
| 6 | +static void drain_openssl_errors(int l, int silent) |
7 | 7 | {
|
8 | 8 | const char *file;
|
9 | 9 | char buf[120];
|
10 | 10 | int e, line;
|
11 | 11 |
|
12 | 12 | if (ERR_peek_error() == 0)
|
13 | 13 | return;
|
14 |
| - fprintf(stderr, "At main.c:%d:\n", l); |
| 14 | + if (!silent) |
| 15 | + fprintf(stderr, "At main.c:%d:\n", l); |
15 | 16 |
|
16 |
| - while ((e = ERR_get_error_line(&file, &line))) { |
| 17 | + while ((e = ERR_peek_error_line(&file, &line))) { |
17 | 18 | ERR_error_string(e, buf);
|
18 |
| - fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line); |
| 19 | + if (!silent) |
| 20 | + fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line); |
| 21 | + ERR_get_error(); |
19 | 22 | }
|
20 | 23 | }
|
21 | 24 |
|
22 |
| -static void drain_openssl_errors(void) |
23 |
| -{ |
24 |
| - const char *file; |
25 |
| - int line; |
26 |
| - |
27 |
| - if (ERR_peek_error() == 0) |
28 |
| - return; |
29 |
| - while (ERR_get_error_line(&file, &line)) {} |
30 |
| -} |
31 |
| - |
32 | 25 | #define ERR(cond, fmt, ...) \
|
33 | 26 | do { \
|
34 | 27 | bool __cond = (cond); \
|
35 |
| - display_openssl_errors(__LINE__); \ |
| 28 | + drain_openssl_errors(__LINE__, 0); \ |
36 | 29 | if (__cond) { \
|
37 | 30 | errx(1, fmt, ## __VA_ARGS__); \
|
38 | 31 | } \
|
|
0 commit comments