softwarecontainer  0.18.0-739e8d7 2017-05-04
softwarecontainer Namespace Reference

Developers guide to adding a config item: More...

Data Structures

class  BadSuffixError
 
class  BaseConfigStore
 
class  BoolConfig
 Represents a config item of type bool. More...
 
class  CapabilityParseError
 An error occured in ConfigStore when parsing a Capability in a Service Manifest. More...
 
class  CgroupsGateway
 The cgroups gateway sets cgroups related settings for the container. More...
 
class  CgroupsGatewayError
 
class  CGroupsParser
 
class  CleanUpHandler
 
class  CommandJob
 Use this class to execute a command line in a SoftwareContainer. More...
 
class  CommandlineConfigSource
 A config source representing the commandline options. More...
 
class  Config
 Represents the configuration of SoftwareContainer (the component) More...
 
class  ConfigDefinition
 
class  ConfigDependencyError
 
class  ConfigError
 
class  ConfigFileError
 An error occured in a Glib operation. More...
 
class  ConfigInternalError
 An error occured which is an internal error in the config code. More...
 
class  ConfigItem
 Base class for all config item types. More...
 
class  ConfigLoader
 
class  ConfigMandatoryError
 
class  ConfigNotFoundError
 A requested config item could not be found in any of the config sources. More...
 
class  ConfigSource
 Base class for all config sources. More...
 
class  ConfigStoreError
 
class  ConfigTypes
 
class  ConfigUnknownError
 A config is found which is not defined in ConfigDefinition. More...
 
class  Container
 The Container class is an abstraction of the specific containment technology used. More...
 
class  ContainerAbstractInterface
 
class  ContainerError
 An error has occured in the underlying container implementation. More...
 
class  ContainerOptionParseError
 
class  ContainerOptionParser
 
class  ContainerUtilityInterface
 
class  ContainerUtilityInterfaceError
 An error occured in ContainerUtilityInterface. More...
 
class  CreateDir
 The CreateDir class is responsible for creating new directories and removing them when it is necessary. More...
 
class  DBusGateway
 
class  DBusGatewayInstance
 DBus Gateway takes care of spawning and killing the DBus proxies. More...
 
class  DBusGatewayParser
 
class  DefaultConfigSource
 Represents the default config values. More...
 
class  DefaultConfigStore
 
class  Device
 
class  DeviceNodeGateway
 This gateway is responsible for exposing device nodes in an LXC container. More...
 
class  DeviceNodeGatewayError
 
class  DeviceNodeLogic
 This class is responsible for storing all device node configurations in a well-formed list. More...
 
class  DirectoryCleanUpHandler
 
class  DynamicContainerOptions
 
class  EnvironmentGateway
 Environment Gateway is used to define environment variables to the container. More...
 
class  EnvironmentGatewayParser
 
class  Executable
 
class  FileCleanUpHandler
 The FileCleanUpHandler class is a subclass of CleanUpHandler that deletes a file. More...
 
class  FileConfigLoader
 
class  FileGateway
 This gateway lets you map files (including socket files) or folders from the host into the container's filesystem. More...
 
class  FileGatewayParser
 
class  FileGatewaySettingStore
 
class  FileToolkitWithUndo
 
class  FilteredConfigStore
 
class  FunctionJob
 Run a C++ function lambda inside a SoftwareContainer. More...
 
class  Gateway
 Gateway base class for SoftwareContainer. More...
 
class  GatewayConfiguration
 
class  GatewayError
 
class  GatewayParserError
 
class  IntConfig
 Represents a config item of type int. More...
 
class  InvalidContainerError
 The container instance is in an invalid state and should not be used. More...
 
class  InvalidInputError
 
class  InvalidOperationError
 A method was called which is inappropriate in the current state. More...
 
class  IPAllocationError
 
class  IPTableEntry
 A rules entry for the treatment of packets. More...
 
class  JobAbstract
 Abstract class for jobs which get executed inside a container. More...
 
class  JSonError
 
class  JSONParser
 Convenience layer for the Jansson JSON parser. More...
 
class  LimitRangeError
 
class  MainConfigSource
 
class  MountCleanUpHandler
 
class  Netlink
 Handles various network operations over netlink. More...
 
class  NetworkGateway
 Sets up and manages network access and routing to the container. More...
 
class  NetworkGatewayError
 
class  NetworkGatewayFunctions
 Sets up and manages network access and routing to the container. More...
 
