I'm porting some Qt Windows/VC++ code to Linux/GCC. The application can add it's own shortcut to the Windows Autostart folder so the application starts after login.
I want to do the same in Linux. I'm using Kubuntu 15.10 but the solution should work for virtually all (or at least most) Linux variants out there. And it should work without super user rights (or it should request the rights automatically).
I searched the web and found two solutions:
- Add a desktop entry file to
$HOME/.config/autostart - Add a symbolic link to
/etc/init.d/
Will they both work in all Linux distributions? What are the differences? Which is to be preferred?
Also I would like to know if I should do that by programmatically running a shell command or if there is some native API I could use in C/C++ (including easy error detection).
/etcis system-wide, under/homeit is user-specific. That also means that if no user is logged in, nothing is running and if two users are logged in, the same program could be started twice. It seems that you want at most one program running in the system, since it always runs as root. However, that would have to run without an X session. If you need a UI, you could also install the application with SUID-bit set and then use a per-user autostart. Lastly, you could also start a server on demand, e.g. via xinetd if it operates as a networked server.