hkdb / s76cc

A GUI wrapper for system76-power for adjusting charge thresholds
MIT License
2 stars 0 forks source link

panic: runtime error: slice bounds out of range #1

Open yochananmarqos opened 3 years ago

yochananmarqos commented 3 years ago

The binary has hardcoded references to your home directory:

No config directory... creating...
exit status 1

panic: runtime error: slice bounds out of range [9:0]

goroutine 1 [running, locked to thread]:
main.checkCurrent(0x0, 0xb, 0x56d398, 0x2, 0x56d416, 0x3)
    /home/hkdb/Development/s76cc/main.go:121 +0x6f1
main.initConfig()
    /home/hkdb/Development/s76cc/main.go:88 +0x280
main.getUserEnv()
    /home/hkdb/Development/s76cc/main.go:63 +0xfa
main.main()
    /home/hkdb/Development/s76cc/main.go:536 +0x22
hkdb commented 3 years ago

@yochananmarqos

Thanks for helping to test! I was able to replicate your issue with a vanilla Arch VM. These "hard coded references to your home directory" are normal as that's where I compiled the binary from so it's expected. The real problem is that my error handling is not done well enough to be helpful at pointing out what's really wrong which I will work on. From my playing around with my vanilla Arch VM, I was able to replicate your issue and looks like the root cause is it's because system76-power is not installed/available or not in your $PATH. From my Arch VM, I wrote a dummy script placed in /usr/local/bin as such to emulate that system76-power is actually there:

#!/bin/bash

echo "Profile: Full Charge (full-charge)"
echo "Start: 96"
echo "End: 100"#!/bin/bash

Then, I tried to run the binary again and it launches no problem. Can you help me verify that this is also your case?

You don't have to use the script to emulation system76-power to verify if you don't want to. You can simply check to see what happens if you type system76-power from the terminal.

On another note, I also realized that $HOME/.local/bin is not used or automatically made in Arch nor is there a .profile in /etc/skel like PopOS! so as to help automatically add $HOME/.local/bin to your $PATH if it exists. Here's the excerpt from Pop's /etc/skel/.profile that takes care of this part:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

This issue breaks my install and launch method. So perhaps I can add an OS detection feature on the install and if it's Arch, do this a little differently.

Thanks again for the feedback! Will let you know once I find some time to fix this and push.

yochananmarqos commented 3 years ago

I installed it to /usr/bin/ as I was preparing an AUR PKGBUILD.

system76-power is indeed in my $PATH:

❯ which system76-power
/usr/bin/system76-power
❯ system76-power -V
system76-power 1.1.16

I tried copying the binary to ~/.local/bin/ and it made no difference. I have added it to my $PATH:

❯ echo $PATH
/home/yochanan/bin:/home/yochanan/.local/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
hkdb commented 3 years ago

Hum... interesting... What does the command output if you type the below?

system76-power charge-thresholds

Thanks...

yochananmarqos commented 3 years ago

I don't have a laptop with switched graphics, so I really don't need system76-power. I have a Serval WS 12. Either way, right now I do have it installed and the service is started:

❯ system76-power charge-thresholds
daemon returned an error message: "Not running System76 firmware with charge threshold suppport"
❯ systemctl status system76-power.service
● system76-power.service - System76 Power Daemon
     Loaded: loaded (/usr/lib/systemd/system/system76-power.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2021-05-04 16:32:06 MDT; 1min 22s ago
   Main PID: 707654 (system76-power)
      Tasks: 17 (limit: 38324)
     Memory: 2.4M
        CPU: 33ms
     CGroup: /system.slice/system76-power.service
             └─707654 /usr/bin/system76-power daemon

May 04 16:32:06 manjaro system76-power[707654]: [WARN] Failed to set automatic graphics power: does not have switchable graphics
May 04 16:32:06 manjaro system76-power[707654]: [INFO] Initializing with the balanced profile
May 04 16:32:06 manjaro system76-power[707654]: [INFO] Registering dbus name com.system76.PowerDaemon
May 04 16:32:06 manjaro systemd[1]: Started System76 Power Daemon.
May 04 16:32:06 manjaro system76-power[707654]: [INFO] Adding dbus path /com/system76/PowerDaemon with interface com.system76.PowerDaemon
May 04 16:32:06 manjaro system76-power[707654]: [ERROR] fan daemon: platform hwmon not found
May 04 16:32:06 manjaro system76-power[707654]: [INFO] Handling dbus requests
May 04 16:32:06 manjaro system76-power[707654]: [ERROR] hid_backlight: no system76_acpi::kbd_backlight led
May 04 16:32:08 manjaro system76-power[707654]: [INFO] DBUS Received GetChargeProfiles() method
May 04 16:32:08 manjaro system76-power[707654]: [INFO] DBUS Received GetChargeThresholds() method
hkdb commented 3 years ago

Yeah, so that's probably what caused the crash. If you are not using system76 firmware, it will return the wrong message and hence, causing the app to crash. Perhaps you can try to also install the System76 firmware as well?

yochananmarqos commented 3 years ago

You misunderstood the output. My laptop firmware does not support the feature.

hkdb commented 3 years ago

Oh right... Well, in that case... looks like there's not a whole lot we can do.... Either way, I will still try to fix what I can on my side so that at least other Lemur Pro users can benefit from this. Thanks!

yochananmarqos commented 3 years ago

Well, I guess I won't be able to support an AUR package then.

Either way, please add the source files so others can compile it themselves.

yochananmarqos commented 1 year ago

I now have a Gazelle 17 (gaze17-3060-b) with support and decided to try this out again.

It's not detecting the profile correctly and only has the option to change to Full Charge.

❯ system76-power charge-thresholds --list-profiles
full_charge
  Title: Full Charge
  Description: Battery is charged to its full capacity for the longest possible use on battery power. Charging resumes when the battery falls below 96% charge.
  Start: 96
  End: 100
balanced
  Title: Balanced
  Description: Use this threshold when you unplug frequently but don't need the full battery capacity. Charging stops when the battery reaches 90% capacity and resumes when the battery falls below 85%.
  Start: 86
  End: 90
max_lifespan
  Title: Maximum Lifespan
  Description: Use this threshold if you rarely use the system on battery for extended periods. Charging stops when the battery reaches 60% capacity and resumes when the battery falls below 50%.
  Start: 50
  End: 60
❯ system76-power charge-thresholds
Profile: Maximum Lifespan (max_lifespan)
Start: 50
End: 60
❯ s76cc
[{Full Charge 96 100}]
Count: 1
Count Index: 0
Profile: Maximum Lifespan (max_lifespan)
Start: 50
End: 60

Name:  Maximum Lifespan (max_lifespan)
Start:  50
End:  60
Profile: Full Charge (full_charge)
Start: 96
End: 100

image

❯ systemctl status com.system76.PowerDaemon.service
● com.system76.PowerDaemon.service - System76 Power Daemon
     Loaded: loaded (/usr/lib/systemd/system/com.system76.PowerDaemon.service; enabled; preset: disabled)
     Active: active (running) since Fri 2023-06-30 09:12:54 MDT; 1min 32s ago
   Main PID: 110247 (system76-power)
      Tasks: 1 (limit: 38185)
     Memory: 1.0M
        CPU: 33ms
     CGroup: /system.slice/com.system76.PowerDaemon.service
             └─110247 /usr/bin/system76-power daemon

Jun 30 09:12:54 gazelle system76-power[110247]: [INFO] Adding dbus path /com/system76/PowerDaemon with interface com.system76.PowerDaemon
Jun 30 09:12:54 gazelle systemd[1]: Started System76 Power Daemon.
Jun 30 09:12:54 gazelle system76-power[110247]: [ERROR] fan daemon: platform hwmon not found
Jun 30 09:12:54 gazelle system76-power[110247]: [INFO] Handling dbus requests
Jun 30 09:12:54 gazelle system76-power[110247]: [INFO] hid_backlight: no devices found
Jun 30 09:12:59 gazelle system76-power[110247]: [INFO] Setting power management to on
Jun 30 09:12:59 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeProfiles() method
Jun 30 09:12:59 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeThresholds() method
Jun 30 09:13:01 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeProfiles() method
Jun 30 09:13:03 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeThresholds() method
yochananmarqos commented 1 year ago

I just added the preset profiles manually, then started it again. It crashed and the service died:

❯ s76cc
[{Full Charge 96 100} {Full Charge 96 100} {Balanced 86 90} {Maximum Lifespan 50 60}]
Count: 4
Count Index: 0
exit status 1

panic: runtime error: slice bounds out of range [9:0]

goroutine 1 [running, locked to thread]:
main.checkCurrent(0x5938c0, 0xc0000c8008, 0xc0000e1e10, 0x2, 0x2, 0xf)
    /home/hkdb/Development/s76cc/main.go:121 +0x6f1
main.loadConfig()
    /home/hkdb/Development/s76cc/main.go:291 +0x60a
main.getUserEnv()
    /home/hkdb/Development/s76cc/main.go:66 +0xeb
main.main()
    /home/hkdb/Development/s76cc/main.go:536 +0x22
❯ systemctl status com.system76.PowerDaemon.service
○ com.system76.PowerDaemon.service - System76 Power Daemon
     Loaded: loaded (/usr/lib/systemd/system/com.system76.PowerDaemon.service; enabled; preset: disabled)
     Active: inactive (dead) since Fri 2023-06-30 09:22:15 MDT; 3min 13s ago
   Duration: 9min 20.613s
    Process: 110247 ExecStart=/usr/bin/system76-power daemon (code=exited, status=0/SUCCESS)
   Main PID: 110247 (code=exited, status=0/SUCCESS)
        CPU: 111ms

Jun 30 09:20:51 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeThresholds() method
Jun 30 09:21:05 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeProfiles() method
Jun 30 09:21:05 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeThresholds() method
Jun 30 09:21:14 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeProfiles() method
Jun 30 09:21:14 gazelle system76-power[110247]: [INFO] DBUS Received GetChargeThresholds() method
Jun 30 09:22:15 gazelle systemd[1]: Stopping System76 Power Daemon...
Jun 30 09:22:15 gazelle system76-power[110247]: [INFO] caught signal: SIGTERM
Jun 30 09:22:15 gazelle system76-power[110247]: [INFO] daemon exited from loop
Jun 30 09:22:15 gazelle systemd[1]: com.system76.PowerDaemon.service: Deactivated successfully.
Jun 30 09:22:15 gazelle systemd[1]: Stopped System76 Power Daemon.

After restarting the service, the program works normally again.

yochananmarqos commented 1 year ago

Update: It seems even though system76-power is changing the battery threshold, it's not actually doing anything. It should start discharging, right?

The service crashing was due to having power-profiles-daemon.service running at the same time, forgot about that. I disabled it and masked it.