[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to control LCD backlight via program?



On Thu, 25 Sep 2003 14:36:14 +0800 Yun-Ta Tsai wrote:
> On Thursday 25 September 2003 14:06, Carlos Sousa wrote:
> >
> > In my machine, the rest of the buttons will run sylpheed, mozilla and
> > openoffice.
> 
> I have problem with this.
> My laptop is shared with other users, but while executing mozilla via acpid 
> script, the uid will be root. How can I prevent this?

(I was hoping no one would ask that... ;)

Here's the ugly hack I've come up with:

- acpid is configured to run a root script (see below) for each of the
  desired events (button press, lid open/close, etc.)

- Each non-root user that wants to take advantage of these acpi features
  creates scripts under $HOME/.acpi/ for the desired events, containing
  calls to the desired programs (ex: 'mozilla &').

- root also creates scripts under /root/.acpi/ for all the desired events,
  to be called by acpid.
  In the case of user-unrelated events (like speedstepping the processor
  or dimming the LCD backlight), the root script will just run the
  appropriate code.
  In the case of events triggering user-related actions (like calling up
  an email client), the root script will try to determine the user logged
  into the X session, and then use 'su -c' to execute the relevant script in
  that user's directory.

The ugliness is, of course, in the code I've come up for X user detection,
which is based on the process table (ps). First it collects all X displays
currently running, then, for each of them, it tries to determine its user
(following the PID and parent PID hints, can't be done directly).

I've had success applying this logic to various combinations of X displays,
started by various methods (startx, xdm, kdm, gdm), my code has always
come up with the correct X user(s).

Of course, if there are X sessions belonging to more than one user, we
have a problem...

I've googled around, and I don't think there's any Right Way (tm) to
determine to which user the X display currently on the screen belongs to,
so the above method is my best attempt to overcome the problem. It has
been working ok...

HTH.

-- 
Carlos Sousa
http://vbc.dyndns.org/



Reply to: