From d63053bbdfa226c85e9cec06c35283296e254a84 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Mon, 7 Jun 2021 11:50:43 +0200 Subject: 80-test_cmp_http.t: Improve the way the test server is launched and killed Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15642) --- apps/include/s_apps.h | 2 +- apps/lib/http_server.c | 2 +- apps/lib/s_socket.c | 29 +++++++++++++++-------------- 3 files changed, 17 insertions(+), 16 deletions(-) (limited to 'apps') diff --git a/apps/include/s_apps.h b/apps/include/s_apps.h index 18dbd50..d610df4 100644 --- a/apps/include/s_apps.h +++ b/apps/include/s_apps.h @@ -16,7 +16,7 @@ #define PROTOCOL "tcp" typedef int (*do_server_cb)(int s, int stype, int prot, unsigned char *context); -int report_server_accept(BIO *out, int asock, int with_address); +int report_server_accept(BIO *out, int asock, int with_address, int with_pid); int do_server(int *accept_sock, const char *host, const char *port, int family, int type, int protocol, do_server_cb cb, unsigned char *context, int naccept, BIO *bio_s_out); diff --git a/apps/lib/http_server.c b/apps/lib/http_server.c index 1858d04..03faac7 100644 --- a/apps/lib/http_server.c +++ b/apps/lib/http_server.c @@ -241,7 +241,7 @@ BIO *http_server_init_bio(const char *prog, const char *port) /* Report back what address and port are used */ BIO_get_fd(acbio, &asock); - if (!report_server_accept(bio_out, asock, 1)) { + if (!report_server_accept(bio_out, asock, 1, 1)) { log_message(prog, LOG_ERR, "Error printing ACCEPT string"); goto err; } diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c index fbe913e..36dbe61 100644 --- a/apps/lib/s_socket.c +++ b/apps/lib/s_socket.c @@ -191,9 +191,9 @@ out: return ret; } -int report_server_accept(BIO *out, int asock, int with_address) +int report_server_accept(BIO *out, int asock, int with_address, int with_pid) { - int success = 0; + int success = 1; if (BIO_printf(out, "ACCEPT") <= 0) return 0; @@ -205,22 +205,23 @@ int report_server_accept(BIO *out, int asock, int with_address) if ((info.addr = BIO_ADDR_new()) != NULL && BIO_sock_info(asock, BIO_SOCK_INFO_ADDRESS, &info) && (hostname = BIO_ADDR_hostname_string(info.addr, 1)) != NULL - && (service = BIO_ADDR_service_string(info.addr, 1)) != NULL - && BIO_printf(out, - strchr(hostname, ':') == NULL - ? /* IPv4 */ " %s:%s\n" - : /* IPv6 */ " [%s]:%s\n", - hostname, service) > 0) - success = 1; - else + && (service = BIO_ADDR_service_string(info.addr, 1)) != NULL) { + success = BIO_printf(out, + strchr(hostname, ':') == NULL + ? /* IPv4 */ " %s:%s" + : /* IPv6 */ " [%s]:%s", + hostname, service) > 0; + } else { (void)BIO_printf(out, "unknown:error\n"); - + success = 0; + } OPENSSL_free(hostname); OPENSSL_free(service); BIO_ADDR_free(info.addr); - } else if (BIO_printf(out, "\n") > 0) { - success = 1; } + if (with_pid) + success = success && BIO_printf(out, " PID=%d", getpid()) > 0; + success = success && BIO_printf(out, "\n") > 0; (void)BIO_flush(out); return success; @@ -331,7 +332,7 @@ int do_server(int *accept_sock, const char *host, const char *port, BIO_ADDRINFO_free(res); res = NULL; - if (!report_server_accept(bio_s_out, asock, sock_port == 0)) { + if (!report_server_accept(bio_s_out, asock, sock_port == 0, 0)) { BIO_closesocket(asock); ERR_print_errors(bio_err); goto end; -- cgit v1.1