SB++
Sandbox applications
Loading...
Searching...
No Matches
shared Namespace Reference

Shared functionality. More...

Data Structures

class  TemporaryDirectory
 A Temporary Directory A directory that destroys itself upon falling out of scope. More...
 

Typedefs

using set = std::set<std::string>
 
using vector = std::vector<std::string>
 
using list = std::initializer_list<std::string_view>
 

Functions

void log (const list &msg, const std::string &level="log")
 Log output to console, if verbose.
 
bool contains (const char &v, const char &d)
 
bool contains (const char &v, const std::string_view &d)
 
void emplace (std::set< std::string > &working, const std::string_view &val)
 
void emplace (std::vector< std::string > &working, const std::string_view &val)
 
template<class T>
std::string join (const T &list, const char &joiner=' ')
 Join a vector into a string.
 
template std::string join (const list &, const char &)
 
template std::string join (const vector &, const char &)
 
template std::string join (const set &, const char &)
 
template<typename T>
std::string strip (const std::string_view &in, const T &to_strip)
 Strip all instance of character from a string.
 
template std::string strip (const std::string_view &, const char &)
 
template std::string strip (const std::string_view &, const std::string_view &)
 
template<typename T>
std::string trim (const std::string &in, const T &to_strip)
 Trim characters from the front and end of a string.
 
template std::string trim (const std::string &, const char &)
 
template std::string trim (const std::string &, const std::string_view &)
 
set wildcard (const std::string_view &pattern, const std::string_view &path, const list &args={})
 Resolve wildcard patterns.
 
void genv (vector &command, const std::string_view &env)
 Attach an environment variable to the sandbox.
 
template<class T>
void extend (vector &dest, T source)
 Extend a container in place.
 
template void extend (vector &, list)
 
template void extend (vector &, vector)
 
template void extend (vector &, set)
 
template<class T>
void extend (set &dest, const T source)
 
template void extend (set &, const list)
 
template void extend (set &, const vector)
 
void extend (set &dest, set source)
 
void inotify_wait (const int &wd, const std::string_view &name="")
 Wait for an inotify watcher.
 
void share (vector &command, const std::string_view &path, const std::string &mode="ro-bind")
 Share a path with the sandbox using a mode.
 
std::string hash (const std::string_view &in)
 Hash a string.
 
std::string escape (const std::string &in)
 Escape a string.
 
void merge (set &command, set path)
 Merge two sets together.
 
template<class T, class A, class L = list, class ... Args>
void single_batch (const A &fun, T &accum, const L &mem, Args &&... args)
 Batch multiple iterations of an accumulator function together.
 
template<class T, class A, class L = list, class ... Args>
void batch (const A &fun, T &accum, const L &mem, Args &&... args)
 Batch multiple iterations of an accumulator function together, threaded.
 
void extend (vector &dest, const std::initializer_list< const list > &source)
 Batch multiple extend calls into the thread pool.
 

Variables

BS::thread_pool< BS::tp::wait_deadlock_checks > pool = {}
 
int inotify = -1
 
const std::string home = std::getenv("HOME")
 
const std::string runtime = std::getenv("XDG_RUNTIME_DIR")
 
const std::string session = std::getenv("DBUS_SESSION_BUS_ADDRESS")
 
const std::string config = std::getenv("XDG_CONFIG_HOME") == nullptr ? home + "/.config/" : std::getenv("XDG_CONFIG_HOME")
 
const std::string cache = std::getenv("XDG_CACHE_HOME") == nullptr ? home + "/.cache/" : std::getenv("XDG_CACHE_HOME")
 
const std::string data = std::getenv("XDG_DATA_HOME") == nullptr ? home + "/.local/share/" : std::getenv("XDG_DATA_HOME")
 
const std::string nobody = std::to_string(getpwnam("nobody")->pw_uid)
 
const std::string real = std::to_string(getuid())
 
std::filesystem::path data_dir = std::filesystem::path(data) / "sb"
 
std::filesystem::path app_data = ""
 

Detailed Description

Shared functionality.

Function Documentation

◆ batch()

template<class T, class A, class L = list, class ... Args>
void shared::batch ( const A & fun,
T & accum,
const L & mem,
Args &&... args )

