Waybar icon indicating copy to clipboard operation
Waybar copied to clipboard

Waybar crash (SIGABRT) when trying to use signal (RTMN+x)

Open simonm opened this issue 1 year ago • 1 comments

Hi All

I'm seeing unexpected behavior using signals in waybar. I get the following when sending signals to the waybar process:

**[2024-08-08 17:33:53.705] [error] Value is not convertible to Int.
terminate called after throwing an instance of 'Json::LogicError'
  what():  Value is not convertible to Int.
fish: Job 1, '/usr/bin/waybar -c /home/…' terminated by signal SIGABRT (Abort)

I have some systemd user units to stop and start certain services, and I only want waybar to be updated when those services are running.

For example:

systemd unit file

    [Unit]
    Description=Waynergy
    PartOf=graphical-session.target

    [Service]
    Type=simple
    ExecStart=/usr/bin/waynergy
    ExecReload=/bin/kill -SIGUSR2 $MAINPID
    ExecStop=/bin/kill -2 $MAINPID
    ExecCondition=/usr/bin/nc -w 3 -z <my-laptop-hostname> 22
    ExecStartPost=/usr/bin/pkill -RTMIN+12 waybar
    ExecStopPost=/usr/bin/pkill -RTMIN+12 waybar
    Restart=always
    RestartSec=10
    TimeoutStopSec=5

    [Install]
    WantedBy=graphical-session.target

relevant bit from waybar config:

    "custom/waynergy_test": {
        "exec": "~/bin/bar/waybar-waynergy.sh",
        "format": "{}",
        "interval": 600,
        "signal": 12,
        "return-type": "json",
        "on-click": "systemctl --user restart waynergy.service"
    },

the script

This simply checks if waynergy is running, or connected etc. It's not really relevant to the specific issue, but I'm in a copying-n-pasting mood.

    #!/usr/bin/env bash

    # Three states:
    # not_running
    # running
    # running_con
    # colours managed by style.css

    glyph="\uf192" 

    is_running() {
        pgrep -x waynergy &>/dev/null
    }

    is_connected() {
        netstat -a | grep "laptop-wire:24800 ESTABLISHED" &>/dev/null
    }

    output_text="$glyph"
    output_class="not_running"

    if is_running; then
        output_class="running"
        if is_connected; then
            output_class="runing_conn"
        fi
    fi

    echo "{\"text\":\"$output_text\",\"class\":\"$output_class\"}"

Now, contrary to the error at the top of this post, above, I believe the script below does produce valid JSON.

Output examples:

{"text":"\uf192","class":"not_running"} {"text":"\uf192","class":"running"} {"text":"\uf192","class":"runing_conn"}

Is this a known issue? I did look but could not find a duplicate.

Any suggestions on how to help find root cause?

Thank you

simonm avatar Aug 08 '24 16:08 simonm

It's not necessarily the json output from the script. The config file is json as well. I can't reproduce any issues otherwise, but if I replace "signal" : 12 with "signal" : "12xyz" I get [error] Value is not convertible to Int. and waybar exits.

Obviously, that's not what your config file says, and I also don't see the uncaught exception. Still, since the signal is theoretically sent to all modules, it might be worth checking your config file for other signals?

Another thing you can try to narrow it down, is to use plain text output instead of json. If the error still occurs that way, it's probably not the json output from your script. ;)

RobertMueller2 avatar Aug 09 '24 13:08 RobertMueller2