class  NetworkGatewayParser
 
class  OverlaySyncCleanupHandler
 The OverlaySyncCleanupHandler class is used to copy files on cleanup and can be added to the CleanupHandler stack in the FileToolkitWithUndo class. More...
 
class  PulseGateway
 The PulseAudio Gateway is used to provide access to the host system PulseAudio server. More...
 
class  RecursiveCopy
 The RecursiveCopy class is a singleton class used to copy files recursively from a source to a destination. More...
 
class  RecursiveDelete
 The RecursiveDelete class is a singleton class used to delete files recursively in a directory. More...
 
class  ServiceManifestFileLoader
 
class  ServiceManifestLoader
 Base class used for creating a service manifest loader. More...
 
class  ServiceManifestParseError
 An error occured in ConfigStore when parsing a Service Manifest. More...
 
class  ServiceManifestPathError
 An error occured in ConfigStore relating to the path to the Service Manifest(s) More...
 
class  SignalConnectionsHandler
 The SignalConnectionsHandler class contains references to sigc++ connections and automatically disconnects them on destruction. More...
 
class  SoftwareContainer
 An abstraction of concrete container implementations. More...
 
class  SoftwareContainerAbstractInterface
 
class  SoftwareContainerAgent
 
class  SoftwareContainerAgentAdaptor
 
class  SoftwareContainerAgentError
 An error occured in SoftwareContainerAgent. More...
 
class  SoftwareContainerConfig
 Contains all values that should be passed to SoftwareContainer on creation. More...
 
class  SoftwareContainerError
 
class  SoftwareContainerFactory
 
class  StringConfig
 Represents a config item of type string. More...
 
class  WaylandGateway
 

Typedefs

typedef std::vector< std::tuple< std::string, std::string, ConfigType, MandatoryFlag > > ConfigItems
 
typedef std::pair< std::string, std::string > UniqueKey
 
typedef std::vector< UniqueKey > MandatoryConfigs
 
typedef std::map< UniqueKey, std::vector< UniqueKey > > ConfigDependencies
 
typedef std::map< UniqueKey, ConfigTypeTypeMap
 
typedef bool MandatoryFlag
 
typedef int32_t ContainerID
 
typedef std::map< std::string, std::string > EnvironmentVariables
 
typedef logging::DefaultLogContext LogContext
 

Enumerations

enum  ConfigType { String, Integer, Boolean }
 Represents the type of a config value. More...
 
enum  ConfigSourceType { Commandline, Main, Default }
 
enum  ContainerState { READY, SUSPENDED, TERMINATED, INVALID }
 

Functions

 LOG_DEFINE_APP_IDS ("SCAG","SoftwareContainer agent")
 
 LOG_DECLARE_DEFAULT_CONTEXT (PAM_DefaultLogContext,"MAIN","Main context")
 
int copyFile (const char *, const struct stat, int)
 
int copyFile (const char *srcPath, const struct stat *sb, int typeflag)
 copy_file Copy files from src_path to dst_root global path More...
 
int deleteFile (const char *, const struct stat, int, struct FTW *ftwbuf)
 
