Convert to use imsg_get_fd() since proc_forward_imsg() never forwards a
authorclaudio <claudio@openbsd.org>
Wed, 17 Jan 2024 08:22:40 +0000 (08:22 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 17 Jan 2024 08:22:40 +0000 (08:22 +0000)
file descriptor just use -1 there.
OK tb@

usr.sbin/httpd/config.c
usr.sbin/httpd/logger.c
usr.sbin/httpd/proc.c

index e8c5cd5..b4a8e73 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: config.c,v 1.64 2024/01/17 08:20:58 claudio Exp $     */
+/*     $OpenBSD: config.c,v 1.65 2024/01/17 08:22:40 claudio Exp $     */
 
 /*
  * Copyright (c) 2011 - 2015 Reyk Floeter <reyk@openbsd.org>
@@ -626,6 +626,7 @@ config_getserver(struct httpd *env, struct imsg *imsg)
        struct server_config     srv_conf;
        uint8_t                 *p = imsg->data;
        size_t                   s;
+       int                      fd;
 
        IMSG_SIZE_CHECK(imsg, &srv_conf);
        memcpy(&srv_conf, p, sizeof(srv_conf));
@@ -634,6 +635,8 @@ config_getserver(struct httpd *env, struct imsg *imsg)
        /* Reset these variables to avoid free'ing invalid pointers */
        serverconfig_reset(&srv_conf);
 
+       fd = imsg_get_fd(imsg);
+
        if ((IMSG_DATA_SIZE(imsg) - s) < (size_t)srv_conf.return_uri_len) {
                log_debug("%s: invalid message length", __func__);
                goto fail;
@@ -643,11 +646,11 @@ config_getserver(struct httpd *env, struct imsg *imsg)
        if ((srv = server_byaddr((struct sockaddr *)
            &srv_conf.ss, srv_conf.port)) != NULL) {
                /* Add "host" to existing listening server */
-               if (imsg->fd != -1) {
+               if (fd != -1) {
                        if (srv->srv_s == -1)
-                               srv->srv_s = imsg->fd;
+                               srv->srv_s = fd;
                        else
-                               close(imsg->fd);
+                               close(fd);
                }
                return (config_getserver_config(env, srv, imsg));
        }
@@ -660,7 +663,7 @@ config_getserver(struct httpd *env, struct imsg *imsg)
                goto fail;
 
        memcpy(&srv->srv_conf, &srv_conf, sizeof(srv->srv_conf));
-       srv->srv_s = imsg->fd;
+       srv->srv_s = fd;
 
        if (config_getserver_auth(env, &srv->srv_conf) != 0)
                goto fail;
@@ -688,8 +691,8 @@ config_getserver(struct httpd *env, struct imsg *imsg)
        return (0);
 
  fail:
-       if (imsg->fd != -1)
-               close(imsg->fd);
+       if (fd != -1)
+               close(fd);
        if (srv != NULL)
                serverconfig_free(&srv->srv_conf);
        free(srv);
index 9c62485..31f4410 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: logger.c,v 1.24 2021/01/27 07:21:53 deraadt Exp $     */
+/*     $OpenBSD: logger.c,v 1.25 2024/01/17 08:22:40 claudio Exp $     */
 
 /*
  * Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
@@ -144,9 +144,9 @@ logger_open_fd(struct imsg *imsg)
 
        TAILQ_FOREACH(log, &log_files, log_entry) {
                if (log->log_id == id) {
+                       log->log_fd = imsg_get_fd(imsg);
                        DPRINTF("%s: received log fd %d, file %s",
-                           __func__, imsg->fd, log->log_name);
-                       log->log_fd = imsg->fd;
+                           __func__, log->log_fd, log->log_name);
                        return (0);
                }
        }
index 71bb3c2..e8b08dd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: proc.c,v 1.42 2023/02/15 20:44:01 tobhe Exp $ */
+/*     $OpenBSD: proc.c,v 1.43 2024/01/17 08:22:40 claudio Exp $       */
 
 /*
  * Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -668,7 +668,7 @@ proc_dispatch(int fd, short event, void *arg)
                case IMSG_CTL_PROCFD:
                        IMSG_SIZE_CHECK(&imsg, &pf);
                        memcpy(&pf, imsg.data, sizeof(pf));
-                       proc_accept(ps, imsg.fd, pf.pf_procid,
+                       proc_accept(ps, imsg_get_fd(&imsg), pf.pf_procid,
                            pf.pf_instance);
                        break;
                default:
@@ -799,7 +799,7 @@ proc_forward_imsg(struct privsep *ps, struct imsg *imsg,
     enum privsep_procid id, int n)
 {
        return (proc_compose_imsg(ps, id, n, imsg->hdr.type,
-           imsg->hdr.peerid, imsg->fd, imsg->data, IMSG_DATA_SIZE(imsg)));
+           imsg->hdr.peerid, -1, imsg->data, IMSG_DATA_SIZE(imsg)));
 }
 
 struct imsgbuf *