26 #include <ContainerId.h>
37 #include <sys/types.h>
38 #include <sys/sysmacros.h>
80 virtual bool mkdirRecursive(
int dirFd,
const std::string& path, mode_t mode)
const = 0;
105 virtual bool rmdirRecursive(
int dirFd,
const std::string& path)
const = 0;
131 virtual bool rmdirContents(
int dirFd,
const std::string& path)
const = 0;
178 bool repair =
true)
const = 0;
202 const std::string& fsType =
"ext4")
const = 0;
221 const std::string& logTag = std::string())
const = 0;
244 const std::string& str,
245 int flags, mode_t mode = 0644)
const = 0;
246 virtual bool writeTextFileAt(
int dirFd,
const std::string& path,
247 const std::string& str,
248 int flags, mode_t mode = 0644)
const = 0;
269 size_t maxLen = 4096)
const = 0;
270 virtual std::string readTextFileAt(
int dirFd,
const std::string& path,
271 size_t maxLen = 4096)
const = 0;
327 template<
class Function >
348 template<
class Function,
class... Args >
349 inline bool callInNamespace(pid_t pid,
int nsType, Function&& f, Args&&... args)
const
352 std::forward<Args>(args)...));
380 template<
class Rep,
class Period >
381 inline int startTimer(
const std::chrono::duration<Rep, Period>& timeout,
383 const std::function<
bool()>& handler)
const
385 return this->
startTimerImpl(std::chrono::duration_cast<std::chrono::milliseconds>(timeout),
423 template<
class Function >
429 template<
class Function,
class... Args >
430 inline bool callInNamespace(
int namespaceFd, Function&& f, Args&&... args)
const
433 std::forward<Args>(args)...));
476 inline bool deviceAllowed(
unsigned int major,
unsigned int minor)
const
531 const std::function<
bool()>& handler)
const = 0;
543 virtual gid_t
getGID(pid_t pid)
const = 0;
555 virtual uid_t
getUID(pid_t pid)
const = 0;
580 using IDobbyUtils_v1::writeTextFileAt;
582 using IDobbyUtils_v1::readTextFileAt;
602 virtual int getIntegerMetaData(
const ContainerId &
id,
const std::string &key,
int defaultValue)
const = 0;
603 inline int getIntegerMetaData(
const ContainerId &
id,
const std::string &key)
605 return getIntegerMetaData(
id, key, -1);
618 virtual std::string getStringMetaData(
const ContainerId &
id,
const std::string &key,
const std::string &defaultValue)
const = 0;
619 inline std::string getStringMetaData(
const ContainerId &
id,
const std::string &key)
621 return getStringMetaData(
id, key, std::string());
623 virtual void clearContainerMetaData(
const ContainerId &
id) = 0;
647 using IDobbyUtils_v1::writeTextFileAt;
649 using IDobbyUtils_v1::readTextFileAt;
658 using IDobbyUtils_v2::getIntegerMetaData;
660 using IDobbyUtils_v2::getStringMetaData;
661 using IDobbyUtils_v2::clearContainerMetaData;
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition: ContainerId.h:41
Interface that exports some utilities that plugins may find useful.
Definition: IDobbyUtils.h:52
bool callInNamespace(int namespaceFd, Function func) const
Call the given function in the namespace of the descriptor.
Definition: IDobbyUtils.h:424
virtual bool formatExtImageFile(int dirFd, const std::string &imageFileName, const std::string &fsType="ext4") const =0
Runs the mke2fs tool to format a file system image.
int startTimer(const std::chrono::duration< Rep, Period > &timeout, bool oneShot, const std::function< bool()> &handler) const
Adds a new timer to the timer queue.
Definition: IDobbyUtils.h:381
virtual void cleanMountLostAndFound(const std::string &mountPoint, const std::string &logTag=std::string()) const =0
Logs and deletes any files found in the lost+found directory of the mount point.
virtual int loopDeviceAssociate(int fileFd, std::string *loopDevPath=nullptr) const =0
Associates a give file descriptor with a loop device.
virtual std::string readTextFile(const std::string &path, size_t maxLen=4096) const =0
Simply read a string from a file.
virtual bool mkdirRecursive(const std::string &path, mode_t mode) const =0
Makes a directory and all parent directories as needed.
virtual bool deviceAllowed(dev_t device) const =0
Returns true if the given device is allowed in the container.
virtual bool rmdirContents(const std::string &path) const =0
Removes the contents of a directory but leave the actual directory in place.
virtual bool rmdirRecursive(const std::string &path) const =0
Removes a directory and all it's contents.
virtual uid_t getUID(pid_t pid) const =0
Returns the UID for the given PID.
virtual gid_t getGID(pid_t pid) const =0
Returns the GID for the given PID.
virtual int getNamespaceFd(pid_t pid, int nsType) const =0
Returns a file descriptor to the given namespace of the process.
virtual unsigned int getDriverMajorNumber(const std::string &driverName) const =0
Returns the major number assigned to a given driver.
virtual bool callInNamespaceImpl(pid_t pid, int nsType, const std::function< bool()> &func) const =0
Implementation of the callInNamespace public interface.
virtual bool checkExtImageFile(int dirFd, const std::string &imageFileName, bool repair=true) const =0
Runs the e2fsck tool on a file system image to check it's integrity.
virtual int startTimerImpl(const std::chrono::milliseconds &timeout, bool oneShot, const std::function< bool()> &handler) const =0
Adds a new timer to the timer queue.
virtual bool cancelTimer(int timerId) const =0
Removes the given timer from the timer queue.
bool callInNamespace(pid_t pid, int nsType, Function func) const
Calls the given function in the namespace of given pid.
Definition: IDobbyUtils.h:328
virtual bool writeTextFile(const std::string &path, const std::string &str, int flags, mode_t mode=0644) const =0
Simply writes a string into a file.
virtual bool callInNamespaceImpl(int namespaceFd, const std::function< bool()> &func) const =0
Implementation of the callInNamespace public interface.
bool callInNamespace(pid_t pid, int nsType, Function &&f, Args &&... args) const
Slightly nicer version of callInNamespace, handles the function bind for you automatically.
Definition: IDobbyUtils.h:349
Second version of the interface containing extra functions for working with iptables.
Definition: IDobbyUtils.h:570
virtual void setIntegerMetaData(const ContainerId &id, const std::string &key, int value)=0
Sets / Gets integer meta data for the given container.
virtual void setStringMetaData(const ContainerId &id, const std::string &key, const std::string &value)=0
Sets / Gets string meta data for the given container.
Third version of the interface containing extra functions for working with ebtables.
Definition: IDobbyUtils.h:637
virtual bool deleteEbtablesRule(const std::string &args) const =0
Deletes the given ebtables rule from the existing set.
virtual bool insertEbtablesRule(const std::string &args) const =0
Inserts the given ebtables rule to the existing set.