From: Michael Tremer Date: Fri, 22 Jun 2012 11:08:23 +0000 (+0000) Subject: pppd: Start the daemon and wait for an established connection. X-Git-Tag: 004~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81d0c0b957ad0b53d103c1383805ff9656b0fd54;p=network.git pppd: Start the daemon and wait for an established connection. Thanks to Lennart Poettering for advice how to solve this problem. pppd now will be started by systemd and try to establish the connection. systemctl start ... will block until the connection was established (i.e. pppd forked into the background) or pppd exited. The exit code will then be retrieved by systemctl show for further processing. --- diff --git a/functions.ppp b/functions.ppp index c2eba58d..38a8d64d 100644 --- a/functions.ppp +++ b/functions.ppp @@ -25,7 +25,35 @@ function pppd_start() { local interface=${1} assert isset interface + # This will block until the connection has been established or + # pppd exited. service_start "pppd@${interface}" + + # Get the exit code of the ppp daemon and figure out + # how to handle this. + local ret=$(service_get_exitcode "pppd@${interface}") + case "${ret}" in + 0) + return ${EXIT_OK} + ;; + 1) + error "pppd crashed for an unknown reason" + ;; + 2) + error "pppd: Configuration error" + ;; + 3) + error "pppd terminated" + ;; + 19) + error "pppd: Authentication failed" + ;; + *) + error "pppd: Unhandled exit code: ${ret}" + ;; + esac + + return ${ret} } function pppd_stop() { @@ -284,7 +312,7 @@ function pppd_write_config() { print "# Disable the compression" print "noccp noaccomp nodeflate nopcomp novj novjccomp nobsdcomp nomppe" - print "noipdefault nodetach debug" + print "noipdefault updetach debug" ) >> ${file} return ${EXIT_OK} diff --git a/functions.service b/functions.service index 9d995174..895a1fff 100644 --- a/functions.service +++ b/functions.service @@ -88,3 +88,13 @@ function service_is_active() { systemctl is-active ${name}.service >/dev/null 2>&1 return $? } + +function service_get_exitcode() { + local name=${1} + assert isset name + + name="${name}.service" + + local output=$(systemctl show ${name} --property="ExecMainStatus") + cli_get_val "${output}" +}