From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Gundersen Date: Thu, 11 Apr 2013 15:48:31 +0000 Subject: [PATCH] [RFC] udevd: let tmpfiles create all static nodes Message-Id: <1365695311-30930-1-git-send-email-teg@jklm.no> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org systemd-tmpfiles has had support for creation of static nodes for some time= (to replace copying nodes from /lib/udev/). Make sure these nodes are created b= efore udev is started. Also, drop support for creating static nodes based on modules.devname from systemd-udevd. This allows it to run witohut CAP_MKNOD, moreover we no long= er need to parse /usr/lib/modules/*/modules.devname. As a replacement for udevd's functionality, we let kmod generate a tmpfiles= .d fragment based on the correct modules.devname file (see separate patch). We might want to split the kmod call out into its own unit file and ship that = with kmod instead. Note: one functional change is that we no longer update the creation time on already existing device nodes. Is this important? If so, should tmpfiles le= arn to do that? Cc: Cc: --- Makefile.am | 5 +++ TODO | 4 -- src/udev/udevd.c | 72 -------------------------------= ---- units/systemd-static-nodes.service.in | 17 +++++++++ units/systemd-udevd.service.in | 5 +-- 5 files changed, 24 insertions(+), 79 deletions(-) create mode 100644 units/systemd-static-nodes.service.in diff --git a/Makefile.am b/Makefile.am index ec81f53..3c6adcb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -427,6 +427,7 @@ nodist_systemunit_DATA =3D \ units/systemd-kexec.service \ units/systemd-fsck@.service \ units/systemd-fsck-root.service \ + units/systemd-static-nodes.service \ units/systemd-udevd.service \ units/systemd-udev-trigger.service \ units/systemd-udev-settle.service \ @@ -468,6 +469,7 @@ EXTRA_DIST +=3D \ units/systemd-fsck@.service.in \ units/systemd-fsck-root.service.in \ units/user@.service.in \ + units/systemd-static-nodes.service \ units/systemd-udevd.service \ units/systemd-udev-trigger.service \ units/systemd-udev-settle.service \ @@ -1925,11 +1927,13 @@ CLEANFILES +=3D \ src/udev/udev.pc =20 EXTRA_DIST +=3D \ + units/systemd-static-nodes.service.in \ units/systemd-udevd.service.in \ units/systemd-udev-trigger.service.in \ units/systemd-udev-settle.service.in =20 CLEANFILES +=3D \ + units/systemd-static-nodes.service \ units/systemd-udevd.service \ units/systemd-udev-trigger.service \ units/systemd-udev-settle.service @@ -1938,6 +1942,7 @@ SOCKETS_TARGET_WANTS +=3D \ systemd-udevd-control.socket \ systemd-udevd-kernel.socket SYSINIT_TARGET_WANTS +=3D \ + systemd-static-nodes.service \ systemd-udevd.service \ systemd-udev-trigger.service =20 diff --git a/TODO b/TODO index 369fb78..d70732d 100644 --- a/TODO +++ b/TODO @@ -51,10 +51,6 @@ Features: so that the coredump is properly written to the user's own journal file. =20 -* move /usr/lib/modules/$(uname -r)/modules.devname parsing from udevd to - kmod static-nodes - call kmod as an early service, and drop CAP_MKNOD from udevd.service - * systemd-delta needs to be made aware of *.d/*.conf drop-in files for units. =20 diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 2d9093d..642ca43 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -812,77 +812,6 @@ static void handle_signal(struct udev *udev, int signo) } } =20 -static void static_dev_create_from_modules(struct udev *udev) -{ - struct utsname kernel; - char modules[UTIL_PATH_SIZE]; - char buf[4096]; - FILE *f; - - if (uname(&kernel) < 0) { - log_error("uname failed: %m"); - return; - } - - strscpyl(modules, sizeof(modules), ROOTPREFIX "/lib/modules/", ker= nel.release, "/modules.devname", NULL); - f =3D fopen(modules, "re"); - if (f =3D NULL) - return; - - while (fgets(buf, sizeof(buf), f) !=3D NULL) { - char *s; - const char *modname; - const char *devname; - const char *devno; - int maj, min; - char type; - mode_t mode; - char filename[UTIL_PATH_SIZE]; - - if (buf[0] =3D '#') - continue; - - modname =3D buf; - s =3D strchr(modname, ' '); - if (s =3D NULL) - continue; - s[0] =3D '\0'; - - devname =3D &s[1]; - s =3D strchr(devname, ' '); - if (s =3D NULL) - continue; - s[0] =3D '\0'; - - devno =3D &s[1]; - s =3D strchr(devno, ' '); - if (s =3D NULL) - s =3D strchr(devno, '\n'); - if (s !=3D NULL) - s[0] =3D '\0'; - if (sscanf(devno, "%c%u:%u", &type, &maj, &min) !=3D 3) - continue; - - mode =3D 0600; - if (type =3D 'c') - mode |=3D S_IFCHR; - else if (type =3D 'b') - mode |=3D S_IFBLK; - else - continue; - - strscpyl(filename, sizeof(filename), "/dev/", devname, NUL= L); - mkdir_parents_label(filename, 0755); - label_context_set(filename, mode); - log_debug("mknod '%s' %c%u:%u\n", filename, type, maj, min= ); - if (mknod(filename, mode, makedev(maj, min)) < 0 && errno = =3D EEXIST) - utimensat(AT_FDCWD, filename, NULL, 0); - label_context_clear(); - } - - fclose(f); -} - static int systemd_fds(struct udev *udev, int *rctrl, int *rnetlink) { int ctrl =3D -1, netlink =3D -1; @@ -1067,7 +996,6 @@ int main(int argc, char *argv[]) mkdir("/run/udev", 0755); =20 dev_setup(NULL); - static_dev_create_from_modules(udev); =20 /* before opening new files, make sure std{in,out,err} fds are in = a sane state */ if (daemonize) { diff --git a/units/systemd-static-nodes.service.in b/units/systemd-static-n= odes.service.in new file mode 100644 index 0000000..8178c43 --- /dev/null +++ b/units/systemd-static-nodes.service.in @@ -0,0 +1,17 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=3DCreate static device nodes in /dev +DefaultDependencies=3Dno +Before=3Dsysinit.target local-fs-pre.target +ConditionCapability=CAP_MKNOD + +[Service] +Type=3Doneshot +ExecStart=3D@rootbindir@/kmod devname2tmpfile +ExecStart=3D@rootbindir@/systemd-tmpfiles --prefix=3D/dev --create diff --git a/units/systemd-udevd.service.in b/units/systemd-udevd.service.in index ddef423..c0dc4f2 100644 --- a/units/systemd-udevd.service.in +++ b/units/systemd-udevd.service.in @@ -9,10 +9,9 @@ Description=3Dudev Kernel Device Manager Documentation=3Dman:systemd-udevd.service(8) man:udev(7) DefaultDependencies=3Dno -Wants=3Dsystemd-udevd-control.socket systemd-udevd-kernel.socket -After=3Dsystemd-udevd-control.socket systemd-udevd-kernel.socket +Wants=3Dsystemd-static-nodes.service systemd-udevd-control.socket systemd-= udevd-kernel.socket +After=3Dsystemd-static-nodes.service systemd-udevd-control.socket systemd-= udevd-kernel.socket Before=3Dsysinit.target local-fs-pre.target -ConditionCapability=CAP_MKNOD =20 [Service] Type=3Dnotify --=20 1.8.2.1