more C++-izations over places
authorRobert Swiecki <robert@swiecki.net>
Sat, 28 Apr 2018 23:10:09 +0000 (01:10 +0200)
committerRobert Swiecki <robert@swiecki.net>
Sat, 28 Apr 2018 23:10:09 +0000 (01:10 +0200)
caps.cc
subproc.cc

diff --git a/caps.cc b/caps.cc
index 53723a0..878465f 100644 (file)
--- a/caps.cc
+++ b/caps.cc
@@ -83,9 +83,9 @@ static struct {
 };
 
 int nameToVal(const char* name) {
-       for (size_t i = 0; i < ARR_SZ(capNames); i++) {
-               if (strcmp(name, capNames[i].name) == 0) {
-                       return capNames[i].val;
+       for (const auto& cap : capNames) {
+               if (strcmp(name, cap.name) == 0) {
+                       return cap.val;
                }
        }
        LOG_W("Uknown capability: '%s'", name);
@@ -93,13 +93,13 @@ int nameToVal(const char* name) {
 }
 
 static const std::string capToStr(int val) {
-       std::string res;
-       for (size_t i = 0; i < ARR_SZ(capNames); i++) {
-               if (val == capNames[i].val) {
-                       return capNames[i].name;
+       for (const auto& cap : capNames) {
+               if (val == cap.val) {
+                       return cap.name;
                }
        }
 
+       std::string res;
        res.append("CAP_UNKNOWN(");
        res.append(std::to_string(val));
        res.append(")");
index 3b49c79..3935381 100644 (file)
@@ -92,12 +92,12 @@ static const std::string cloneFlagsToStr(uintptr_t flags) {
        };
 
        uintptr_t knownFlagMask = CSIGNAL;
-       for (size_t i = 0; i < ARR_SZ(cloneFlags); i++) {
-               if (flags & cloneFlags[i].flag) {
-                       res.append(cloneFlags[i].name);
+       for (const auto& f : cloneFlags) {
+               if (flags & f.flag) {
+                       res.append(f.name);
                        res.append("|");
                }
-               knownFlagMask |= cloneFlags[i].flag;
+               knownFlagMask |= f.flag;
        }
 
        if (flags & ~(knownFlagMask)) {
@@ -112,9 +112,9 @@ static const std::string cloneFlagsToStr(uintptr_t flags) {
 /* Reset the execution environment for the new process */
 static bool resetEnv(void) {
        /* Set all previously changed signals to their default behavior */
-       for (size_t i = 0; i < ARR_SZ(nssigs); i++) {
-               if (signal(nssigs[i], SIG_DFL) == SIG_ERR) {
-                       PLOG_W("signal(%s, SIG_DFL)", util::sigName(nssigs[i]).c_str());
+       for (const auto& sig : nssigs) {
+               if (signal(sig, SIG_DFL) == SIG_ERR) {
+                       PLOG_W("signal(%s, SIG_DFL)", util::sigName(sig).c_str());
                        return false;
                }
        }
@@ -221,6 +221,7 @@ static void removeProc(nsjconf_t* nsjconf, pid_t pid) {
                            p->remote_txt.c_str(), util::timeToStr(p->start).c_str());
                        close(p->pid_syscall_fd);
                        nsjconf->pids.erase(p);
+
                        return;
                }
        }