Batch multiple iterations of an accumulator function together, threaded.

Template Parameters
TThe accumulator type.
AThe function type
LThe container holding each value.
...ArgsAdditional arguments.
Parameters
funThe function to call.
accumThe accumulator to append to.
memThe list of values to emplace.
argsAdditional arguments.
Warning
All arguments must be immutable, as instances are threaded together. If the ordering matters, or residue arguments are accumulators, use single_batch
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ escape()

std::string shared::escape ( const std::string & in)

Escape a string.

Parameters
inThe string to escape.
Returns
: The escaped string.

◆ extend() [1/2]

void shared::extend ( vector & dest,
const std::initializer_list< const list > & source )

Batch multiple extend calls into the thread pool.

Template Parameters
TThe list type.
Parameters
destThe accumulator.
sourceA list of lists that need to be extended.

◆ extend() [2/2]

template<class T>
void shared::extend ( vector & dest,
T source )

Extend a container in place.

Template Parameters
TThe container type for both dest and source.
Parameters
destThe container to extend.
sourceThe values to pull from.
+ Here is the caller graph for this function:

◆ genv()

void shared::genv ( vector & command,
const std::string_view & env )

Attach an environment variable to the sandbox.

Parameters
commandThe command to append to.
envThe environment variable to add.
Note
: The value of the variable is the actual value.
+ Here is the call graph for this function:

◆ hash()

std::string shared::hash ( const std::string_view & in)

Hash a string.

Parameters
inThe input string.
Returns
The hex digest.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inotify_wait()

void shared::inotify_wait ( const int & wd,
const std::string_view & name = "" )

Wait for an inotify watcher.

Parameters
wdThe inotify FD for a specific watch.
nameThe optional name to look out for.

◆ join()

template<class T>
std::string shared::join ( const T & list,
const char & joiner = ' ' )

Join a vector into a string.

Template Parameters
Thecontainer. Defaults to vector of strings, but can also be set.
Parameters
listThe list to join.
joinerThe character to join each member.
Returns
: The joined string.
+ Here is the caller graph for this function:

◆ log()

void shared::log ( const list & msg,
const std::string & level = "log" )

Log output to console, if verbose.

Parameters
msgA list of strings to be printed.
+ Here is the caller graph for this function:

◆ merge()

void shared::merge ( set & command,
set path )

Merge two sets together.

Parameters
commandThe set to be extended.
pathThe set to merge into the first.
Note
This function exists because C++ cannot deduce bracket initializers.

◆ share()

void shared::share ( vector & command,
const std::string_view & path,
const std::string & mode = "ro-bind" )

Share a path with the sandbox using a mode.

Parameters
commandThe command to append to.
pathThe path to share.
modeThe mode to use to share.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ single_batch()

template<class T, class A, class L = list, class ... Args>
void shared::single_batch ( const A & fun,
T & accum,
const L & mem,
Args &&... args )

Batch multiple iterations of an accumulator function together.

Template Parameters
TThe accumulator type.
AThe function type.
LThe container holding each value.
...ArgsAdditional arguments.
Parameters
funThe function to call
accumThe accumulator passed to the function.
memThe list of values to emplace.
argsAdditional arguments.
+ Here is the caller graph for this function:

◆ strip()

template<typename T>
std::string shared::strip ( const std::string_view & in,
const T & to_strip )

Strip all instance of character from a string.

Parameters
inThe input string.
to_stripA list of characters to remove
Returns
The stripped string.
+ Here is the caller graph for this function:

◆ trim()

template<typename T>
std::string shared::trim ( const std::string & in,
const T & to_strip )

Trim characters from the front and end of a string.

Parameters
inThe input string.
to_stripThe list of characters to trim.
Returns
The trimmed string.
Note
trim only removes from the front and end, stopping after encountered a non-to_strip character, whereas strip removes all instances regardless.
+ Here is the caller graph for this function:

◆ wildcard()

set shared::wildcard ( const std::string_view & pattern,
const std::string_view & path,
const list & args = {} )

Resolve wildcard patterns.

Parameters
patternThe pattern to resolve
pathThe path to look in
argsAny additional arguments to find.
Returns
: All unique matches.
+ Here is the caller graph for this function: