CARTA Backend
The backend component of CARTA
Loading...
Searching...
No Matches
App.cc File Reference
#include "App.h"
#include <unistd.h>
#include <climits>
#include <fstream>
#include <sstream>
#include "FileSystem.h"
#include "Logger/Logger.h"
Include dependency graph for App.cc:

Macros

#define MAX_PLATFORM_INFO_LENGTH   1024
 
#define MAX_PLATFORM_LINE_LENGTH   256
 

Functions

bool FindExecutablePath (std::string &path)
 Retrieves the absolute path of the currently running executable.
 
std::string GetReleaseInformation ()
 Retrieves the operating system release information.
 
std::string OutputOfCommand (const char *command)
 Executes a shell command and returns its output.
 

Macro Definition Documentation

◆ MAX_PLATFORM_INFO_LENGTH

#define MAX_PLATFORM_INFO_LENGTH   1024

◆ MAX_PLATFORM_LINE_LENGTH

#define MAX_PLATFORM_LINE_LENGTH   256

Function Documentation

◆ FindExecutablePath()

bool FindExecutablePath ( std::string &  path)

Retrieves the absolute path of the currently running executable.

This function determines the full path of the running executable and stores it in the path parameter. It supports both macOS (_NSGetExecutablePath) and Linux (/proc/self/exe).

Note
On macOS, _NSGetExecutablePath is used, and the buffer size is checked dynamically.
On Linux, the function reads from /proc/self/exe using readlink().
Warning
On macOS, if the buffer is too small, _NSGetExecutablePath may fail, this implementation does not handle resizing the buffer.
Here is the caller graph for this function:

◆ GetReleaseInformation()

std::string GetReleaseInformation ( )

Retrieves the operating system release information.

This function fetches OS release details using platform-specific methods:

  • On macOS, it runs the sw_vers command and reads the output.
  • On Linux/Unix, it attempts to read /etc/os-release, which is available on most distributions using systemd.
Note
  • On macOS, popen("sw_vers", "r") is used to execute sw_vers, which outputs OS version details.
  • On Linux, the function reads the /etc/os-release file into a string.
  • If an error occurs while reading the file, a warning is logged via spdlog::warn.
Warning
  • The function does not support Windows.
  • On macOS, buffer overflow protection is in place, but the buffer size is fixed.
Here is the caller graph for this function:

◆ OutputOfCommand()

std::string OutputOfCommand ( const char *  command)

Executes a shell command and returns its output.

This function opens a pipe using popen() to execute the given command, reads its output, and returns it as a std::string.

Note
  • The function trims trailing newline characters from the output.
  • The caller must ensure the command is safe to execute (avoid shell injection).
  • Works only on Unix-like systems.
Warning
  • If popen() fails, an error message is printed, and an empty string is returned.
  • The function does not handle command execution failures beyond detecting if popen() fails.
Here is the caller graph for this function: