script "</dev/tcp/127.0.0.1/80" relies on /bin/sh being bash

Bug #1934300 reported by Paride Legovini
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
keepalived
Fix Released
Unknown
keepalived (Ubuntu)
Fix Released
Low
Unassigned

Bug Description

The /usr/share/doc/keepalived/samples/keepalived.conf.vrrp.localcheck sample configuration file shows how to check if a TCP port is open using a `script`, e.g.:

vrrp_script chk_http_port {
       script "</dev/tcp/127.0.0.1/80" # connects and exits
       interval 1 # check every second
       weight -2 # default prio: -2 if connect fails
}

however this works only on systems where `/bin/sh` is Bash, and therefore doesn't work on Ubuntu. This happens because `script` basically passes the script name to stdlib's system(), which in turn does (see system(3)):

    execl("/bin/sh", "sh", "-c", command, (char *) NULL);

When `/bin/sh` is Bash then `script "</dev/tcp/127.0.0.1/80"` works because `/dev/tcp/host/port` is a special syntax telling Bash to tcp-connect to `host:port`, however other shells will just try to open `/dev/tcp/127.0.0.1/80` as a file and fail.

As the sample file comes from upstream I filed an upstream issue [1].

Possible workarounds are (warning: untested!):

    script "bash -c '</dev/tcp/127.0.0.1/80'"
    script "nc -z 127.0.0.1 80"

[1] https://github.com/acassen/keepalived/issues/1926

Paride Legovini (paride)
Changed in keepalived (Ubuntu):
status: New → Triaged
importance: Undecided → Low
Revision history for this message
Paride Legovini (paride) wrote :

Note for context: this is a spin-off from LP: #1795420.

Changed in keepalived:
status: Unknown → New
Changed in keepalived:
status: New → Fix Released
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

https://github.com/acassen/keepalived/commit/8f658000ff9fa8b67a81d29b4a73c6a3c1fc2c2b
was accepted upstream and is in
 keepalived | 1:2.2.4-0.2 | jammy | source, amd64, arm64, armhf, ppc64el, riscv64, s390x

I do not think this needs backports, setting fix released.

Changed in keepalived (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.