From b509a4872188323ae2f0ee5f5bd5e580f48f3a53 Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Sun, 26 Apr 2020 10:51:21 +0300 Subject: [PATCH] net-misc/networkmanager: create /run/NetworkManager earlier 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 --- .../files/init.d.NetworkManager-r2 | 62 +++++++++++++++++++ .../networkmanager-1.18.6.ebuild | 2 +- ...uild => networkmanager-1.22.10-r11.ebuild} | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 net-misc/networkmanager/files/init.d.NetworkManager-r2 rename net-misc/networkmanager/{networkmanager-1.22.10-r10.ebuild => networkmanager-1.22.10-r11.ebuild} (99%) diff --git a/net-misc/networkmanager/files/init.d.NetworkManager-r2 b/net-misc/networkmanager/files/init.d.NetworkManager-r2 new file mode 100644 index 000000000000..f7b95c047cd9 --- /dev/null +++ b/net-misc/networkmanager/files/init.d.NetworkManager-r2 @@ -0,0 +1,62 @@ +#!/sbin/openrc-run +# Copyright (c) 2008 Saleem Abdulrasool +# 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 : diff --git a/net-misc/networkmanager/networkmanager-1.18.6.ebuild b/net-misc/networkmanager/networkmanager-1.18.6.ebuild index 9280f0f85f6a..b410b2553ee6 100644 --- a/net-misc/networkmanager/networkmanager-1.18.6.ebuild +++ b/net-misc/networkmanager/networkmanager-1.18.6.ebuild @@ -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 diff --git a/net-misc/networkmanager/networkmanager-1.22.10-r10.ebuild b/net-misc/networkmanager/networkmanager-1.22.10-r11.ebuild 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 a6ae13c86a5d..b2cd3babde33 100644 --- a/net-misc/networkmanager/networkmanager-1.22.10-r10.ebuild +++ b/net-misc/networkmanager/networkmanager-1.22.10-r11.ebuild @@ -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 -- 2.26.2