Re: [hackers] [slstatus][PATCH] backlight: implemented openbsd support

From: Tobias Tschinkowitz <he4d_AT_posteo.de>
Date: Wed, 23 May 2018 22:47:37 +0200

On Wed, May 23, 2018 at 04:30:41PM -0300, lucas wrote:
Lucas,
> Tobias,
>
> > See my notes below the commit message of the patch.
>
> I saw the note just after sending the email. My bad. Still, I think that
> slstatus shouldn't be run as root. It would be nice to find a workaround
> when launching X from xenodm.
>

Absolutely, this is why i just noted that this is a proposal.
I hoped to get the discussion started on how we could work this out
(seems like it worked..)

> > Updated diff below.
> >
> > diff --git a/components/backlight.c b/components/backlight.c
> > index 21e06a1..4234164 100644
> > --- a/components/backlight.c
> > +++ b/components/backlight.c
> > _AT_@ -39,7 +39,7 @@
> > const char *
> > backlight_perc(const char *unused)
> > {
> > - int fd, err;
> > + int fd;
> > struct wsdisplay_param wsd_param = {
> > .param = WSDISPLAYIO_PARAM_BRIGHTNESS
> > };
> > _AT_@ -48,11 +48,12 @@
> > warn("could not open /dev/ttyC0");
> > return NULL;
> > }
> > - if ((err = ioctl(fd, WSDISPLAYIO_GETPARAM, &wsd_param)) < 0) {
> > + if ((ioctl(fd, WSDISPLAYIO_GETPARAM, &wsd_param)) < 0) {
>
> Haven't taken a look at the rest of the code, but are the extra () used
> everywhere?
>

Nope, just blindly removed the err and forgot about the (). Removed
them, diff below..

> > warn("ioctl 'WSDISPLAYIO_GETPARAM' failed");
> > return NULL;
> > }
> > - return bprintf("%d", wsd_param.curval * 100 / wsd_param.max);
> > + return bprintf("%d", wsd_param.curval * 100 /
> > + (wsd_param.max - wsd_param.min));
>
> Better, but .curval is still between .min and .max, so you should substract
> .min from it to get the right percentage.
>

Fixed in the diff below. Thanks again.

> > }
> >
> > #endif
> >
>

Greetings,
Tobias

diff --git a/components/backlight.c b/components/backlight.c
index 21e06a1..cc13aed 100644
--- a/components/backlight.c
+++ b/components/backlight.c
_AT_@ -39,7 +39,7 @@
         const char *
         backlight_perc(const char *unused)
         {
- int fd, err;
+ int fd;
                 struct wsdisplay_param wsd_param = {
                         .param = WSDISPLAYIO_PARAM_BRIGHTNESS
                 };
_AT_@ -48,11 +48,12 @@
                         warn("could not open /dev/ttyC0");
                         return NULL;
                 }
- if ((err = ioctl(fd, WSDISPLAYIO_GETPARAM, &wsd_param)) < 0) {
+ if (ioctl(fd, WSDISPLAYIO_GETPARAM, &wsd_param) < 0) {
                         warn("ioctl 'WSDISPLAYIO_GETPARAM' failed");
                         return NULL;
                 }
- return bprintf("%d", wsd_param.curval * 100 / wsd_param.max);
+ return bprintf("%d", (wsd_param.curval - wsd_param.min) * 100 /
+ (wsd_param.max - wsd_param.min));
         }
 
 #endif
Received on Wed May 23 2018 - 22:47:37 CEST

This archive was generated by hypermail 2.3.0 : Wed May 23 2018 - 22:48:38 CEST