[core] reset internal flags after graceful restart

reset internal socket flags after graceful restart:
re-init srv->socket->sidx and srv_socket->is_ssl
  after SIGUSR1 or systemd socket activation

(thx jens-maus)

x-ref:
  https://github.com/jens-maus/RaspberryMatic/pull/1847
master
Glenn Strauss 6 months ago
parent 33f73b4d82
commit da8025fb30
  1. 13
      src/network.c
  2. 4
      src/server.c

@ -425,6 +425,10 @@ static int network_server_init(server *srv, network_socket_config *s, buffer *ho
/* check if we already know this socket (after potential DNS resolution), and if yes, don't init it */
for (uint32_t i = 0; i < srv->srv_sockets.used; ++i) {
if (0 == memcmp(&srv->srv_sockets.ptr[i]->addr, &addr, sizeof(addr))) {
if ((unsigned short)~0u == srv->srv_sockets.ptr[i]->sidx) {
srv->srv_sockets.ptr[i]->sidx = sidx;
srv->srv_sockets.ptr[i]->is_ssl = s->ssl_enabled;
}
return 0;
}
}
@ -873,12 +877,21 @@ int network_init(server *srv, int stdin_fd) {
force_assert(NULL != srv_socket);
memcpy(srv_socket, srv->srv_sockets_inherited.ptr[i],
sizeof(server_socket));
srv_socket->is_ssl = p->defaults.ssl_enabled;
/*(note: re-inits srv_socket->srv_token to new buffer ptr)*/
network_srv_socket_init_token(srv_socket,srv_socket->srv_token);
network_srv_sockets_append(srv, srv_socket);
}
}
/* reset sidx of any graceful sockets not explicitly listed in config */
for (uint32_t i = 0; i < srv->srv_sockets.used; ++i) {
if ((unsigned short)~0u == srv->srv_sockets.ptr[i]->sidx) {
srv->srv_sockets.ptr[i]->sidx = 0;
srv->srv_sockets.ptr[i]->is_ssl = p->defaults.ssl_enabled;
}
}
} while (0);
free(p->cvlist);

@ -787,8 +787,10 @@ static void server_sockets_restore (server *srv) { /* graceful_restart */
memset(&graceful_sockets, 0, sizeof(server_socket_array));
memcpy(&srv->srv_sockets_inherited, &inherited_sockets, sizeof(server_socket_array));
memset(&inherited_sockets, 0, sizeof(server_socket_array));
for (uint32_t i = 0; i < srv->srv_sockets.used; ++i)
for (uint32_t i = 0; i < srv->srv_sockets.used; ++i) {
srv->srv_sockets.ptr[i]->srv = srv; /* update ptr */
srv->srv_sockets.ptr[i]->sidx= (unsigned short)~0u;
}
for (uint32_t i = 0; i < srv->srv_sockets_inherited.used; ++i)
srv->srv_sockets_inherited.ptr[i]->srv = srv; /* update ptr */
}

Loading…
Cancel
Save