Re: Checking whether Gnome screensaver currently active

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

 



On Tuesday, January 18, 2011 09:00:22 am Robert Nichols wrote:
> On 01/18/2011 01:34 AM, Rick Sewill wrote:
> > On Monday, January 17, 2011 10:57:00 pm Robert Nichols wrote:
> >> On 01/17/2011 09:57 PM, Rick Sewill wrote:
> >>> Question please:
> >>> 
> >>> Can you use
> >>> gnome-screensaver-command -q
> >>> 
> >>> man gnome-screensaver-command
> >>> 
> >>> I'm currently trying out KDE so I don't know
> >>> what is returned by the above command for the
> >>> various gnome-screensaver states.
> >> 
> >> As I said in my original message, when run from a cron job that fails:
> >>        ** Message: Failed to connect to the D-BUS daemon:
> >>        /bin/dbus-launch terminated abnormally with the following error:
> >>        Autolaunch error: X11 initialization failed.
> >> 
> >> And yes, I did try it with "DISPLAY=:0.0" in the environment.
> > 
> > You have a good puzzle!
> > 
> > I read all the responses for the problem,
> > http://www.mail-archive.com/debian-kde@xxxxxxxxxxxxxxxx/msg30421.html
> > 
> > I tried to condense their answer to the following...please give it a try:
> > 
> > I created a file, ${HOME}/bin/testscreensaver
> > ===== Please begin contents of file testscreensaver with following line
> > #!/bin/bash
> > 
> > # We must set the DISPLAY variable so dbus is happy.
> > 
> > export DISPLAY=:0.0
> > 
> > # We must find the DBUS_SESSION_BUS_ADDRESS so dbus is happy.
> > 
> > for pid in $(pgrep -u $USER)
> > do
> > 
> >      declare DBUS_SESSION_BUS_ADDRESS=$(cat /proc/${pid}/environ | \
> >      
> >              tr '\0' '\n' | grep "DBUS_SESSION_BUS_ADDRESS=")
> > 
> > # I looked for the first DBUS_SESSION_BUS_ADDRESS found.
> > 
> >      [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] || break
> > 
> > done
> > 
> > 
> > # Strip off the DBUS_SESSION_BUS_ADDRESS= string at the beginning.
> > DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:25}"
> > 
> > # I echo it for debugging purposes...you probably don't want to echo it.
> > echo "Set bus address to<${DBUS_SESSION_BUS_ADDRESS}>"
> > 
> > # If I have a string, I call the gnome-screensaver-command
> > [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] || gnome-screensaver-command -q
> > 
> > ===== Please end file testscreensaver with previous line
> 
> Hmmm, in that script you're not doing anything with
> DBUS_SESSION_BUS_ADDRESS beyond testing for non-null (it's not exported),
> so "Set bus address to" is a misnomer.  "Found bus address" might be more
> to the point.  It does test whether this user currently has a session,
> which is useful.
> 

Please see "man dbus-daemon".

I believe the variable, DBUS_SESSION_BUS_ADDRESS, must be set for desktop 
applications to find the per-session daemon to have interprocess communication 
amongst themselves.  From "man dbus-daemon", I am referring to the per-session 
daemon, not the systemwide daemon.

I believe gnome-screensaver-command attempts to use the per-session daemon to 
talk to gnome-screensaver.

I made the assumption all $USER processes, where DBUS_SESSION_BUS_ADDRESS was 
defined, would be the same, and associated with the current, user session.
This is remiss of me.

To be pedantic, one may need to check the /proc/${PID}/environ special file for 
the value of the DISPLAY variable, to insure the session isn't a remote ssh or 
other remote session.  I didn't insure /proc/${PID}/environ was readable.
Perhaps others can suggest other and better checks.

There are other interesting things mentioned in "man dbus-daemon".
Please see the DEBUGGING section.  It speaks of running dbus-monitor.
It speaks of running a test copy of dbus-daemon, and how to communicate with 
the test copy by setting the DBUS_SESSION_BUS_ADDRESS for the applications you 
want to test with the test copy of the dbus-daemon.

> OK, now it looks like I might just have been hit by a glitch.  On another
> machine, I found that
> 
>      DISPLAY=:0.0 gnome-screensaver-command -q
> 
> works just fine in a cron job.  After rebooting the desktop system where
> I'd been having the problem (system had been up 22 days with me poking
> around trying things), it works fine there, too.
> 

I am surprised, given what I read about DBUS_SESSION_BUS_ADDRESS,
this would work without DBUS_SESSION_BUS_ADDRESS being set.

What version of software are these other machines using?

> So, all I can say is, "Sorry for contributing to the noise here."  At least
> I've learned a few things from some of the responses.  Thanks, all.

It is not noise.  Your question is a good one.  I enjoyed looking up things.
If my answer is wrong, I hope others gently correct me.

Attachment: signature.asc
Description: This is a digitally signed message part.

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux