Package: ppp
Version: 2.4.8-1+2
File: /etc/ppp/ip-up.d/0000usepeerdns

In /etc/ppp/ip-up.d/0000usepeerdns we see:

# exit if systemd-resolved is running
[ -x /usr/bin/systemd-resolve ] && \
  /usr/bin/systemd-resolve --status >/dev/null &&
  exit 0

However this is the wrong test to see "if systemd-resolved is running".

Proof:

# systemctl start systemd-resolved
# systemctl status systemd-resolved|grep running
     Active: active (running) since Wed 2021-01-06 19:05:09 CST; 12s ago
# systemctl stop systemd-resolved
# systemctl status systemd-resolved|grep running
# systemctl status systemd-resolved|grep Active
     Active: inactive (dead) since Wed 2021-01-06 19:05:35 CST; 20s ago

The current test in /etc/ppp/ip-up.d/0000usepeerdns will give TRUE even
"if systemd-resolved is NOT running":

# systemctl start systemd-resolved
# /usr/bin/systemd-resolve --status >/dev/null && echo TRUE
TRUE
# systemctl stop systemd-resolved
# /usr/bin/systemd-resolve --status >/dev/null && echo TRUE
TRUE

Probing further,

# systemctl disable systemd-resolved
Removed /etc/systemd/system/multi-user.target.wants/systemd-resolved.service.
Removed /etc/systemd/system/dbus-org.freedesktop.resolve1.service.
# /usr/bin/systemd-resolve --status >/dev/null && echo TRUE
TRUE
# systemctl --now disable systemd-resolved
# /usr/bin/systemd-resolve --status >/dev/null && echo TRUE
Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found.

OK, we finally got it to not return TRUE, in fact due to a bug (it can't
find a file, so bombs early,) which I will report to them...

OK, now let us research what the documented exit value of
/usr/bin/systemd-resolve is.

# man systemd-resolve
No manual entry for systemd-resolve
# systemd-resolve --help | grep man
See the resolvectl(1) man page for details.

Ah, it turns out /usr/bin/systemd-resolve
  lrwxrwxrwx  1 root         10 01-03 00:06 systemd-resolve -> resolvectl
is a symlink all along.

Anyway the resolvectl man page doesn't mention anything about exit
statuses.

So maybe one needs a junky line like:
# systemctl status systemd-resolved|grep Active|grep -q running && echo TRUE
to test if something is running. I didn't explore further. All I know is
the current test used in 0000usepeerdns is wrong.

(I did look in /run and did find some stuff, but it doesn't seem affected
by my tests....)

Wait! I found the correct test for you:

$ man systemctl

       is-active PATTERN...

           Check whether any of the specified units are active (i.e. running).
           Returns an exit code 0 if at least one is active, or non-zero
           otherwise. Unless --quiet is specified, this will also print the
           current unit state to standard output.

# systemctl stop systemd-resolved
# systemctl --quiet is-active systemd-resolved && echo TRUE
# systemctl start systemd-resolved
# systemctl --quiet is-active systemd-resolved && echo TRUE
TRUE

Reply via email to