From: Robert Swiecki Date: Tue, 1 Jan 2019 10:36:02 +0000 (+0100) Subject: More of RETURN_ON_FAILURE X-Git-Tag: 2.9~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a4315f31808ed6da95f4c7b33cb7f7dc4ced69d;p=platform%2Fupstream%2Fnsjail.git More of RETURN_ON_FAILURE --- diff --git a/Makefile b/Makefile index 105fc96..e318820 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ cmdline.o: util.h config.o: caps.h nsjail.h cmdline.h config.h config.pb.h logs.h macros.h config.o: mnt.h user.h util.h contain.o: contain.h nsjail.h caps.h cgroup.h cpu.h logs.h macros.h mnt.h -contain.o: net.h pid.h user.h uts.h +contain.o: net.h pid.h user.h util.h uts.h cpu.o: cpu.h nsjail.h logs.h util.h logs.o: logs.h macros.h util.h nsjail.h mnt.o: mnt.h nsjail.h logs.h macros.h subproc.h util.h diff --git a/contain.cc b/contain.cc index 18c43d4..176f216 100644 --- a/contain.cc +++ b/contain.cc @@ -48,6 +48,7 @@ #include "net.h" #include "pid.h" #include "user.h" +#include "util.h" #include "uts.h" namespace contain { @@ -294,41 +295,21 @@ bool setupFD(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err) { } bool containProc(nsjconf_t* nsjconf) { - if (!containUserNs(nsjconf)) { - return false; - } - if (!containInitPidNs(nsjconf)) { - return false; - } - if (!containInitMountNs(nsjconf)) { - return false; - } - if (!containInitNetNs(nsjconf)) { - return false; - } - if (!containInitUtsNs(nsjconf)) { - return false; - } - if (!containInitCgroupNs()) { - return false; - } - if (!containDropPrivs(nsjconf)) { - return false; - } + RETURN_ON_FAILURE(containUserNs(nsjconf)); + RETURN_ON_FAILURE(containInitPidNs(nsjconf)); + RETURN_ON_FAILURE(containInitMountNs(nsjconf)); + RETURN_ON_FAILURE(containInitNetNs(nsjconf)); + RETURN_ON_FAILURE(containInitUtsNs(nsjconf)); + RETURN_ON_FAILURE(containInitCgroupNs()); + RETURN_ON_FAILURE(containDropPrivs(nsjconf)); + ; /* */ /* As non-root */ - if (!containCPU(nsjconf)) { - return false; - } - if (!containSetLimits(nsjconf)) { - return false; - } - if (!containPrepareEnv(nsjconf)) { - return false; - } - if (!containMakeFdsCOE(nsjconf)) { - return false; - } + RETURN_ON_FAILURE(containCPU(nsjconf)); + RETURN_ON_FAILURE(containSetLimits(nsjconf)); + RETURN_ON_FAILURE(containPrepareEnv(nsjconf)); + RETURN_ON_FAILURE(containMakeFdsCOE(nsjconf)); + return true; } diff --git a/user.cc b/user.cc index 1eccadc..4053884 100644 --- a/user.cc +++ b/user.cc @@ -205,18 +205,11 @@ static bool uidMapExternal(nsjconf_t* nsjconf, pid_t pid UNUSED) { } static bool uidGidMap(nsjconf_t* nsjconf, pid_t pid) { - if (!gidMapSelf(nsjconf, pid)) { - return false; - } - if (!gidMapExternal(nsjconf, pid)) { - return false; - } - if (!uidMapSelf(nsjconf, pid)) { - return false; - } - if (!uidMapExternal(nsjconf, pid)) { - return false; - } + RETURN_ON_FAILURE(gidMapSelf(nsjconf, pid)); + RETURN_ON_FAILURE(gidMapExternal(nsjconf, pid)); + RETURN_ON_FAILURE(uidMapSelf(nsjconf, pid)); + RETURN_ON_FAILURE(uidMapExternal(nsjconf, pid)); + return true; }