Skip to content
Advertisement

Enable a linux service to show popup window

I developed an IP messenger using C language and I wish to share some of it’s implementation details to make completely understand my problem.

  1. Used GTK+-2.0 library for showing GUI windows.
  2. It has a listening socket and whenever a new connection arrives then it will create a new process to serve the connection.
  3. Whenever a new message arrives then it will show a GUI window to display the received message (like popup window).
  4. It need root permissions to run because it uses a raw socket to send ICMP echo packets to identify the available hosts in the local network. (RAW socket requires super permissions)
  5. The process is demonized , so it will run on background and show popups only when a message is arrived.
  6. My machine is CentOS 6.9

And everything works perfect when i am starting this process from a terminal. But then i created a startup entry for this program to run it as a service, by adding startup script in /etc/init.d/ directory. then i started my service using the service command,

 # service ipmsnger start

Now i can see the process is running by using ps command. but it does not shows the popup window if a message arrives. message sender gets success delivery report from the messenger. What will be the reason? What is the difference between staring a demon process from terminal by user and starting it as a startup service by system?

Advertisement

Answer

When you start your program from a terminal window, it is associated with your current login session. This gives it the context needed to present popups in your GUI.

But remember that Linux is a multiuser system, supporting even multiple concurrent GUI sessions. Each GUI belongs to one session; there isn’t any sense of a one true GUI for the machine. If you start your program as a system service then it is not connected with any particular login session, so it does not know about your GUI to present anything there.

Given that the service runs with root privilege, it might be possible for it to discover login sessions and pop up messages in them, but you do not get that for free.

I infer that the point of running your program as a service is to make it usable by people who cannot assert root privilege. In that case, I suggest refactoring into two programs: a service that runs as root, and a client that runs without privilege. Users are expected to run the client, as themselves, in the session where they want to receive popups. The client registers itself with the server. The server receives messages from the network and distributes them to registered clients for them to display.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement