]> git.ipfire.org Git - people/ms/network.git/commitdiff
pppd: Start the daemon and wait for an established connection.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Jun 2012 11:08:23 +0000 (11:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Jun 2012 11:08:23 +0000 (11:08 +0000)
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.

functions.ppp
functions.service

index c2eba58dc9c46a87498f18ad7d62b4cd4b65bf6c..38a8d64dfe6b7e8ce46c465436c7c6134483317d 100644 (file)
@@ -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}
index 9d9951748f48f609837358243884e236001d3c7d..895a1fffd8b1efa6a6bccaa56a8368f9f63218d8 100644 (file)
@@ -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}"
+}