commit 8507d3d5b7832bfe03b50521368f4829ceb782586ac8e40398196e724caec3de from: Tracey Emery date: Tue Nov 10 16:30:14 2026 UTC run a single sockets process Drop the prefork pool of sockets processes. Connections are long-lived, so balancing them once at accept() across N processes by kernel lottery never rebalanced anything, and every listener-scoped fact (per-listener connection counts, bridge placement, mqttctl show listeners) had to be summed over N. The parent, broker and control each talk to one sockets pipe now. "prefork" in mqttd.conf is still parsed and logs a deprecation warning. The broker keeps its per-process routing index so the coming listen/worker split does not touch it again. commit - 605bf9f121de8fbec15a7e6f15f1060ed29ee16c831b7597f4a351afa5806a3a commit + 8507d3d5b7832bfe03b50521368f4829ceb782586ac8e40398196e724caec3de blob - 86ba75eaa735b2ed45091ebaab4b6dc2d682b89a3cec821a0963a16ce11f7c38 blob + e8bd3e9700c6d0061d25b3a4b0ddda72267fe3dc9952548d8d8fba7b1b382f2f --- README.md +++ README.md @@ -10,8 +10,8 @@ Aware behaviour and topic ACLs with password, certific authentication. The daemon is split into a privileged parent, a control process, a single -broker process holding all protocol state, and a configurable number of -preforked sockets processes that own the network connections and TLS. +broker process holding all protocol state, and a sockets process that +owns the network connections and TLS. The layout and plumbing come from the thingsd proxy daemon. Prerequisites blob - 63cb40e9fd999f3a04529bf015f343349db5b30abbf3480783887288c069d608 blob + 024ceec5cb3ff0c4be2245ce6c3448bcc147ea37bee3d844eff7d1fb398ed58d --- mqttctl/mqttctl.c +++ mqttctl/mqttctl.c @@ -338,7 +338,6 @@ show_parent_msg(struct imsg *imsg) printf(" started: %s\n", fmt_time(pi.started)); printf(" uptime: %s\n", fmt_duration(time(NULL) - pi.started, dbuf, sizeof(dbuf))); - printf(" sockets processes: %u\n", pi.prefork); printf(" listeners: %u\n", pi.nlisteners); break; case IMSG_CTL_SHOW_PARENT_END: blob - 615e5c9904a4de5cf302e777413092e27393f9203ffbce9538d42cbddff7ac99 blob + c47a03beeff7e1b2c59dddc04d810c80e8011009a1b995987ed801adb8a9a708 --- mqttd/broker.c +++ mqttd/broker.c @@ -71,15 +71,15 @@ static struct imsgev *broker_iev_auth; static struct imsgev *broker_iev_snow; static uint32_t auth_next_id; -/* sockets processes by index, or the snowflake process */ +/* the sockets process, or the snowflake process */ static struct imsgev * broker_proc_iev(uint32_t proc) { if (proc == MQTTD_PROC_SNOW) return (broker_iev_snow); - if (proc >= env->conf.prefork) + if (proc != 0) return (NULL); - return (&broker_iev_socks[proc]); + return (broker_iev_socks); } struct route_ctx { @@ -181,10 +181,9 @@ user_entry_cmp(struct user_entry *a, struct user_entry __dead void broker(int fd_parent, int fd_control, int fd_storage, int fd_auth, - int fd_snow, int *fd_socks) + int fd_snow, int fd_socks) { struct timeval tv; - int n; log_procinit("broker"); proc_privdrop("broker"); @@ -240,12 +239,9 @@ broker(int fd_parent, int fd_control, int fd_storage, fatal("%s: calloc", __func__); imsg_event_init(broker_iev_snow, fd_snow, broker_dispatch_sockets); - if ((broker_iev_socks = calloc(env->conf.prefork, - sizeof(*broker_iev_socks))) == NULL) + if ((broker_iev_socks = calloc(1, sizeof(*broker_iev_socks))) == NULL) fatal("%s: calloc", __func__); - for (n = 0; n < env->conf.prefork; n++) - imsg_event_init(&broker_iev_socks[n], fd_socks[n], - broker_dispatch_sockets); + imsg_event_init(broker_iev_socks, fd_socks, broker_dispatch_sockets); evtimer_set(&ev_sweep, broker_sweep, NULL); tv.tv_sec = MQTTD_RETAIN_SWEEP; @@ -301,8 +297,6 @@ broker_sweep(int fd, short event, void *arg) static __dead void broker_shutdown(void) { - int n; - /* the last snapshot must reach storage before the pipe closes */ db_snapshot_sync(); @@ -322,8 +316,7 @@ broker_shutdown(void) imsg_event_shutdown(broker_iev_snow); free(broker_iev_snow); } - for (n = 0; n < env->conf.prefork; n++) - imsg_event_shutdown(&broker_iev_socks[n]); + imsg_event_shutdown(broker_iev_socks); free(broker_iev_socks); log_info("broker exiting, pid %d", getpid()); @@ -662,8 +655,7 @@ broker_dispatch_sockets(int fd, short event, void *arg uint32_t proc; int n; - proc = iev == broker_iev_snow ? MQTTD_PROC_SNOW : - (uint32_t)(iev - broker_iev_socks); + proc = iev == broker_iev_snow ? MQTTD_PROC_SNOW : 0; if (event & EV_READ) { if ((n = imsgbuf_read(ibuf)) == -1) @@ -741,24 +733,22 @@ broker_socks_event_add(struct imsgev *iev) } /* - * Backpressure. When any sockets pipe holds more than MQTTD_QUEUE_HIGH - * unsent messages the broker stops reading from every sockets process, - * so publishers stall instead of the broker growing without bound. - * Reading resumes once every pipe is below MQTTD_QUEUE_LOW. + * Backpressure. When the sockets pipe or the snowflake pipe holds more + * than MQTTD_QUEUE_HIGH unsent messages the broker stops reading from + * both, so publishers stall instead of the broker growing without bound. + * Reading resumes once both pipes are below MQTTD_QUEUE_LOW. */ static void broker_flow_update(void) { size_t q; - int n, over = 0, above_low = 0; + int over = 0, above_low = 0; - for (n = 0; n < env->conf.prefork; n++) { - q = imsgbuf_queuelen(&broker_iev_socks[n].ibuf); - if (q > MQTTD_QUEUE_HIGH) - over = 1; - if (q > MQTTD_QUEUE_LOW) - above_low = 1; - } + q = imsgbuf_queuelen(&broker_iev_socks->ibuf); + if (q > MQTTD_QUEUE_HIGH) + over = 1; + if (q > MQTTD_QUEUE_LOW) + above_low = 1; if (broker_iev_snow != NULL) { q = imsgbuf_queuelen(&broker_iev_snow->ibuf); if (q > MQTTD_QUEUE_HIGH) @@ -776,8 +766,7 @@ broker_flow_update(void) } else return; - for (n = 0; n < env->conf.prefork; n++) - broker_socks_event_add(&broker_iev_socks[n]); + broker_socks_event_add(broker_iev_socks); if (broker_iev_snow != NULL) broker_socks_event_add(broker_iev_snow); } blob - 2fb538fa061e09d314f3733770a7cb7704b31e0bd95030fba26272e921074105 blob + 512395aa375e2bde98bf428ceb550fedaaf686db68bea2c7a85b0dfe00f77c5d --- mqttd/control.c +++ mqttd/control.c @@ -49,7 +49,6 @@ struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; struct imsgev iev; struct sockpeercred peercred; - int listeners_pending; }; TAILQ_HEAD(ctl_connlist, ctl_conn); @@ -82,10 +81,8 @@ static __dead void control_shutdown(void); __dead void -control(int fd_parent, int fd_broker, int *fd_socks) +control(int fd_parent, int fd_broker, int fd_socks) { - int n; - log_procinit("control"); /* the socket is bound as root, before the chroot */ @@ -120,12 +117,11 @@ control(int fd_parent, int fd_broker, int *fd_socks) imsg_event_init(control_iev_broker, fd_broker, control_dispatch_broker); - if ((control_iev_socks = calloc(env->conf.prefork, - sizeof(*control_iev_socks))) == NULL) + if ((control_iev_socks = calloc(1, sizeof(*control_iev_socks))) + == NULL) fatal("%s: calloc", __func__); - for (n = 0; n < env->conf.prefork; n++) - imsg_event_init(&control_iev_socks[n], fd_socks[n], - control_dispatch_sockets); + imsg_event_init(control_iev_socks, fd_socks, + control_dispatch_sockets); TAILQ_INIT(&ctl_conns); @@ -161,7 +157,6 @@ static __dead void control_shutdown(void) { struct ctl_conn *c; - int n; control_cleanup(&control_cs); @@ -175,8 +170,7 @@ control_shutdown(void) free(control_iev_parent); imsg_event_shutdown(control_iev_broker); free(control_iev_broker); - for (n = 0; n < env->conf.prefork; n++) - imsg_event_shutdown(&control_iev_socks[n]); + imsg_event_shutdown(control_iev_socks); free(control_iev_socks); log_info("control exiting, pid %d", getpid()); @@ -309,7 +303,6 @@ control_dispatch_sockets(int fd, short event, void *ar struct imsgev *iev = arg; struct imsgbuf *ibuf = &iev->ibuf; struct imsg imsg; - struct ctl_conn *c; int n; if (event & EV_READ) { @@ -338,16 +331,8 @@ control_dispatch_sockets(int fd, short event, void *ar switch (imsg.hdr.type) { case IMSG_CTL_SHOW_LISTENERS_DATA: - control_relay(&imsg); - break; case IMSG_CTL_SHOW_LISTENERS_END: - /* - * Every sockets process answers, so the end marker - * is passed on once the last one has replied. - */ - c = control_connbyfd(imsg.hdr.peerid); - if (c != NULL && --c->listeners_pending == 0) - control_relay(&imsg); + control_relay(&imsg); break; default: log_warnx("%s: unexpected imsg %d from sockets", @@ -618,8 +603,6 @@ control_dispatch_imsg(int fd, short event, void *arg) 0, 0, -1, NULL, 0); break; case IMSG_CTL_SHOW_LISTENERS_REQUEST: - c->listeners_pending = env->conf.prefork; - /* FALLTHROUGH */ case IMSG_CTL_SHOW_PARENT_REQUEST: case IMSG_CTL_SHOW_BROKER_REQUEST: case IMSG_CTL_SHOW_CLIENTS_REQUEST: blob - d9a4ef5672a8d27051390245fa4e28002e8069c99c6f8285f3c8a59225f1646c blob + 412c68b097457a0a5dee2463afc903894b23fff1508e1de12cda91ff6f49e84e --- mqttd/mqttd.8 +++ mqttd/mqttd.8 @@ -72,9 +72,8 @@ warehouse confirmed. The parent resolves names and signs its JWTs so it needs neither DNS nor the private key. .It sockets -A configurable number of preforked processes which accept connections, -run TLS, split the byte stream into control packets and relay them to -the broker. +Accepts connections, runs TLS, splits the byte stream into control +packets and relays them to the broker. .El .Pp Apart from auth, all children run @@ -142,7 +141,6 @@ the configuration is re-read: limits, users, ACLs, TLS listeners take effect immediately without dropping connections; a removed listener's existing clients stay connected. Changes to -.Ic prefork , .Ic persistence , .Ic auth or bridges are reported in the log and need a restart. blob - 61440506ee13e193d055e45631203af3f5c224386d370f26e5b9ace73c82ac57 blob + 1cc61a93d33ca7110f189e306477af4a169866335eaecfbea136bb9822813120 --- mqttd/mqttd.c +++ mqttd/mqttd.c @@ -211,7 +211,7 @@ parent_dispatch_control(int fd, short event, void *arg struct imsgev *iev = arg; struct imsgbuf *ibuf = &iev->ibuf; struct imsg imsg; - int i, n, verbose; + int n, verbose; if (event & EV_READ) { if ((n = imsgbuf_read(ibuf)) == -1) @@ -252,16 +252,14 @@ parent_dispatch_control(int fd, short event, void *arg imsg_forward_event(parent_iev_broker, &imsg); break; case IMSG_CTL_SHOW_LISTENERS_REQUEST: - for (i = 0; i < env->conf.prefork; i++) - imsg_forward_event(&parent_iev_socks[i], &imsg); + imsg_forward_event(parent_iev_socks, &imsg); break; case IMSG_CTL_VERBOSE: IMSG_SIZE_CHECK(&imsg, &verbose); memcpy(&verbose, imsg.data, sizeof(verbose)); log_setverbose(verbose); imsg_forward_event(parent_iev_broker, &imsg); - for (i = 0; i < env->conf.prefork; i++) - imsg_forward_event(&parent_iev_socks[i], &imsg); + imsg_forward_event(parent_iev_socks, &imsg); break; default: log_warnx("%s: unexpected imsg %d from control", @@ -613,7 +611,7 @@ main(int argc, char **argv) struct mqttd *e; const char *conffile = MQTTD_CONF; struct stat st; - int ch, i, n; + int ch; int pipe_control[2]; int pipe_broker[2]; int pipe_storage[2]; @@ -623,10 +621,9 @@ main(int argc, char **argv) int pipe_broker_auth[2]; int pipe_snow[2]; int pipe_broker_snow[2]; - int pipe_socks[MQTTD_MAX_PREFORK][2]; - int pipe_control_socks[MQTTD_MAX_PREFORK][2]; - int pipe_broker_socks[MQTTD_MAX_PREFORK][2]; - int fds[MQTTD_MAX_PREFORK]; + int pipe_socks[2]; + int pipe_control_socks[2]; + int pipe_broker_socks[2]; if ((e = calloc(1, sizeof(*e))) == NULL) fatal("%s: calloc", __func__); @@ -723,19 +720,16 @@ main(int argc, char **argv) socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, pipe_snow) == -1 || socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, - pipe_broker_snow) == -1) + pipe_broker_snow) == -1 || + socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, + pipe_socks) == -1 || + socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, + pipe_control_socks) == -1 || + socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, + pipe_broker_socks) == -1) fatal("%s: socketpair", __func__); - for (i = 0; i < e->conf.prefork; i++) { - if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, - pipe_socks[i]) == -1 || - socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, - pipe_control_socks[i]) == -1 || - socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, - pipe_broker_socks[i]) == -1) - fatal("%s: socketpair", __func__); - } - /* control: parent[1], control_broker[0], control_socks[i][0] */ + /* control: parent[1], control_broker[0], control_socks[0] */ switch (fork()) { case -1: fatal("%s: fork", __func__); @@ -756,15 +750,13 @@ main(int argc, char **argv) close(pipe_broker_auth[1]); close(pipe_broker_snow[0]); close(pipe_broker_snow[1]); - for (i = 0; i < e->conf.prefork; i++) { - close(pipe_socks[i][0]); - close(pipe_socks[i][1]); - close(pipe_control_socks[i][1]); - close(pipe_broker_socks[i][0]); - close(pipe_broker_socks[i][1]); - fds[i] = pipe_control_socks[i][0]; - } - control(pipe_control[1], pipe_control_broker[0], fds); + close(pipe_socks[0]); + close(pipe_socks[1]); + close(pipe_control_socks[1]); + close(pipe_broker_socks[0]); + close(pipe_broker_socks[1]); + control(pipe_control[1], pipe_control_broker[0], + pipe_control_socks[0]); /* NOTREACHED */ } @@ -789,14 +781,12 @@ main(int argc, char **argv) close(pipe_broker_auth[0]); close(pipe_broker_auth[1]); close(pipe_broker_snow[0]); - for (i = 0; i < e->conf.prefork; i++) { - close(pipe_socks[i][0]); - close(pipe_socks[i][1]); - close(pipe_control_socks[i][0]); - close(pipe_control_socks[i][1]); - close(pipe_broker_socks[i][0]); - close(pipe_broker_socks[i][1]); - } + close(pipe_socks[0]); + close(pipe_socks[1]); + close(pipe_control_socks[0]); + close(pipe_control_socks[1]); + close(pipe_broker_socks[0]); + close(pipe_broker_socks[1]); snowflake(pipe_snow[1], pipe_broker_snow[1]); /* NOTREACHED */ } @@ -822,14 +812,12 @@ main(int argc, char **argv) close(pipe_broker_auth[1]); close(pipe_broker_snow[0]); close(pipe_broker_snow[1]); - for (i = 0; i < e->conf.prefork; i++) { - close(pipe_socks[i][0]); - close(pipe_socks[i][1]); - close(pipe_control_socks[i][0]); - close(pipe_control_socks[i][1]); - close(pipe_broker_socks[i][0]); - close(pipe_broker_socks[i][1]); - } + close(pipe_socks[0]); + close(pipe_socks[1]); + close(pipe_control_socks[0]); + close(pipe_control_socks[1]); + close(pipe_broker_socks[0]); + close(pipe_broker_socks[1]); storage(pipe_storage[1], pipe_broker_storage[1]); /* NOTREACHED */ } @@ -855,14 +843,12 @@ main(int argc, char **argv) close(pipe_broker_auth[0]); close(pipe_broker_snow[0]); close(pipe_broker_snow[1]); - for (i = 0; i < e->conf.prefork; i++) { - close(pipe_socks[i][0]); - close(pipe_socks[i][1]); - close(pipe_control_socks[i][0]); - close(pipe_control_socks[i][1]); - close(pipe_broker_socks[i][0]); - close(pipe_broker_socks[i][1]); - } + close(pipe_socks[0]); + close(pipe_socks[1]); + close(pipe_control_socks[0]); + close(pipe_control_socks[1]); + close(pipe_broker_socks[0]); + close(pipe_broker_socks[1]); auth(pipe_auth[1], pipe_broker_auth[1]); /* NOTREACHED */ } @@ -885,58 +871,46 @@ main(int argc, char **argv) close(pipe_broker_storage[1]); close(pipe_broker_auth[1]); close(pipe_broker_snow[1]); - for (i = 0; i < e->conf.prefork; i++) { - close(pipe_socks[i][0]); - close(pipe_socks[i][1]); - close(pipe_control_socks[i][0]); - close(pipe_control_socks[i][1]); - close(pipe_broker_socks[i][1]); - fds[i] = pipe_broker_socks[i][0]; - } + close(pipe_socks[0]); + close(pipe_socks[1]); + close(pipe_control_socks[0]); + close(pipe_control_socks[1]); + close(pipe_broker_socks[1]); broker(pipe_broker[1], pipe_control_broker[1], pipe_broker_storage[0], pipe_broker_auth[0], - pipe_broker_snow[0], fds); + pipe_broker_snow[0], pipe_broker_socks[0]); /* NOTREACHED */ } - /* sockets n: socks[n][1], control_socks[n][1], broker_socks[n][1] */ - for (n = 0; n < e->conf.prefork; n++) { - switch (fork()) { - case -1: - fatal("%s: fork", __func__); - case 0: - close(pipe_control[0]); - close(pipe_control[1]); - close(pipe_broker[0]); - close(pipe_broker[1]); - close(pipe_storage[0]); - close(pipe_storage[1]); - close(pipe_auth[0]); - close(pipe_auth[1]); - close(pipe_snow[0]); - close(pipe_snow[1]); - close(pipe_control_broker[0]); - close(pipe_control_broker[1]); - close(pipe_broker_storage[0]); - close(pipe_broker_storage[1]); - close(pipe_broker_auth[0]); - close(pipe_broker_auth[1]); - close(pipe_broker_snow[0]); - close(pipe_broker_snow[1]); - for (i = 0; i < e->conf.prefork; i++) { - close(pipe_socks[i][0]); - close(pipe_control_socks[i][0]); - close(pipe_broker_socks[i][0]); - if (i == n) - continue; - close(pipe_socks[i][1]); - close(pipe_control_socks[i][1]); - close(pipe_broker_socks[i][1]); - } - sockets(pipe_socks[n][1], pipe_control_socks[n][1], - pipe_broker_socks[n][1]); - /* NOTREACHED */ - } + /* sockets: socks[1], control_socks[1], broker_socks[1] */ + switch (fork()) { + case -1: + fatal("%s: fork", __func__); + case 0: + close(pipe_control[0]); + close(pipe_control[1]); + close(pipe_broker[0]); + close(pipe_broker[1]); + close(pipe_storage[0]); + close(pipe_storage[1]); + close(pipe_auth[0]); + close(pipe_auth[1]); + close(pipe_snow[0]); + close(pipe_snow[1]); + close(pipe_control_broker[0]); + close(pipe_control_broker[1]); + close(pipe_broker_storage[0]); + close(pipe_broker_storage[1]); + close(pipe_broker_auth[0]); + close(pipe_broker_auth[1]); + close(pipe_broker_snow[0]); + close(pipe_broker_snow[1]); + close(pipe_socks[0]); + close(pipe_control_socks[0]); + close(pipe_broker_socks[0]); + sockets(pipe_socks[1], pipe_control_socks[1], + pipe_broker_socks[1]); + /* NOTREACHED */ } /* parent: the [0] end of every pipe to a child */ @@ -953,13 +927,11 @@ main(int argc, char **argv) close(pipe_broker_auth[1]); close(pipe_broker_snow[0]); close(pipe_broker_snow[1]); - for (i = 0; i < e->conf.prefork; i++) { - close(pipe_socks[i][1]); - close(pipe_control_socks[i][0]); - close(pipe_control_socks[i][1]); - close(pipe_broker_socks[i][0]); - close(pipe_broker_socks[i][1]); - } + close(pipe_socks[1]); + close(pipe_control_socks[0]); + close(pipe_control_socks[1]); + close(pipe_broker_socks[0]); + close(pipe_broker_socks[1]); event_init(); @@ -1000,12 +972,10 @@ main(int argc, char **argv) fatal("%s: calloc", __func__); imsg_event_init(parent_iev_snow, pipe_snow[0], parent_dispatch_snow); - if ((parent_iev_socks = calloc(e->conf.prefork, - sizeof(*parent_iev_socks))) == NULL) + if ((parent_iev_socks = calloc(1, sizeof(*parent_iev_socks))) == NULL) fatal("%s: calloc", __func__); - for (i = 0; i < e->conf.prefork; i++) - imsg_event_init(&parent_iev_socks[i], pipe_socks[i][0], - parent_dispatch_sockets); + imsg_event_init(parent_iev_socks, pipe_socks[0], + parent_dispatch_sockets); if (parent_configure(e) == -1) fatalx("configuration failed"); @@ -1013,7 +983,7 @@ main(int argc, char **argv) /* * A reload re-parses (rpath dns route), may bind new listeners * (inet unix cpath fattr) and hands their descriptors to the - * sockets processes (sendfd). + * sockets process (sendfd). */ if (pledge("stdio rpath inet dns route proc sendfd unix cpath fattr", NULL) == -1) @@ -1031,7 +1001,7 @@ parent_configure(struct mqttd *e) struct user *u; struct acl *a; struct bridge_def *b; - int n, fd; + int fd; TAILQ_FOREACH(l, &e->listeners, entry) { if (sockets_create_listener(l) == -1) @@ -1039,19 +1009,16 @@ parent_configure(struct mqttd *e) if (listener_tls_load(l) == -1) return (-1); - for (n = 0; n < e->conf.prefork; n++) { - if ((fd = dup(l->fd)) == -1) { - log_warn("%s: dup", __func__); - return (-1); - } - if (config_send_listener(&parent_iev_socks[n], l, - fd) == -1) - return (-1); - if (config_send_tls(&parent_iev_socks[n], l) == -1) - return (-1); + if ((fd = dup(l->fd)) == -1) { + log_warn("%s: dup", __func__); + return (-1); } + if (config_send_listener(parent_iev_socks, l, fd) == -1) + return (-1); + if (config_send_tls(parent_iev_socks, l) == -1) + return (-1); - /* the children hold their own copies now */ + /* the sockets process holds its own copy now */ close(l->fd); l->fd = -1; freezero(l->conf.tls_key, l->conf.tls_key_len); @@ -1067,9 +1034,8 @@ parent_configure(struct mqttd *e) return (-1); if (config_send_global(parent_iev_snow, e) == -1) return (-1); - for (n = 0; n < e->conf.prefork; n++) - if (config_send_global(&parent_iev_socks[n], e) == -1) - return (-1); + if (config_send_global(parent_iev_socks, e) == -1) + return (-1); TAILQ_FOREACH(u, &e->users, entry) if (config_send_user(parent_iev_broker, u) == -1) @@ -1111,7 +1077,7 @@ parent_configure(struct mqttd *e) return (-1); continue; } - b->conf.proc = b->conf.id % e->conf.prefork; + b->conf.proc = 0; if (b->conf.tls) { b->conf.tls_ca = tls_load_file(b->conf.tls_ca_file != NULL ? b->conf.tls_ca_file : MQTTD_BRIDGE_CA, @@ -1123,12 +1089,10 @@ parent_configure(struct mqttd *e) } if (config_send_bridge(parent_iev_broker, b) == -1) return (-1); - if (imsg_compose_event(&parent_iev_socks[b->conf.proc], - IMSG_CFG_BRIDGE, 0, 0, -1, &b->conf, - sizeof(b->conf)) == -1) + if (imsg_compose_event(parent_iev_socks, IMSG_CFG_BRIDGE, 0, 0, + -1, &b->conf, sizeof(b->conf)) == -1) return (-1); - if (config_send_bridge_ca(&parent_iev_socks[b->conf.proc], - b) == -1) + if (config_send_bridge_ca(parent_iev_socks, b) == -1) return (-1); explicit_bzero(b->conf.password, sizeof(b->conf.password)); } @@ -1138,15 +1102,13 @@ parent_configure(struct mqttd *e) * The broker only acknowledges once storage has replayed the last * snapshot into it, so no client connects to a half restored state. */ - e->cfg_pending = 4 + e->conf.prefork; + e->cfg_pending = 5; imsg_compose_event(parent_iev_storage, IMSG_CFG_DONE, 0, 0, -1, NULL, 0); imsg_compose_event(parent_iev_auth, IMSG_CFG_DONE, 0, 0, -1, NULL, 0); imsg_compose_event(parent_iev_snow, IMSG_CFG_DONE, 0, 0, -1, NULL, 0); imsg_compose_event(parent_iev_broker, IMSG_CFG_DONE, 0, 0, -1, NULL, 0); - for (n = 0; n < e->conf.prefork; n++) - imsg_compose_event(&parent_iev_socks[n], IMSG_CFG_DONE, 0, 0, - -1, NULL, 0); + imsg_compose_event(parent_iev_socks, IMSG_CFG_DONE, 0, 0, -1, NULL, 0); return (0); } @@ -1154,8 +1116,6 @@ parent_configure(struct mqttd *e) static void parent_configure_done(struct mqttd *e) { - int n; - if (e->cfg_pending == 0) { log_warnx("%s: configuration already finished", __func__); return; @@ -1172,12 +1132,9 @@ parent_configure_done(struct mqttd *e) 0); imsg_compose_event(parent_iev_auth, IMSG_CTL_START, 0, 0, -1, NULL, 0); imsg_compose_event(parent_iev_snow, IMSG_CTL_START, 0, 0, -1, NULL, 0); - for (n = 0; n < e->conf.prefork; n++) - imsg_compose_event(&parent_iev_socks[n], IMSG_CTL_START, 0, 0, - -1, NULL, 0); + imsg_compose_event(parent_iev_socks, IMSG_CTL_START, 0, 0, -1, NULL, 0); - log_info("%s ready, %u listener(s), %u sockets process(es)", - getprogname(), e->nlisteners, e->conf.prefork); + log_info("%s ready, %u listener(s)", getprogname(), e->nlisteners); } static int @@ -1208,8 +1165,8 @@ sockaddr_same(struct sockaddr_storage *a, struct socka } /* - * SIGHUP: re-read the configuration. Limits, users, ACLs and TLS - * material take effect at once. Listeners, prefork and persistence are + * SIGHUP: re-read the configuration. Limits, users, ACLs, listeners and + * TLS material take effect at once. Persistence, auth and bridges are * fixed at startup because the children holding them are chrooted and * pledged; changes there are reported and need a restart. */ @@ -1221,7 +1178,7 @@ parent_reload(struct mqttd *e) struct user *u; struct acl *a; struct bridge_def *b; - int i, fd; + int fd; log_info("reloading configuration from %s", e->conffile); @@ -1241,10 +1198,6 @@ parent_reload(struct mqttd *e) return; } - if (n->conf.prefork != e->conf.prefork) { - log_warnx("prefork changed, a restart is needed for that"); - n->conf.prefork = e->conf.prefork; - } if (n->conf.persist != e->conf.persist || strcmp(n->dbdir, e->dbdir) != 0) { log_warnx("persistence settings changed, a restart is needed " @@ -1291,14 +1244,10 @@ parent_reload(struct mqttd *e) "material", nl->conf.name); continue; } - for (i = 0; i < e->conf.prefork; i++) { - if (config_send_tls(&parent_iev_socks[i], - nl) == -1) - break; - imsg_compose_event(&parent_iev_socks[i], + if (config_send_tls(parent_iev_socks, nl) == 0) + imsg_compose_event(parent_iev_socks, IMSG_CFG_TLS_DONE, 0, 0, -1, &nl->conf.id, sizeof(nl->conf.id)); - } } else { if (sockets_create_listener(nl) == -1 || listener_tls_load(nl) == -1) { @@ -1307,17 +1256,13 @@ parent_reload(struct mqttd *e) nl->conf.id = 0; continue; } - for (i = 0; i < e->conf.prefork; i++) { - if ((fd = dup(nl->fd)) == -1 || - config_send_listener(&parent_iev_socks[i], - nl, fd) == -1 || - config_send_tls(&parent_iev_socks[i], - nl) == -1) - break; - imsg_compose_event(&parent_iev_socks[i], + if ((fd = dup(nl->fd)) != -1 && + config_send_listener(parent_iev_socks, nl, + fd) == 0 && + config_send_tls(parent_iev_socks, nl) == 0) + imsg_compose_event(parent_iev_socks, IMSG_CFG_LISTENER_START, 0, 0, -1, &nl->conf.id, sizeof(nl->conf.id)); - } close(nl->fd); nl->fd = -1; log_info("listener %s added", nl->conf.name); @@ -1329,10 +1274,9 @@ parent_reload(struct mqttd *e) TAILQ_FOREACH_SAFE(ol, &e->listeners, entry, tl) { if (ol->fd != -2) { - for (i = 0; i < e->conf.prefork; i++) - imsg_compose_event(&parent_iev_socks[i], - IMSG_CFG_LISTENER_DEL, 0, 0, -1, - &ol->conf.id, sizeof(ol->conf.id)); + imsg_compose_event(parent_iev_socks, + IMSG_CFG_LISTENER_DEL, 0, 0, -1, &ol->conf.id, + sizeof(ol->conf.id)); log_info("listener %s removed", ol->conf.name); } ol->fd = -1; @@ -1367,8 +1311,7 @@ parent_reload(struct mqttd *e) config_send_global(parent_iev_storage, e); config_send_global(parent_iev_auth, e); config_send_global(parent_iev_snow, e); - for (i = 0; i < e->conf.prefork; i++) - config_send_global(&parent_iev_socks[i], e); + config_send_global(parent_iev_socks, e); imsg_compose_event(parent_iev_broker, IMSG_CFG_AUTH_RESET, 0, 0, -1, NULL, 0); @@ -1387,7 +1330,6 @@ parent_show_info(struct imsg *imsg) memset(&pi, 0, sizeof(pi)); pi.verbose = log_getverbose(); - pi.prefork = env->conf.prefork; pi.nlisteners = env->nlisteners; pi.started = env->started; @@ -1405,7 +1347,7 @@ parent_shutdown(struct mqttd *e) struct acl *a; struct bridge_def *b; pid_t pid; - int n, status; + int status; /* closing the pipes tells the children to exit */ imsg_event_shutdown(parent_iev_control); @@ -1418,8 +1360,7 @@ parent_shutdown(struct mqttd *e) free(parent_iev_auth); imsg_event_shutdown(parent_iev_snow); free(parent_iev_snow); - for (n = 0; n < e->conf.prefork; n++) - imsg_event_shutdown(&parent_iev_socks[n]); + imsg_event_shutdown(parent_iev_socks); free(parent_iev_socks); log_debug("waiting for children to terminate"); blob - 39ef196a560787977e63fc84a10b25618e336828f2409a3135fe744f2b341cc1 blob + 7dab33d363d26b173b9e0d1e43dc33514febec4ecba7e1cc34cae888a24bcbeb --- mqttd/mqttd.conf.5 +++ mqttd/mqttd.conf.5 @@ -195,10 +195,6 @@ It must exist and be owned by the user; the storage process is chrooted into it. The default is .Pa /var/db/mqttd . -.It Ic prefork Ar number -Run the specified number of sockets processes. -Connections are spread over them by the kernel. -The default is 3. .It Ic retain Pq Ic yes Ns | Ns Ic no Whether retained messages are supported. The default is @@ -570,7 +566,6 @@ Example configuration file. .Sh EXAMPLES A broker for a fleet of sensors reporting to a dashboard: .Bd -literal -offset indent -prefork 4 max keepalive 300 max session expiry 86400 blob - 9a840761a13ab607a3c81b1e41d127a8e943c8968c6e451de3463bd7a1727090 blob + 3ab7ab937a64b0e804f57ed389718f7efae00478bcfb678afbd79f1af0b2f382 --- mqttd/mqttd.h +++ mqttd/mqttd.h @@ -77,8 +77,6 @@ #define MQTTD_MAXPEER 64 #define MQTTD_MAXHASH 128 #define MQTTD_MAXIFACE 16 -#define MQTTD_MAX_PREFORK 32 -#define MQTTD_NUMPROC 3 #define MQTT_PORT 1883 #define MQTTS_PORT 8883 @@ -211,7 +209,6 @@ struct imsgev { /* global broker limits, fixed size so it travels in a single imsg */ struct mqttd_global { - uint16_t prefork; uint32_t max_clients; uint32_t max_packet_size; uint16_t max_inflight; @@ -592,7 +589,6 @@ struct ctl_filter { struct ctl_parent_info { int verbose; - uint16_t prefork; uint32_t nlisteners; time_t started; }; @@ -710,7 +706,7 @@ int sockets_create_listener(struct listener *); /* broker.c */ __dead void - broker(int, int, int, int, int, int *); + broker(int, int, int, int, int, int); /* storage.c */ __dead void @@ -729,7 +725,7 @@ int jwt_sign(const struct snow_config *, char *, size /* control.c */ __dead void - control(int, int, int *); + control(int, int, int); /* config.c */ void config_init(struct mqttd *); blob - ad98b10190f877f828484e172cb50b6b271aa54be03fd2a506ec5bac2510e429 blob + 9f661dbe61297dd830d546740d9953f2ceeb132d28084dca8d2684872fd8d51a --- mqttd/parse.y +++ mqttd/parse.y @@ -204,12 +204,8 @@ yesno : YES { $$ = 1; } ; main : PREFORK NUMBER { - if ($2 <= 0 || $2 > MQTTD_MAX_PREFORK) { - yyerror("invalid number of preforked " - "sockets processes: %lld", $2); - YYERROR; - } - conf->conf.prefork = $2; + log_warnx("%s:%d: prefork is deprecated and ignored", + file->name, yylval.lineno); } | MAX CLIENTS NUMBER { if ($3 < 0 || $3 > UINT32_MAX) { @@ -1703,7 +1699,6 @@ parse_config(const char *filename, struct mqttd *xconf conf = xconf; config_init(conf); - conf->conf.prefork = MQTTD_NUMPROC; conf->conf.max_clients = 0; conf->conf.max_packet_size = MQTTD_DEFAULT_MAX_PACKET; conf->conf.max_inflight = MQTTD_DEFAULT_MAX_INFLIGHT;