ncopa / pingu

Policy routing daemon with failover and load-balancing for multi ISP setups
48 stars 6 forks source link

pinguctl not working when path to admin socket is explicitly set #5

Closed fiisch closed 2 months ago

fiisch commented 5 years ago

Hi, I am using pingu with non-default paths, set -a for the admin socket and pointed it to /var/run/pingu/pingu-2.ctl . Pingu daemon runs fine but I am not able to query status info with pinguctl. When running pinguctl -a /var/run/pingu/pingu-2.ctl gateway-status the return code is 0 but no info is printed. Pinguctl successfuly opens the socket and then closes it right away. When I have socket in the default location, pinguctl gateway-status works fine but pinguctl -a path_to_default_socket_location gateway-status fails. Command specificaton (host-status, gateway-status does not matter).

Using git.8c9b53c built on CentOS7.

systemd unit:

[Unit]
Description=PINGU 2
After=syslog.target network-online.target

[Service]
Type=simple
PIDFile=/var/run/pingu-2.pid
KillMode=process
ExecStartPre=/usr/bin/mkdir -p /run/pingu
ExecStart=/usr/local/sbin/pingu -c /etc/pingu/pingu-2.conf -p /var/run/pingu/pingu-2.pid -a /var/run/pingu/pingu-2.ctl
ExecStop=/bin/kill -INT $MAINPID
TimeoutSec=15s

[Install]
WantedBy=multi-user.target

strace of failing pinguctl (notice missing commnication with socket):

[root@multi-isp-test pingu]# strace -ff pinguctl -a /var/run/pingu/pingu-2.ctl host-status
execve("/usr/local/sbin/pinguctl", ["pinguctl", "-a", "/var/run/pingu/pingu-2.ctl", "host-status"], [/* 25 vars */]) = 0
brk(NULL)                               = 0x108f000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0ad99f3000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=33236, ...}) = 0
mmap(NULL, 33236, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f0ad99ea000
close(3)                                = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P%\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2173512, ...}) = 0
mmap(NULL, 3981792, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f0ad9406000
mprotect(0x7f0ad95c9000, 2093056, PROT_NONE) = 0
mmap(0x7f0ad97c8000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c2000) = 0x7f0ad97c8000
mmap(0x7f0ad97ce000, 16864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f0ad97ce000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0ad99e9000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0ad99e7000
arch_prctl(ARCH_SET_FS, 0x7f0ad99e7740) = 0
mprotect(0x7f0ad97c8000, 16384, PROT_READ) = 0
mprotect(0x601000, 4096, PROT_READ)     = 0
mprotect(0x7f0ad99f4000, 4096, PROT_READ) = 0
munmap(0x7f0ad99ea000, 33236)           = 0
socket(AF_LOCAL, SOCK_STREAM, 0)        = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/pingu/pingu-2.ctl"}, 110) = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++
fiisch commented 5 years ago

I managed to isolate and correct the problem - argument parsing in the pinguctl.c source. Patch attached. Please check it to make sure I didn't commit some C heresy. ;)

If you rather have me submit a pull request, just let me know.

diff --git a/src/pinguctl.c b/src/pinguctl.c
index ea59f8a..5f79a38 100644
--- a/src/pinguctl.c
+++ b/src/pinguctl.c
@@ -71,15 +71,17 @@ int main(int argc, char *argv[])
            socket_path = optarg;
            break;
        }
-       argc -= optind;
-       argv += optind;
    }
+
+   argc -= optind;
+   argv += optind;
+
    log_init("pinguctl", 0);
    fd = adm_init(socket_path);
    if (fd < 0)
        return 1;

-   for (i = 1; i < argc; i++) {
+   for (i = 0; i < argc; i++) {
        if (adm_send_cmd(fd, argv[i]) < 0 || adm_recv(fd) < 0)
            return 1;
    }