dhcpcd-discuss

Re: Evolution request for managing namespaces

Roy Marples

Wed Apr 08 15:48:03 2020

On 08/04/2020 09:03, Stéphane Veyret wrote:
Hi Roy,

Le mar. 7 avr. 2020 à 16:57, Roy Marples <roy@xxxxxxxxxxxx> a écrit :
Do you think a “--nomaster” option (which would simply ignore the
socket) would be complicated to implement?

Actually yes it is complicated :)
What if you run --nomaster and there are two interfaces?

I'd say that you should do what is the simplest: either exit with
error, or start provided interfaces independently.

You can achieve this on linux as it stands with a simple shell script, pasted below.

Let me know how it works for you!

Yes, it works with this script, thanks a lot. But it will require me
to modify my OpenRC script (I am using Gentoo) which could be
overridden at next update.
If I look at the copyright of the OpenRC script, it seems that it is
provided by you, but I couldn't find it in the dhcpcd git tree.
If you don't want to add the “--nomaster” option, would that be
possible to at least modify the script so that it can be provided
options? I was thinking of something like that:

init.d scripts in Gentoo are updated via etc-update which allows you to decide if you want to update it or not, but whatever.

You know I wrote OpenRC? I don't use or maintain it anymore, but you could adjust /etc/conf.d/dhcpcd like so:

# Totally untested, I don't have an OpenRC system handy right now

list_interfaces()
{
        for iface in /sys/class/net/*; do
                [ -h $iface/device ] && echo ${iface##*/}
        done
}

set_interface()
{
	set -- $(list_interfaces)
	if [ -n "$2" ]; then
        	eerror "More than one physical interface found:"
        	eerror $*
		return 1
	fi
	if [ -z "$1" ]; then
        	eerror "No physical interface found"
	        return 1
	fi

	iface=$1
	command_args="$command_args $iface"
	pidfile=$(dhcpcd -P $command_args)
	return 0
}

start_pre()
{
	set_interface || return $?
}

stop_pre()
{
	set_interface || return $?
}

status_pre()
{
	set_interface || return $?
}

I can provide a PR or a git diff if you prefer.

That's something for Gentoo, not me.
The dhcpcd init script is part of the dhcpcd Gentoo ebuild as found here:
https://gitweb.gentoo.org/repo/gentoo.git/tree/net-misc/dhcpcd/files/dhcpcd.initd

Roy

Follow-Ups:
Re: Evolution request for managing namespacesRoy Marples
References:
Evolution request for managing namespacesStéphane Veyret
Re: Evolution request for managing namespacesRoy Marples
Re: Evolution request for managing namespacesStéphane Veyret
Re: Evolution request for managing namespacesRoy Marples
Re: Evolution request for managing namespacesStéphane Veyret
Archive administrator: postmaster@marples.name