Louvre  v2.9.0-1
C++ library for Wayland compositors
Static Public Member Functions | List of all members
LLauncher Class Reference

Utility for launching applications safely. More...

Static Public Member Functions

static pid_t startDaemon (const std::string &name="LLauncher")
 Starts the daemon and returns its process ID. More...
 
static pid_t pid ()
 Gets the process ID (PID) of the daemon. More...
 
static pid_t launch (const std::string &command)
 Launches an application. More...
 
static void stopDaemon ()
 Terminates the daemon. More...
 

Detailed Description

Utility for launching applications safely.

Creating a fork of the compositor while it's running is a risky operation that can result in resource leaks to child processes, leading to undesired behaviors and potentially causing the compositor to experience reduced performance or crashes.

The LLauncher class is an auxiliary class designed to facilitate the secure launching of applications from the compositor. It creates a background daemon capable of launching applications using the system() call.

The daemon must be started before creating an instance of LCompositor, achieved through the startDaemon() function. The daemon can be terminated by calling the stopDaemon() function and is automatically exited when the compositor ends.

If the daemon exits normally, it sends a SIGTERM signal to all processes in its process group.

Member Function Documentation

◆ startDaemon()

pid_t startDaemon ( const std::string &  name = "LLauncher")
static

Starts the daemon and returns its process ID.

Should preferably be the first function called from the main() function and must be called before creating an instance of LCompositor.

Parameters
nameThe process name to be set for the daemon.
Returns
The process ID of the daemon if successful, or < 0 on error. Possible errors include the daemon already running or calling this function after creating an instance of LCompositor.

◆ pid()

pid_t pid ( )
static

Gets the process ID (PID) of the daemon.

Returns
The PID of the daemon if it is running, or a negative number if the daemon is not running.

◆ launch()

pid_t launch ( const std::string &  command)
static

Launches an application.

This function uses the same arguments as the system() call. It launches an application specified by the provided command and returns the application's process ID.

Parameters
commandThe command to execute, as a string.
Returns
The process ID of the launched application if successful, or a negative number on error.

◆ stopDaemon()

void stopDaemon ( )
static

Terminates the daemon.

Calling this method when the daemon is not running is a no-op.

Note
If the daemon is stopped while the compositor is running, it won't be able to be launched again.