ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have written a acpi-daemon that polls my batterylevel. The daemon should start another programm, when my battery is low. Therefore I used "system() " to call my qt-programm which just displays a small window with a button.
I have written the initscript for the daemon and everything works fine, except that there's no popup window.
I don't really now why, because if I start the daemon by hand in a terminal and send to background, the external qt-program is called and there's displayed the warning window.
Is it because no terminal is associated for daemon ??
Basically, daemons are system services that are running no matter what, so in general they cannot produce output. Not to a terminal, not to an X-server. Simply because it may not be running at that particular time, or it may not have permission to open a window or whatever.
The "nice" thing of solving this problem, is having the deamon not open an x-window. Instead, you write an x-applet that sits in your panel (for example), and connects to the daemon, receiving an update when the power is low. Then it can open a window (since it already has permission to do so.
Then again, there are already lots of applications that do just that.
Anyway. To solve your original problem, the daemon would have to know to which X-server to connect (i.e. its "DISPLAY" environment variable should be set correctly) and it should have permission to show a window. Giving permission can be done in a multitude of ways. One would be to have the daemon run as the same user that is currently logged in (i.e. you), or you could run "xhost +", basically giving anyone permission. Aternatively, you should look into xauth.
When starting the daemon from the shell, both conditions (permission and correct DISPLAY environment variable) are satisfied automatically, which is why it works then. For daemon mode, there is a little bit more work to do.
i'll try to do it the nice way, the other stuff is a nice workaround but quite unsafety.
How can I establish a connection to the daemon, since I have closed all filedescriptors. My daemon just posts logs via syslog.h commands.
Do I have to realize this by sockets?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.