NetlinkResponse send(const NetlinkMessage& msg, int pid)
{
- assert(msg.hdr().nlmsg_flags & NLM_F_ACK);
+ const auto &hdr = msg.hdr();
+ assert(hdr.nlmsg_flags & NLM_F_ACK);
std::unique_ptr<std::vector<char>> data;
Netlink nl;
nl.open(pid);
try {
- nl.send(&msg.hdr());
- data = nl.rcv(msg.hdr().nlmsg_seq);
+ nl.send(&hdr);
+ data = nl.rcv(hdr.nlmsg_seq);
} catch (const std::exception& ex) {
LOGE("Sending failed (" << ex.what() << ")");
nl.close();
#else // ENABLE_SAME_THREAD_GUARD
# define ASSERT_SAME_THREAD(g)
- bool check() {return true;}
- void reset() {}
+ static bool check() {return true;}
+ static void reset() {}
#endif // ENABLE_SAME_THREAD_GUARD
};
LOGT("Worker thread exited");
}
- void execute(const TaskInfo& taskInfo)
+ static void execute(const TaskInfo& taskInfo)
{
try {
LOGT("Executing task from subgroup " << taskInfo.groupID);
#define CONFIG_REGISTER_EMPTY \
template<typename Visitor> \
- void accept(Visitor ) { \
- } \
- template<typename Visitor> \
- void accept(Visitor ) const { \
+ static void accept(Visitor ) { \
} \
#define CONFIG_REGISTER(...) \
Connection::~Connection()
{
- if (::sqlite3_close(mDbPtr) != SQLITE_OK) {
- throw ConfigException("Error during closing the database. Error: " + getErrorMessage());
- }
+ ::sqlite3_close(mDbPtr);
}
void Connection::exec(const std::string& query)
}// config
-#endif //COMMON_CONFIG_TYPES_HPP
\ No newline at end of file
+#endif //COMMON_CONFIG_TYPES_HPP
Client::Client(epoll::EventPoll& eventPoll, const std::string& socketPath)
: mEventPoll(eventPoll),
+ mServiceID(-1),
mProcessor(eventPoll, "[CLIENT] "),
mSocketPath(socketPath)
{
FileDescriptor getEventFD();
private:
- typedef std::function<void(int fd, std::shared_ptr<void>& data)> SerializeCallback;
- typedef std::function<std::shared_ptr<void>(int fd)> ParseCallback;
typedef std::unique_lock<std::mutex> Lock;
typedef RequestQueue<Event>::Request Request;
struct RegisterSignalsProtocolMessage {
RegisterSignalsProtocolMessage() = default;
- RegisterSignalsProtocolMessage(const std::vector<MethodID> ids)
+ RegisterSignalsProtocolMessage(const std::vector<MethodID>& ids)
: ids(ids) {}
std::vector<MethodID> ids;
Socket Socket::createSocket(const std::string& path)
{
// Initialize a socket
- int fd = -1;
+ int fd;
#ifdef HAVE_SYSTEMD
fd = getSystemdSocketInternal(path);
+ if (fd == -1) {
+ fd = createSocketInternal(path);
+ }
+#else
+ fd = createSocketInternal(path);
#endif // HAVE_SYSTEMD
- fd = fd != -1 ? fd : createSocketInternal(path);
return Socket(fd);
}
const std::string& objectPath,
const std::string& interface,
const std::string& /* signalName */,
- GVariant* /* parameters */)
+ GVariant* /* parameters */) const
{
+ (void)this; // satisfy cpp-check
if (objectPath != api::dbus::OBJECT_PATH || interface != api::dbus::INTERFACE) {
return;
}
const std::string& objectPath,
const std::string& interface,
const std::string& signalName,
- GVariant* parameters);
+ GVariant* parameters) const;
};
size_t pos = addrAttr.find(":");
if (pos == string::npos || pos == addrAttr.length()) {
LOGE("Wrong input data format: ill formed address attribute: " << addrAttr);
- VasumException("Wrong input data format: ill formed address attribute");
+ throw VasumException("Wrong input data format: ill formed address attribute");
}
attrs.push_back(make_tuple(addrAttr.substr(0, pos), addrAttr.substr(pos + 1)));
}
throw UtilsException("Failed to hard link: path prefix is not valid");
}
-std::string ZoneProvision::getId(const ZoneProvisioningConfig::File& file) const
+std::string ZoneProvision::getId(const ZoneProvisioningConfig::File& file)
{
//TODO output of type,flags and mode should be more user friendly
return "file " +
std::to_string(file.mode);
}
-std::string ZoneProvision::getId(const ZoneProvisioningConfig::Mount& mount) const
+std::string ZoneProvision::getId(const ZoneProvisioningConfig::Mount& mount)
{
//TODO output of flags should be more user friendly
return "mount " +
mount.data;
}
-std::string ZoneProvision::getId(const ZoneProvisioningConfig::Link& link) const
+std::string ZoneProvision::getId(const ZoneProvisioningConfig::Link& link)
{
return "link " + link.source + " " + link.target;
}
-std::string ZoneProvision::getId(const ZoneProvisioningConfig::Provision& provision) const
+std::string ZoneProvision::getId(const ZoneProvisioningConfig::Provision& provision)
{
using namespace vasum;
if (provision.is<ZoneProvisioningConfig::File>()) {
void file(const ZoneProvisioningConfig::File& config);
void link(const ZoneProvisioningConfig::Link& config);
- std::string getId(const ZoneProvisioningConfig::File& file) const;
- std::string getId(const ZoneProvisioningConfig::Mount& mount) const;
- std::string getId(const ZoneProvisioningConfig::Link& link) const;
- std::string getId(const ZoneProvisioningConfig::Provision& provision) const;
+ static std::string getId(const ZoneProvisioningConfig::File& file);
+ static std::string getId(const ZoneProvisioningConfig::Mount& mount);
+ static std::string getId(const ZoneProvisioningConfig::Link& link);
+ static std::string getId(const ZoneProvisioningConfig::Provision& provision);
};
} // namespace vasum
}
Zone& zoneToFocus = get(iter);
- const std::string idToFocus = zoneToFocus.getId();
+ const std::string& idToFocus = zoneToFocus.getId();
if (idToFocus == mActiveZoneId) {
return;
--- /dev/null
+#!/bin/bash
+OPT=""
+OPT+=" --enable=all"
+OPT+=" --std=c++11"
+OPT+=" --inconclusive"
+OPT+=" --suppressions tests/cppcheck/cppcheck.suppress"
+OPT+=" --suppress=missingIncludeSystem"
+OPT+=" --inline-suppr"
+OPT+=" -iCMakeFiles"
+OPT+=" -I common"
+OPT+=" -I libs"
+OPT+=" -I client"
+OPT+=" -I server"
+OPT+=" -U__NR_capset"
+cppcheck ${OPT} --template=gcc ./ 1>/dev/null
--- /dev/null
+// public API functions (or write tests to use them all)
+unusedFunction:wrapper/wrapper-compatibility.cpp
+unusedFunction:wrapper/wrapper.cpp
+
+// lambda not recognized to catch exception (v1.68)
+exceptThrowInNoexecptFunction:client/vasum-client-impl.cpp
+
struct SubConfig {
struct SubSubConfig {
- int intVal;
- bool moved;
- CONFIG_REGISTER
- (
- intVal
- )
SubSubConfig() : intVal(), moved(false) {}
SubSubConfig(const SubSubConfig& config) : intVal(config.intVal), moved(false) {}
SubSubConfig(SubSubConfig&& config) : intVal(std::move(config.intVal)), moved(false) {
bool isMoved() const {
return moved;
}
+
+ int intVal;
+ bool moved;
+ CONFIG_REGISTER
+ (
+ intVal
+ )
};
int intVal;
struct ThrowOnAcceptData {
template<typename Visitor>
- void accept(Visitor)
+ static void accept(Visitor)
{
throw std::runtime_error("intentional failure in accept");
}
- template<typename Visitor>
- void accept(Visitor) const
- {
- throw std::runtime_error("intentional failure in accept const");
- }
};
void returnEmptyCallback(const PeerID,
cleanup();
}
- void cleanup()
+ static void cleanup()
{
LxcZone lxc(ZONE_PATH, ZONE_NAME);
if (lxc.isDefined()) {
}
}
- void waitForInit()
+ static void waitForInit()
{
// wait for init fully started (wait for bash to be able to trap SIGTERM)
std::this_thread::sleep_for(std::chrono::milliseconds(200));
LOGI("------------ setup complete -----------");
}
- void prepare()
+ static void prepare()
{
ScopedGlibLoop loop;
ipc::epoll::ThreadDispatcher mDispatcher;
BOOST_REQUIRE(utils::saveFileContent(SOME_FILE_PATH.string(), "text"));
}
- ZoneProvision create(const std::vector<std::string>& validLinkPrefixes)
+ static ZoneProvision create(const std::vector<std::string>& validLinkPrefixes)
{
return ZoneProvision(ROOTFS_PATH.string(),
TEST_CONFIG_PATH,
validLinkPrefixes);
}
- void load(ZoneProvisioningConfig& config)
+ static void load(ZoneProvisioningConfig& config)
{
config::loadFromKVStoreWithJsonFile(DB_PATH.string(), TEST_CONFIG_PATH, config, DB_PREFIX);
}
- void save(const ZoneProvisioningConfig& config)
+ static void save(const ZoneProvisioningConfig& config)
{
config::saveToKVStore(DB_PATH.string(), config, DB_PREFIX);
}
}
- void ensureStarted()
+ static void ensureStarted()
{
// wait for zones init to fully start
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
- void ensureStop()
+ static void ensureStop()
{
// wait for fully stop
std::this_thread::sleep_for(std::chrono::milliseconds(200));
API vsm_fso_type_t fso_string_to_type(char *str)
{
LOGS("");
- int len;
int i;
for (i = 0; i <= VSM_FSO_MAX_TYPE; i++) {
- len = strlen(fso_type_strtab[i]);
+ int len = strlen(fso_type_strtab[i]);
if (strncmp(str, fso_type_strtab[i], len) == 0)
return static_cast<vsm_fso_type_t>(i);
}
LOGS("");
const char *tmp = dir;
const char *orig = dir;
- char *makeme;
do {
dir = tmp + strspn(tmp, "/");
tmp = dir + strcspn(dir, "/");
- makeme = strndup(orig, dir - orig);
+ char *makeme = strndup(orig, dir - orig);
if (*makeme) {
if (mkdir(makeme, mode) && errno != EEXIST) {
free(makeme);
{
LOGS("");
struct stat path_stat;
- DIR *dp;
- struct dirent *d;
int status = 0;
if (lstat(path, &path_stat) < 0) {
}
if (S_ISDIR(path_stat.st_mode)) {
+ struct dirent *d;
+ DIR *dp;
if ((dp = opendir(path)) == NULL) {
ERROR("Unable to opendir %s", path);
return -1;
LOGS("");
int ret;
FILE *sfp, *dfp;
- size_t nread, nwritten, size = BUF_SIZE;
char buffer[BUF_SIZE];
if ((sfp = fopen(source, "r")) == NULL) {
}
while (1) {
+ size_t nread, nwritten, size = BUF_SIZE;
nread = fread(buffer, 1, size, sfp);
if (nread != size && ferror(sfp)) {
fp = fopen(filename, "r");
if (fp != NULL) {
- if (fscanf(fp, "%d", &ret) < 0) {
+ if (fscanf(fp, "%7d", &ret) < 0) {
ERROR("Failed to read %s\n", filename);
ret = -2;
}
FILE *cmdfp;
char cmdpath[PATH_MAX];
- res = sscanf(line, "%d", &pid);
+ res = sscanf(line, "%7d", &pid);
if (res != 1) {
ERROR("Failed to read %s\n", path);
res = -1;
continue;
}
- if (fscanf(cmdfp, "%s", cmd) < 0) {
+ if (fscanf(cmdfp, "%1023s", cmd) < 0) {
ERROR("Failed to read cmdline - pid : %d\n", pid);
continue;
}
{
struct parser_state state;
char *args[PARSER_MAXARGS];
- int i, nargs, done, rc;
+ int i;
int ret = 0;
UNUSED(ctx);
for (i = 0; i < argc; i++) {
+ int nargs, done, rc;
done = nargs = 0;
parser_init_state(&state, argv[i]);
{
}
-void Daemon::onNameLostCallback()
+void Daemon::onNameLostCallback() const
{
+ (void)this; // satisfy cpp-check
//TODO: Try to reconnect or close the daemon.
LOGE("Dbus name lost");
}
-void Daemon::onGainFocusCallback()
+void Daemon::onGainFocusCallback() const
{
+ (void)this; // satisfy cpp-check
LOGD("Gained Focus");
}
-void Daemon::onLoseFocusCallback()
+void Daemon::onLoseFocusCallback() const
{
+ (void)this; // satisfy cpp-check
LOGD("Lost Focus");
-
}
} // namespace zone_daemon
virtual ~Daemon();
private:
- void onNameLostCallback();
- void onGainFocusCallback();
- void onLoseFocusCallback();
+ void onNameLostCallback() const;
+ void onGainFocusCallback() const;
+ void onLoseFocusCallback() const;
std::unique_ptr<DaemonConnection> mConnectionPtr;
};
/**
* Starts all the daemon and blocks until SIGINT or SIGTERM
*/
- void run();
+ static void run();
/**
* Terminates the daemon.
* Equivalent of sending SIGINT or SIGTERM signal
*/
- void terminate();
+ static void terminate();
};