views:

220

answers:

4

Hi, on Ubuntu 8/9, i'm trying to write a daemon in python, that monitors a certain network condition and informs the user using a gtk.messagedialog. I installed this script using rc-update. The daemon starts at boot, but doesn't show the dialog even after I login. I assume because init.d starts my daemon at tty1 and no gnome is available. Tried running the dialog through a subprocess, but it seems to inherit the same run environment. Whats the best practice for this sort of thing.

A: 

In order to find out whether your code works at all, you should first try and execute the daemon as normal program in a graphical shell (on a GNOME desktop).

You could also call zenity.

AndiDog
A: 

It does work when GNOME is running. Zenity is "ok", if it works, and I don't think it will, because it is the same problem, there is no GNOME when I'll call it with python.

helpisrequired
In other words... server/client is the way.Thought about it after I posted... but wanted something with one process.Thank you
helpisrequired
zenity seems to work fine when executed as normal user (e.g. `env DISPLAY=:0.0 zenity --question`). But when executed as root, it "cannot open display: :0.0" (guess root is not in the xauth list?!) - and daemons are usually executed as root!This is a very interesting question but I couldn't find a good solution. Maybe you should start the daemon after GDM, e.g. as a normal GNOME/GTK app. BTW you should comment on answers instead of answering your own question ;)
AndiDog
+3  A: 

If five users are logged in to X sessions, who gets the message? Everyone?

If someone is logged in locally but only using the tty, and not X11, should they see the message?

If someone is logged in remotely via ssh -X to run a graphic application on their own system off of your CPU, should they see the message? How would you get it to them?

Linux is too flexible for your current approach. The standard way to do this is for any user who is interested in the kind of message you are sending to run an application that receives the message and displays it in a way of its choosing. Dbus is a popular way of setting up the messaging process. This way remote users or users logged in with TTY mode only still have an option for seeing the message.

Justin Smith
Good point. I didn't even think about that problem.
AndiDog
A: 

You may use notify-send (from libnotify-bin package) to send notifications to desktop users from your daemon.

dtmilano