Skip to main content

源码阅读[systemd/udev]: 错过了一次往systemd 提交代码的机会

在读 systemd 代码的时候, 发现如下代码片段:

struct udev_ctrl *udev_ctrl_new_from_fd(int fd) {
        struct udev_ctrl *uctrl;
        int r;

        uctrl = new0(struct udev_ctrl, 1);
        if (!uctrl)
                return NULL;
        uctrl->n_ref = 1;

        if (fd < 0) {
                uctrl->sock = socket(AF_LOCAL, SOCK_SEQPACKET|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
                if (uctrl->sock < 0) {
                        log_error_errno(errno, "Failed to create socket: %m");
                        udev_ctrl_unref(uctrl);
                        return NULL;
                }
        } else {
                uctrl->bound = true;
                uctrl->sock = fd;
        }

        /*
         * FIXME: remove it as soon as we can depend on this:
         *   http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=90c6bd34f884cd9cee21f1d152baf6c18bcac949
         */
        r = setsockopt_int(uctrl->sock, SOL_SOCKET, SO_PASSCRED, true);
        if (r < 0)
                log_warning_errno(r, "Failed to set SO_PASSCRED: %m");

        uctrl->saddr.un = (struct sockaddr_un) {
                .sun_family = AF_UNIX,
                .sun_path = "/run/udev/control",
        };

        uctrl->addrlen = SOCKADDR_UN_LEN(uctrl->saddr.un);
        return uctrl;
}

FIXME 吸引了我的注意,我猜测这段存在的原因是当时这个13 年kernel 的 commit 还没有进入大部分发行版的stable kernel, 所以采用的临时方案,现在当然可以删掉。所以我异常兴奋,可以给systemd 提交代码了。

但是在上游最新的代码里搜索了一番,失望,这个代码回退20年已经有人做了,晚了一步。

哎,可惜

(赶紧全局搜索一下FIXME)

git log -S "FIXME: remove it as so" src/udev/udev-ctrl.c
commit 3b57baff7ec25e21e50311a4098d0b97f583408a
Author: David Tardon <dtardon@redhat.com>
Date:   Thu Sep 10 15:50:15 2020 +0200

    udev-ctrl: drop workaround for old kernel bug
    
    It's been 7 years. That should be long enough :-)
    
    This reverts commit b97caef538ae37bd2dc04fc15b448c12a2c9422b.

commit 25568304d2cbe95720a336acfee2c7bc0e945a35
Author: Kay Sievers <kay@vrfy.org>
Date:   Thu Aug 27 12:57:17 2015 +0200

    udev: control - add FIXME comment to remove work-around
From 3b57baff7ec25e21e50311a4098d0b97f583408a Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Thu, 10 Sep 2020 15:50:15 +0200
Subject: [PATCH] udev-ctrl: drop workaround for old kernel bug

It's been 7 years. That should be long enough :-)

This reverts commit b97caef538ae37bd2dc04fc15b448c12a2c9422b.
---
 src/udev/udev-ctrl.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index 9deb3864b5a..84016916595 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -58,7 +58,6 @@ struct udev_ctrl {
 int udev_ctrl_new_from_fd(struct udev_ctrl **ret, int fd) {
         _cleanup_close_ int sock = -1;
         struct udev_ctrl *uctrl;
-        int r;
 
         assert(ret);
 
@@ -79,14 +78,6 @@ int udev_ctrl_new_from_fd(struct udev_ctrl **ret, int fd) {
                 .bound = fd >= 0,
         };
 
-        /*
-         * FIXME: remove it as soon as we can depend on this:
-         *   http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=90c6bd34f884cd9cee21f1d152baf6c18bcac949
-         */
-        r = setsockopt_int(uctrl->sock, SOL_SOCKET, SO_PASSCRED, true);
-        if (r < 0)
-                log_warning_errno(r, "Failed to set SO_PASSCRED: %m");
-
         uctrl->saddr.un = (struct sockaddr_un) {
                 .sun_family = AF_UNIX,
                 .sun_path = "/run/udev/control",