From: Michael Tremer Date: Fri, 21 Sep 2018 15:00:24 +0000 (+0200) Subject: port: ethernet: Correctly create new configurations X-Git-Tag: 010~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39aae67414deb3edb8d2fbf909ef472ad04c9b6e;p=network.git port: ethernet: Correctly create new configurations Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.settings b/src/functions/functions.settings index becf3f0f..69f4c238 100644 --- a/src/functions/functions.settings +++ b/src/functions/functions.settings @@ -153,15 +153,16 @@ settings_write() { return ${EXIT_ERROR} fi - log DEBUG "Writing settings file '${settings_file}'" + if ! make_parent_directory "${settings_file}"; then + return ${EXIT_ERROR} + fi - mkdir -p $(dirname ${settings_file}) 2>/dev/null - > ${settings_file} + log DEBUG "Writing settings file '${settings_file}'" local param for param in $(list_sort "$@"); do - echo "${param}=\"${!param}\"" >> ${settings_file} - done + echo "${param}=\"${!param}\"" + done > ${settings_file} } settings_remove() { diff --git a/src/functions/functions.util b/src/functions/functions.util index 8831d84b..1be6dc14 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -251,7 +251,13 @@ file_get_age() { make_directory() { local path="${1}" - mkdir -p "${path}" + if ! mkdir -p "${path}"; then + log ERROR "Could not create directory ${path}" + return ${EXIT_ERROR} + fi + + log DEBUG "Created directory ${path}" + return ${EXIT_OK} } make_parent_directory() { diff --git a/src/hooks/ports/ethernet b/src/hooks/ports/ethernet index 9222bce6..18e9d57c 100644 --- a/src/hooks/ports/ethernet +++ b/src/hooks/ports/ethernet @@ -100,6 +100,22 @@ hook_parse_cmdline() { done } +# This function is only called automatically by hotplug to create +# a new ethernet port. +hook_new() { + local port="${1}" + assert isset port + + local DEVICE="$(device_get_address "${port}")" + + if ! port_settings_write "${port}" ${HOOK_SETTINGS}; then + log ERROR "Could not write settings for port ${port}" + return ${EXIT_ERROR} + fi + + return ${EXIT_OK} +} + hook_create() { return ${EXIT_OK} }