Sunshine master
Self-hosted game stream host for Moonlight.
process.cpp File Reference

Definitions for the startup and shutdown of the apps started by a streaming Session. More...

#include <filesystem>
#include <string>
#include <thread>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/crc.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/token_functions.hpp>
#include <openssl/evp.h>
#include <openssl/sha.h>
#include "config.h"
#include "crypto.h"
#include "display_device.h"
#include "logging.h"
#include "platform/common.h"
#include "process.h"
#include "system_tray.h"
#include "utility.h"
#include "platform/windows/utf_utils.h"
#include <share.h>
Include dependency graph for process.cpp:

Classes

class  proc::deinit_t
 RAII helper that runs shutdown cleanup when destroyed. More...
 

Functions

std::tuple< std::string, std::string > proc::calculate_app_id (const std::string &app_name, std::string app_image_path, int index)
 Calculate a stable id based on name and image data.
 
uint32_t proc::calculate_crc32 (const std::string &input)
 Calculate the CRC-32 checksum for a string.
 
std::optional< std::string > proc::calculate_sha256 (const std::string &filename)
 Calculate the SHA-256 digest for a file.
 
bool proc::check_valid_png (const std::filesystem::path &path)
 Validates a path whether it is a valid PNG.
 
std::string_view::iterator proc::find_match (std::string_view::iterator begin, std::string_view::iterator end)
 Find the closing parenthesis for an environment-variable expression.
 
boost::filesystem::path proc::find_working_directory (const std::string &cmd, boost::process::v1::environment &env)
 Resolve the working directory for a configured command.
 
std::unique_ptr< platf::deinit_tproc::init ()
 Initialize proc functions.
 
std::optional< proc::proc_tproc::parse (const std::string &file_name)
 Parse serialized text into the corresponding runtime representation.
 
std::string proc::parse_env_val (boost::process::v1::native_environment &env, const std::string_view &val_raw)
 Parse env val.
 
void proc::refresh (const std::string &file_name)
 Refresh cached platform state from the operating system.
 
void proc::terminate_process_group (boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout)
 Terminates all child processes in a process group.
 
std::string proc::validate_app_image_path (std::string app_image_path)
 Validate app image path.
 

Variables

proc_t proc::proc
 Global process registry used to track and terminate child processes.
 

Detailed Description

Definitions for the startup and shutdown of the apps started by a streaming Session.

Function Documentation

◆ calculate_app_id()

std::tuple< std::string, std::string > proc::calculate_app_id ( const std::string & app_name,
std::string app_image_path,
int index )

Calculate a stable id based on name and image data.

Returns
Tuple of id calculated without index (for use if no collision) and one with.
Parameters
app_nameApp name.
app_image_pathApp image path.
indexZero-based index of the item being addressed.

◆ calculate_crc32()

uint32_t proc::calculate_crc32 ( const std::string & input)

Calculate the CRC-32 checksum for a string.

Parameters
inputBytes to include in the checksum.
Returns
CRC-32 value for the input bytes.

◆ calculate_sha256()

std::optional< std::string > proc::calculate_sha256 ( const std::string & filename)

Calculate the SHA-256 digest for a file.

Parameters
filenameFile path whose contents should be hashed.
Returns
Lowercase hexadecimal SHA-256 digest, or std::nullopt on read/hash failure.

◆ check_valid_png()

bool proc::check_valid_png ( const std::filesystem::path & path)

Validates a path whether it is a valid PNG.

Parameters
pathThe path to the PNG file.
Returns
true if the file has a valid PNG signature, false otherwise.

◆ find_match()

std::string_view::iterator proc::find_match ( std::string_view::iterator begin,
std::string_view::iterator end )

Find the closing parenthesis for an environment-variable expression.

Parameters
beginIterator positioned at the opening parenthesis.
endEnd iterator for the expression being scanned.
Returns
Iterator for the matching closing parenthesis, or end when unmatched.

◆ find_working_directory()

boost::filesystem::path proc::find_working_directory ( const std::string & cmd,
boost::process::v1::environment & env )

Resolve the working directory for a configured command.

Parameters
cmdCommand line to execute or inspect.
envEnvironment variables for the child process.
Returns
Directory used to launch the command, falling back to PATH lookup when needed.

◆ init()

std::unique_ptr< platf::deinit_t > proc::init ( )

Initialize proc functions.

Returns
Unique pointer to deinit_t to manage cleanup

◆ parse()

std::optional< proc::proc_t > proc::parse ( const std::string & file_name)

Parse serialized text into the corresponding runtime representation.

Parameters
file_nameFile name.
Returns
Parsed value or parse status.

◆ parse_env_val()

std::string proc::parse_env_val ( boost::process::v1::native_environment & env,
const std::string_view & val_raw )

Parse env val.

Parameters
envEnvironment variables for the child process.
val_rawRaw value that may contain substitutions.
Returns
Value with recognized environment-variable substitutions expanded.

◆ refresh()

void proc::refresh ( const std::string & file_name)

Refresh cached platform state from the operating system.

Parameters
file_nameFile name.

◆ terminate_process_group()

void proc::terminate_process_group ( boost::process::v1::child & proc,
boost::process::v1::group & group,
std::chrono::seconds exit_timeout )

Terminates all child processes in a process group.

Parameters
procThe child process itself.
groupThe group of all children in the process tree.
exit_timeoutThe timeout to wait for the process group to gracefully exit.

◆ validate_app_image_path()

std::string proc::validate_app_image_path ( std::string app_image_path)

Validate app image path.

Parameters
app_image_pathCandidate image path from the application configuration.
Returns
Existing PNG path, or the default application image when validation fails.