mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 10:45:44 +01:00
ssl_server2 aborts cleanly on SIGTERM
(while waiting for a new connection)
This commit is contained in:
parent
6f4fbbb3e1
commit
db49330e08
@ -63,6 +63,7 @@ int main( int argc, char *argv[] )
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "polarssl/net.h"
|
||||
#include "polarssl/ssl.h"
|
||||
@ -564,10 +565,19 @@ int psk_callback( void *p_info, ssl_context *ssl,
|
||||
}
|
||||
#endif /* POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED */
|
||||
|
||||
/* Interruption handler to ensure clean exit (for valgrind testing) */
|
||||
static int listen_fd;
|
||||
static int received_sigterm = 0;
|
||||
void term_handler( int sig )
|
||||
{
|
||||
((void) sig);
|
||||
received_sigterm = 1;
|
||||
net_close( listen_fd ); /* causes net_accept() to abort */
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
int ret = 0, len, written, frags;
|
||||
int listen_fd;
|
||||
int client_fd = -1;
|
||||
int version_suites[4][2];
|
||||
unsigned char buf[IO_BUF_LEN];
|
||||
@ -635,6 +645,9 @@ int main( int argc, char *argv[] )
|
||||
memset( (void *) alpn_list, 0, sizeof( alpn_list ) );
|
||||
#endif
|
||||
|
||||
/* Abort cleanly on SIGTERM */
|
||||
signal( SIGTERM, term_handler );
|
||||
|
||||
if( argc == 0 )
|
||||
{
|
||||
usage:
|
||||
@ -1377,6 +1390,13 @@ reset:
|
||||
|
||||
if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 )
|
||||
{
|
||||
if( received_sigterm )
|
||||
{
|
||||
printf( " interrupted by SIGTERM\n" );
|
||||
ret = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " failed\n ! net_accept returned -0x%x\n\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user