commit 90d63d4711e9554b6e7e6e26d2fbeb50964452cf from: Stefan Sperling via: Thomas Adam date: Tue Aug 16 23:47:10 2022 UTC gotwebd: do not allocate server/socket list heads separately ok millert@ commit - 62f852145bf61e3ed9b42f7a00cd7cd0b5ff8835 commit + 90d63d4711e9554b6e7e6e26d2fbeb50964452cf blob - e8aec5bdf956a12e5a7477e7a16635ba28f99613 blob + 20a934f45f3def8b23ec73fe88593410a6bc39e1 --- gotwebd/config.c +++ gotwebd/config.c @@ -58,14 +58,8 @@ config_init(struct gotwebd *env) what = ps->ps_what[privsep_process]; if (what & CONFIG_SOCKS) { env->server_cnt = 0; - env->servers = calloc(1, sizeof(*env->servers)); - if (env->servers == NULL) - fatalx("%s: calloc", __func__); - env->sockets = calloc(1, sizeof(*env->sockets)); - if (env->sockets == NULL) - fatalx("%s: calloc", __func__); - TAILQ_INIT(env->servers); - TAILQ_INIT(env->sockets); + TAILQ_INIT(&env->servers); + TAILQ_INIT(&env->sockets); } return 0; } @@ -116,7 +110,7 @@ config_getserver(struct gotwebd *env, struct imsg *ims srv->name, srv->fcgi_socket ? "yes" : "no", srv->unix_socket ? "yes" : "no"); - TAILQ_INSERT_TAIL(env->servers, srv, entry); + TAILQ_INSERT_TAIL(&env->servers, srv, entry); return 0; } @@ -209,7 +203,7 @@ config_getsock(struct gotwebd *env, struct imsg *imsg) memcpy(&sock->conf, &sock_conf, sizeof(sock->conf)); sock->fd = imsg->fd; - TAILQ_INSERT_TAIL(env->sockets, sock, entry); + TAILQ_INSERT_TAIL(&env->sockets, sock, entry); for (i = 0; i < PRIV_FDS__MAX; i++) sock->priv_fd[i] = -1; @@ -299,7 +293,7 @@ config_getfd(struct gotwebd *env, struct imsg *imsg) IMSG_SIZE_CHECK(imsg, &sock_id); memcpy(&sock_id, p, sizeof(sock_id)); - TAILQ_FOREACH(sock, env->sockets, entry) { + TAILQ_FOREACH(sock, &env->sockets, entry) { const int nfds = (GOTWEB_PACK_NUM_TEMPFILES + PRIV_FDS__MAX); for (i = 0; i < nfds; i++) { if (i < PRIV_FDS__MAX && sock->priv_fd[i] == -1) { blob - ccc18c9026c8ac38a045a46f9170dbc3441feee7 blob + f7cde29268502cd5e4efef53f0888a485aca6057 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -308,24 +308,24 @@ gotweb_get_server(uint8_t *server_name, uint8_t *docum /* check against document_root first */ if (strlen(server_name) > 0) - TAILQ_FOREACH(srv, gotwebd_env->servers, entry) + TAILQ_FOREACH(srv, &gotwebd_env->servers, entry) if (strcmp(srv->name, server_name) == 0) goto done; /* check against document_root second */ if (strlen(document_root) > 0) - TAILQ_FOREACH(srv, gotwebd_env->servers, entry) + TAILQ_FOREACH(srv, &gotwebd_env->servers, entry) if (strcmp(srv->name, document_root) == 0) goto done; /* check against subdomain third */ if (strlen(subdomain) > 0) - TAILQ_FOREACH(srv, gotwebd_env->servers, entry) + TAILQ_FOREACH(srv, &gotwebd_env->servers, entry) if (strcmp(srv->name, subdomain) == 0) goto done; /* if those fail, send first server */ - TAILQ_FOREACH(srv, gotwebd_env->servers, entry) + TAILQ_FOREACH(srv, &gotwebd_env->servers, entry) if (srv != NULL) break; done: blob - 87a3096efd622c30cca639fa880db29b0fcd8c8c blob + 824c4c961044ae7e87a7077a5b10b2eac2ae769a --- gotwebd/gotwebd.c +++ gotwebd/gotwebd.c @@ -292,13 +292,13 @@ gotwebd_configure(struct gotwebd *env) env->gotwebd_reload = env->prefork_gotwebd; /* send our gotweb servers */ - TAILQ_FOREACH(srv, env->servers, entry) { + TAILQ_FOREACH(srv, &env->servers, entry) { if (config_setserver(env, srv) == -1) fatalx("%s: send server error", __func__); } /* send our sockets */ - TAILQ_FOREACH(sock, env->sockets, entry) { + TAILQ_FOREACH(sock, &env->sockets, entry) { if (config_setsock(env, sock) == -1) fatalx("%s: send socket error", __func__); if (config_setfd(env, sock) == -1) blob - 2d740d8c68ee194fe07fbfdcd32adc917ba70b44 blob + 0f238f4dcbdecd4cd7a5224cea8dd35c9bd25215 --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -328,8 +328,8 @@ struct socket { TAILQ_HEAD(socketlist, socket); struct gotwebd { - struct serverlist *servers; - struct socketlist *sockets; + struct serverlist servers; + struct socketlist sockets; struct privsep *gotwebd_ps; const char *gotwebd_conffile; blob - 08b1a2f6f58ebda079361a779c7749acb5a02cf7 blob + 55d6e2d21360d576e728f27c404db667eb55406b --- gotwebd/parse.y +++ gotwebd/parse.y @@ -215,7 +215,7 @@ main : PREFORK NUMBER { server : SERVER STRING { struct server *srv; - TAILQ_FOREACH(srv, gotwebd->servers, entry) { + TAILQ_FOREACH(srv, &gotwebd->servers, entry) { if (strcmp(srv->name, $2) == 0) { yyerror("server name exists '%s'", $2); free($2); @@ -238,7 +238,7 @@ server : SERVER STRING { | SERVER STRING { struct server *srv; - TAILQ_FOREACH(srv, gotwebd->servers, entry) { + TAILQ_FOREACH(srv, &gotwebd->servers, entry) { if (strcmp(srv->name, $2) == 0) { yyerror("server name exists '%s'", $2); free($2); @@ -396,7 +396,7 @@ socketopts1 : LISTEN ON STRING { | PORT fcgiport { struct server *srv; - TAILQ_FOREACH(srv, gotwebd->servers, entry) { + TAILQ_FOREACH(srv, &gotwebd->servers, entry) { if (srv->fcgi_socket_port == $2) { yyerror("port already assigned"); YYERROR; @@ -934,7 +934,7 @@ conf_new_server(const char *name) srv->fcgi_socket = gotwebd->fcgi_socket ? gotwebd->fcgi_socket : 0; TAILQ_INIT(&srv->al); - TAILQ_INSERT_TAIL(gotwebd->servers, srv, entry); + TAILQ_INSERT_TAIL(&gotwebd->servers, srv, entry); gotwebd->server_cnt++; return srv; blob - 283e69d247baeb718f827dfff89f769ca1e9e125 blob + 3ea1c38bdf0a4701eb6d6dceca1d8eb7364101c5 --- gotwebd/sockets.c +++ gotwebd/sockets.c @@ -123,22 +123,22 @@ sockets_parse_sockets(struct gotwebd *env) struct address *a; int sock_id = 0, ipv4 = 0, ipv6 = 0; - TAILQ_FOREACH(srv, env->servers, entry) { + TAILQ_FOREACH(srv, &env->servers, entry) { if (srv->unix_socket) { sock_id++; new_sock = sockets_conf_new_socket(env, srv, sock_id, UNIX, 0); - TAILQ_INSERT_TAIL(env->sockets, new_sock, entry); + TAILQ_INSERT_TAIL(&env->sockets, new_sock, entry); } if (srv->fcgi_socket) { sock_id++; new_sock = sockets_conf_new_socket(env, srv, sock_id, FCGI, 0); - TAILQ_INSERT_TAIL(env->sockets, new_sock, entry); + TAILQ_INSERT_TAIL(&env->sockets, new_sock, entry); /* add ipv6 children */ - TAILQ_FOREACH(sock, env->sockets, entry) { + TAILQ_FOREACH(sock, &env->sockets, entry) { ipv4 = ipv6 = 0; TAILQ_FOREACH(a, &sock->conf.al, entry) { @@ -155,7 +155,7 @@ sockets_parse_sockets(struct gotwebd *env) new_sock = sockets_conf_new_socket(env, srv, sock_id, FCGI, 1); sockets_dup_new_socket(sock, new_sock); - TAILQ_INSERT_TAIL(env->sockets, + TAILQ_INSERT_TAIL(&env->sockets, new_sock, entry); continue; } @@ -284,7 +284,7 @@ sockets_launch(void) { struct socket *sock; - TAILQ_FOREACH(sock, gotwebd_env->sockets, entry) { + TAILQ_FOREACH(sock, &gotwebd_env->sockets, entry) { log_debug("%s: configuring socket %d (%d)", __func__, sock->conf.id, sock->fd); @@ -307,7 +307,7 @@ sockets_purge(struct gotwebd *env) struct socket *sock, *tsock; /* shutdown and remove sockets */ - TAILQ_FOREACH_SAFE(sock, env->sockets, entry, tsock) { + TAILQ_FOREACH_SAFE(sock, &env->sockets, entry, tsock) { if (event_initialized(&sock->ev)) event_del(&sock->ev); if (evtimer_initialized(&sock->evt)) @@ -316,7 +316,7 @@ sockets_purge(struct gotwebd *env) evtimer_del(&sock->pause); if (sock->fd != -1) close(sock->fd); - TAILQ_REMOVE(env->sockets, sock, entry); + TAILQ_REMOVE(&env->sockets, sock, entry); } } @@ -394,18 +394,16 @@ sockets_shutdown(void) sockets_purge(gotwebd_env); /* clean sockets */ - TAILQ_FOREACH_SAFE(sock, gotwebd_env->sockets, entry, tsock) { - TAILQ_REMOVE(gotwebd_env->sockets, sock, entry); + TAILQ_FOREACH_SAFE(sock, &gotwebd_env->sockets, entry, tsock) { + TAILQ_REMOVE(&gotwebd_env->sockets, sock, entry); close(sock->fd); free(sock); } /* clean servers */ - TAILQ_FOREACH_SAFE(srv, gotwebd_env->servers, entry, tsrv) + TAILQ_FOREACH_SAFE(srv, &gotwebd_env->servers, entry, tsrv) free(srv); - free(gotwebd_env->sockets); - free(gotwebd_env->servers); free(gotwebd_env); } @@ -447,7 +445,7 @@ sockets_unix_socket_listen(struct privsep *ps, struct int u_fd = -1; mode_t old_umask, mode; - TAILQ_FOREACH(tsock, env->sockets, entry) { + TAILQ_FOREACH(tsock, &env->sockets, entry) { if (strcmp(tsock->conf.unix_socket_name, sock->conf.unix_socket_name) == 0 && tsock->fd != -1)