#!/bin/sh
# apply sysctl.d the conventional way: all candidates sorted by basename
# across every directory, and for a given basename the first directory in the
# search path wins
. /usr/lib/nitro/rc.lib
case $1 in
up)
    log "loading sysctl settings..."
    for conf in $(
        for d in /run/sysctl.d /etc/sysctl.d /usr/lib/sysctl.d; do
            for f in "$d"/*.conf; do
                [ -f "$f" ] && printf '%s %s\n' "${f##*/}" "$f"
            done
        done | sort -s -u -k1,1 | cut -d' ' -f2
    ); do
        sysctl -p "$conf" >/dev/null || :
    done

    [ -f /etc/sysctl.conf ] && sysctl -p /etc/sysctl.conf >/dev/null
    ;;
esac
exit 0
