net-misc/networkmanager: create /run/NetworkManager earlier
authorMart Raudsepp <leio@gentoo.org>
Sun, 26 Apr 2020 07:51:21 +0000 (10:51 +0300)
committerMart Raudsepp <leio@gentoo.org>
Sun, 26 Apr 2020 08:09:05 +0000 (11:09 +0300)
NetworkManager itself creates /run/NetworkManager very early on in
its main(), but the OpenRC init file also wants to put the
start-stop-daemon pidfile in it.
It seems to have been working well enough for most people
regardless, but there is still a very real race condition and
bug here, which appears to get triggered for more users with
the p.masked networkmanager versions as well.
Hopefully fix it by creating the directory in start_pre() like other
packages making use of a subdirectory pidfile do, with the same
permissions as NetworkManager itself will/would create it.

Package-Manager: Portage-2.3.84, Repoman-2.3.20
Signed-off-by: Mart Raudsepp <leio@gentoo.org>
net-misc/networkmanager/files/init.d.NetworkManager-r2 [new file with mode: 0644]
net-misc/networkmanager/networkmanager-1.18.6.ebuild
net-misc/networkmanager/networkmanager-1.22.10-r11.ebuild [moved from net-misc/networkmanager/networkmanager-1.22.10-r10.ebuild with 99% similarity]

diff --git a/net-misc/networkmanager/files/init.d.NetworkManager-r2 b/net-misc/networkmanager/files/init.d.NetworkManager-r2
new file mode 100644 (file)
index 0000000..f7b95c0
--- /dev/null
@@ -0,0 +1,62 @@
+#!/sbin/openrc-run
+# Copyright (c) 2008 Saleem Abdulrasool <compnerd@compnerd.org>
+# Copyright 2013-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+description="NetworkManager daemon. The service is marked as started only \
+when a network connection is established."
+
+depend() {
+       need dbus
+       use consolekit
+       provide net
+}
+
+start_pre() {
+       checkpath -q -d -m 0755 /run/NetworkManager
+}
+
+start() {
+       # If we are re-called by a dispatcher event, we want to mark the service
+       # as started without starting the daemon again
+       yesno "${IN_BACKGROUND}" && return 0
+
+       [ -z "${INACTIVE_TIMEOUT}" ] && INACTIVE_TIMEOUT="1"
+
+       ebegin "Starting NetworkManager"
+       start-stop-daemon --start --quiet --pidfile /run/NetworkManager/NetworkManager.pid \
+               --exec /usr/sbin/NetworkManager -- --pid-file /run/NetworkManager/NetworkManager.pid
+       local _retval=$?
+       eend "${_retval}"
+       if [ "x${_retval}" = 'x0' ] && ! nm-online -t "${INACTIVE_TIMEOUT}"; then
+               einfo "Marking NetworkManager as inactive. It will automatically be marked"
+               einfo "as started after a network connection has been established."
+               mark_service_inactive
+       fi
+       return "${_retval}"
+}
+
+stop() {
+       # If we are re-called by a dispatcher event, we want to mark the service
+       # as inactive without stopping the daemon
+       if yesno "${IN_BACKGROUND}"; then
+               mark_service_inactive "${SVCNAME}"
+               return 0
+       fi
+
+       ebegin "Stopping NetworkManager"
+       local pidfile=/run/NetworkManager/NetworkManager.pid
+       if [ ! -e "${pidfile}" ] && [ -e /var/run/NetworkManager.pid ]; then
+               # Try stopping the pid file used by <0.9.7
+               pidfile=/var/run/NetworkManager.pid
+               start-stop-daemon --stop --quiet --pidfile "${pidfile}"
+               ret=$?
+               [ ${ret} = 0 ] && [ -e "${pidfile}" ] && rm "${pidfile}"
+               eend ${ret}
+       else
+               start-stop-daemon --stop --quiet --pidfile "${pidfile}"
+               eend $?
+       fi
+}
+
+# vim: set ft=gentoo-init-d ts=4 :
index 9280f0f85f6a1fe5f284ad93a9e109ecc39a47e2..b410b2553ee691e7de2336aca237abb509d810e3 100644 (file)
@@ -285,7 +285,7 @@ multilib_src_install_all() {
        einstalldocs
        ! use systemd && readme.gentoo_create_doc
 
-       newinitd "${FILESDIR}/init.d.NetworkManager-r1" NetworkManager
+       newinitd "${FILESDIR}/init.d.NetworkManager-r2" NetworkManager
        newconfd "${FILESDIR}/conf.d.NetworkManager" NetworkManager
 
        # Need to keep the /etc/NetworkManager/dispatched.d for dispatcher scripts
similarity index 99%
rename from net-misc/networkmanager/networkmanager-1.22.10-r10.ebuild
rename to net-misc/networkmanager/networkmanager-1.22.10-r11.ebuild
index a6ae13c86a5dbb2acb8ef9eba5d08fa28772fbc9..b2cd3babde33bec90640b314d1a90f8cbb9fdf13 100644 (file)
@@ -281,7 +281,7 @@ src_configure() {
 src_install() {
        meson_src_install
 
-       newinitd "${FILESDIR}/init.d.NetworkManager-r1" NetworkManager
+       newinitd "${FILESDIR}/init.d.NetworkManager-r2" NetworkManager
        newconfd "${FILESDIR}/conf.d.NetworkManager" NetworkManager
 
        # Need to keep the /etc/NetworkManager/dispatched.d for dispatcher scripts