int deleteFile (const char *deletePath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
 deleteFile Delete files from the directory More...
 
void addProcessListener (SignalConnectionsHandler &connections, pid_t pid, std::function< void(pid_t, int)> function, Glib::RefPtr< Glib::MainContext > context)
 addProcessListener Adds a glib child watch for a process. More...
 
 LOG_DECLARE_DEFAULT_CONTEXT (defaultLogContext,"MAIN","Main context")
 
bool getStat (const std::string &path, struct stat &st)
 
bool isDirectory (const std::string &path)
 isDirectory Check if path is a directory More...
 
bool isDirectoryEmpty (const std::string &path)
 isDirectoryEmpty Check if path is empty More...
 
bool isFile (const std::string &path)
 isFile Check if path is a file More...
 
bool isPipe (const std::string &path)
 isPipe Check if path is a pipe More...
 
bool isSocket (const std::string &path)
 isSocket Check if path is a socket More...
 
bool existsInFileSystem (const std::string &path)
 existsInFileSystem Check if path exists More...
 
std::string parentPath (const std::string &path_)
 
std::string baseName (const std::string &path)
 
std::string buildPath (const std::string &arg1, const std::string &arg2)
 
std::string buildPath (const std::string &arg1, const std::string &arg2, const std::string &arg3)
 
bool touch (const std::string &path)
 
bool writeToFile (const std::string &path, const std::string &content)
 
bool readFromFile (const std::string &path, std::string &content)
 
bool parseInt (const char *arg, int *result)
 
int waitForProcessTermination (pid_t pid)
 waitForProcessTermination Waits for a process to terminate and then returns the status of the process terminating. More...
 

Variables

const MandatoryFlag Mandatory
 
const MandatoryFlag Optional
 
const int ITEM_INDEX_GROUP
 
const int ITEM_INDEX_KEY
 
const int ITEM_INDEX_TYPE
 
const int ITEM_INDEX_MANDATORY
 
const ConfigItems CONFIGS
 
static constexpr ContainerID INVALID_CONTAINER_ID
 
std::string dstRoot
 
std::string srcRoot
 
static constexpr pid_t INVALID_PID
 
static constexpr int INVALID_FD
 
static constexpr uid_t ROOT_UID
 
static constexpr const char * LXC_CONTAINERS_ROOT_CONFIG_ITEM
 

Detailed Description

Developers guide to adding a config item:

  • Add a definition of the string used as key
  • If the config will be possible to set with a command line option, also add an "intial value" set to something which is possible to use for testing if the user set it, i.e. an "impossible" value.
  • Add an entry for the config to the CONFIGS data

Enumeration Type Documentation

Represents the type of a config value.

This is used to specify the type of the a value when mandatory configs are defined. This information is later used to know how a key should be used to retrive a value, e.g. what type specific methods can be used.

Definition at line 32 of file configtypes.h.

33 {
34  String,
35  Integer,
36  Boolean
37 };

Function Documentation

int softwarecontainer::copyFile ( const char *  srcPath,
const struct stat *  sb,
int  typeflag 
)

copy_file Copy files from src_path to dst_root global path

This function is wrapped and hidden in this separate code unit because of it's side effects and used by the RecursiveCopy::copy() function.

Parameters
src_pathThe path of the file to copy
sbnot used in this function
typeflagPoints to what type of node is traversed by ftw(). Uses the global variables dst_root and src_root to know the root directories being copied to and from. These must not be changed while ftw is running or the function will misbehave.
Returns
always 0 for now.

Definition at line 49 of file recursivecopy.cpp.

50 {
51  std::string dstPath;
52  std::string src(srcPath);
53 
54  if (src.find(srcRoot) != std::string::npos) {
55  dstPath = buildPath(dstRoot, src.erase(0, srcRoot.length()));
56  } else {
57  dstPath = buildPath(dstRoot, src);
58  }
59 
60  switch(typeflag) {
61  case FTW_D:
62  mkdir(dstPath.c_str(), sb->st_mode);
63  break;
64  case FTW_F:
65  std::ifstream src(srcPath, std::ios::binary);
66  std::ofstream dst(dstPath, std::ios::binary);
67  dst << src.rdbuf();
68  }
69  return 0;
70 }
int softwarecontainer::deleteFile ( const char *  deletePath,
const struct stat *  sb,
int  typeflag,
struct FTW *  ftwbuf 
)

deleteFile Delete files from the directory

Parameters
deletePathThe path of the file to delete
sbnot used in this function
typeflagPoints to what type of node is traversed by ftw().
Returns
always 0 for now.

Definition at line 41 of file recursivedelete.cpp.

42 {
43  (void)sb;
44  (void)typeflag;
45  (void)ftwbuf;
46 
47  remove(deletePath);
48  return 0;
49 }
void softwarecontainer::addProcessListener ( SignalConnectionsHandler connections,
pid_t  pid,
std::function< void(pid_t, int)>  function,
Glib::RefPtr< Glib::MainContext >  context 
)
inline

addProcessListener Adds a glib child watch for a process.

Warning
This is not thread safe!
Parameters
connectionsAdd the signal to this list of connections
pidThe pid to watch for.
functionA lambda/function pointer to run when the signal is sent for a process.
contextglib context to attach the SignalChildWatch to.

Definition at line 58 of file signalconnectionshandler.h.

References softwarecontainer::SignalConnectionsHandler::addConnection().

Referenced by softwarecontainer::SoftwareContainerAgent::execute().

63 {
64  Glib::SignalChildWatch watch = context->signal_child_watch();
65  auto connection = watch.connect(function, pid);
66  connections.addConnection(connection);
67 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool softwarecontainer::isDirectory ( const std::string &  path)

isDirectory Check if path is a directory

Parameters
pathPath to check
Returns
true/false

Definition at line 43 of file softwarecontainer-common.cpp.

Referenced by softwarecontainer::FileToolkitWithUndo::bindMount(), softwarecontainer::Container::bindMountInContainer(), softwarecontainer::ContainerUtilityInterface::checkWorkspace(), softwarecontainer::CreateDir::createDirectory(), softwarecontainer::ServiceManifestFileLoader::loadContent(), softwarecontainer::SoftwareContainer::previouslyConfigured(), and waitForProcessTermination().

44 {
45  struct stat st;
46  if (getStat(path, st)) {
47  return S_ISDIR(st.st_mode);
48  }
49 
50  return false;
51 }

Here is the caller graph for this function:

bool softwarecontainer::isDirectoryEmpty ( const std::string &  path)

isDirectoryEmpty Check if path is empty

Parameters
pathThe path to check
Returns
false if the directory is not empty
false if the directory does not exist
true if the directory is empty

Definition at line 53 of file softwarecontainer-common.cpp.

Referenced by softwarecontainer::ServiceManifestFileLoader::loadContent(), softwarecontainer::SoftwareContainer::previouslyConfigured(), softwarecontainer::FileToolkitWithUndo::tmpfsMount(), and waitForProcessTermination().

53  {
54  int n = 0;
55  constexpr int EMPTY_DIR_SIZE=2;
56  struct dirent *d;
57  DIR *dir = opendir(path.c_str());
58  if (dir == NULL) { //Not a directory or doesn't exist
59  return true;
60  }
61  while ((d = readdir(dir)) != NULL) {
62  ++n;
63  if(n > EMPTY_DIR_SIZE) {
64  break;
65  }
66  }
67  closedir(dir);
68  if (n <= EMPTY_DIR_SIZE) { //Directory Empty
69  return true;
70  } else {
71  return false;
72  }
73 }

Here is the caller graph for this function:

bool softwarecontainer::isFile ( const std::string &  path)

isFile Check if path is a file

Parameters
pathPath to check
Returns
true/false

Definition at line 75 of file softwarecontainer-common.cpp.

Referenced by softwarecontainer::ServiceManifestFileLoader::loadContent(), and waitForProcessTermination().

76 {
77  struct stat st;
78  if (getStat(path, st)) {
79  return S_ISREG(st.st_mode);
80  }
81 
82  return false;
83 }

Here is the caller graph for this function:

bool softwarecontainer::isPipe ( const std::string &  path)

isPipe Check if path is a pipe

Parameters
pathPath to check
Returns
true/false

Definition at line 85 of file softwarecontainer-common.cpp.

Referenced by waitForProcessTermination().

86 {
87  struct stat st;
88  if (getStat(path, st)) {
89  return S_ISFIFO(st.st_mode);
90  }
91 
92  return false;
93 }

Here is the caller graph for this function:

bool softwarecontainer::isSocket ( const std::string &  path)

isSocket Check if path is a socket

Parameters
pathPath to check
Returns
true/false

Definition at line 95 of file softwarecontainer-common.cpp.

Referenced by waitForProcessTermination().

96 {
97  struct stat st;
98  if (getStat(path, st)) {
99  return S_ISSOCK(st.st_mode);
100  }
101 
102  return false;
103 }

Here is the caller graph for this function:

bool softwarecontainer::existsInFileSystem ( const std::string &  path)

existsInFileSystem Check if path exists

Parameters
pathPath to check
Returns
true/false

Definition at line 105 of file softwarecontainer-common.cpp.

Referenced by softwarecontainer::FileToolkitWithUndo::bindMount(), softwarecontainer::Container::bindMountInContainer(), and waitForProcessTermination().

106 {
107  struct stat st;
108  return getStat(path, st);
109 }

Here is the caller graph for this function:

int softwarecontainer::waitForProcessTermination ( pid_t  pid)
inline

waitForProcessTermination Waits for a process to terminate and then returns the status of the process terminating.

Parameters
pidthe process id to wait for.
Returns
Process termination status.

Definition at line 45 of file softwarecontainer-common.h.

References existsInFileSystem(), isDirectory(), isDirectoryEmpty(), isFile(), isPipe(), and isSocket().

Referenced by softwarecontainer::Container::executeSync().

46 {
47  int status = 0;
48  waitpid(pid, &status, 0);
49  return WEXITSTATUS(status);
50 }

Here is the call graph for this function:

Here is the caller graph for this function: