• NetBSD
  • XFCE's battery monitor in NetBSD 9.1

Hi folks,

Was anybody able to make XFCE's battery monitor plugin work in NetBSD 9.1?
I've done some research (works with APM and ACPI), looked into the source code of the plugin (there is a "patch" for NetBSD) but I haven't found any way to make it work:


#if defined(__OpenBSD__) || defined(__NetBSD__)
  /* Code for OpenBSD by Joe Ammond <jra@twinight.org>. Using the same
     procedure as for FreeBSD.
     Made to work on NetBSD by Stefan Sperling <stsp@stsp.in-berlin.de>
  */
    struct apm_power_info apm;
    int fd;

    fd = open(APMDEVICE, O_RDONLY);
    if (fd == -1) return TRUE;
    if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1)
        return TRUE;
    close(fd);
    charge = apm.battery_life;
    time_remaining = apm.minutes_left;
    acline = apm.ac_state ? TRUE : FALSE;
    method = BM_USE_APM;

My instance displays the following:

[ 1.032653] apm0 at acpi0: Power Management spec V1.2

And the apm command works like a charm:

Battery charge state: high
Battery remaining: 100 percent
A/C adapter state: connected
Power management enabled
Number of batteries: 1

It looks like I'm missing something or the version shipped with pkgin (xfce4-battery-plugin-1.1.3nb4) doesn't include the patch, which I doubt as the code above is available in the mainstream version.

Does anyone have the same issue? By the way, I'm running NetBSD on a cutting edge Asus EeePC 1005P 🙂 which, indeed, is back to life thanks to NetBSD and an SDD disk.

Thanks in advance.

bsdprof

  • rvp replied to this.
  • Jay likes this.

    it should use envsys rather than apm on netbsd imo

    • Jay likes this.

    bsdprof xfce4-battery-plugin won't on amd64. As @nia said, the code will have to be re-worked to use envsys on that (and other) platform(s). But, it should work just fine on i386 which still has /dev/apm.

    What's the output of this commmand:

    $ ls -l /dev/apm

    Compile and run this program:

    #include <sys/param.h>
    #include <sys/ioctl.h>
    #include <machine/apmvar.h>
    
    #include <err.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int
    main(void)
    {
    	struct apm_power_info apm;
    	int fd;
    
    	if ((fd = open("/dev/apm", O_RDONLY)) == -1)
    		err(EXIT_FAILURE, "open");
    	if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1)
    		err(EXIT_FAILURE, "ioctl");
    	printf("life: %d\n", apm.battery_life);
    	printf("left: %d\n:", apm.minutes_left);
    	printf("state: %d\n", apm.ac_state);
    
    	exit(EXIT_SUCCESS);
    }

    If the command prints sensible values, then xfce4-battery-plugin should also work--I've just pulled that NetBSD-specific code out into a separate program.

      6 days later

      rvp

      Hey rvp,

      This is the output of ls -l /dev/apm:

      [bsdprof@shuri ~]$ ls -l /dev/apm
      crw-r--r--  1 root  wheel  21, 0 Nov 21 13:23 /dev/apm

      And this is the output of the code you pulled from the plugin:

      [bsdprof@shuri ~]$ ./apm 
      life: 82
      left: 112
      :state: 0

      That means the current plugin doesn't have the patch 🙂 I've double checked the NetBSD 9.1 installation in my ThinkPad X230 and no apm device.

      I'll dig into envsys and I'll modify the code to add apm and envsys support; I'll update the thread when I make it work.

      • rvp replied to this.
      • Jay likes this.

        bsdprof This is the output of ls -l /dev/apm

        So, /dev/apm is present and readable by all. This is OK.

        bsdprof That means the current plugin doesn't have the patch

        Compile the code yourself with debug messages turned on.

        bsdprof I've double checked the NetBSD 9.1 installation in my ThinkPad X230 and no apm device.

        amd64 won't have /dev/apm

        • Jay likes this.
        7 days later

        Trying to work some battery monitor things myself. My issue currently is that compile fails because

        #include <machine/apmvar.h>

        cannot be found.

        I've tried to figure out where that specific file might come from, but no luck yet.

          0x1b machine is a symbolic link in /usr/include to the system's architecture:

          $ ls -l /usr/include/machine
          lrwxr-xr-x  1 root  wheel  5 Dec 20 13:46 /usr/include/machine -> amd64
          $

          And, apmvar.h can be found in /usr/include/i386/ as APM is i386-specific. For amd64 use the envsys framework.

          0x1b Here's a simple battery monitor shell-script.
          Call it whatever you fancy, make it executable and add it to your bar.

          #!/bin/sh
          
          while true; do
          
          # Battery
          BAT="$(envstat -s acpibat0:charge | tail -1 | sed -e 's,.*(\([ ]*[0-9]*\)\..*,\1,g')"
          
          # Print
          echo "Bat: $BAT%"
          
          sleep 2
          done
          exit 0