From: Yoshisato Yanagisawa Date: Mon, 25 Sep 2017 05:08:22 +0000 (+0900) Subject: Use 0xff as nsjail error code. X-Git-Tag: 1.7~5^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1389da4c917c09a6522d15d05da741ab0a9fae11;p=platform%2Fupstream%2Fnsjail.git Use 0xff as nsjail error code. For ease of distinguishing errors coming from a program executed by nsjail and errors from nsjail, let me change nsjail error exit status code to 0xff instead of 1. I think most of programs use EXIT_FAILURE (i.e. 1) as a default error exit status code. --- diff --git a/log.c b/log.c index 7782a9b..e50fa89 100644 --- a/log.c +++ b/log.c @@ -130,7 +130,7 @@ void logLog(enum llevel_t ll, const char *fn, int ln, bool perr, const char *fmt /* End printing logs */ if (ll == FATAL) { - exit(1); + exit(0xff); } } diff --git a/mount.c b/mount.c index 854809d..195c65d 100644 --- a/mount.c +++ b/mount.c @@ -376,7 +376,7 @@ bool mountInitNs(struct nsjconf_t * nsjconf) } if (pid == 0) { - exit(mountInitNsInternal(nsjconf) ? 0 : 1); + exit(mountInitNsInternal(nsjconf) ? 0 : 0xff); } int status; diff --git a/nsjail.c b/nsjail.c index 90c496d..18b27fa 100644 --- a/nsjail.c +++ b/nsjail.c @@ -170,7 +170,7 @@ int main(int argc, char *argv[]) struct nsjconf_t nsjconf; if (!cmdlineParse(argc, argv, &nsjconf)) { LOG_E("Couldn't parse cmdline options"); - exit(1); + exit(0xff); } if (nsjconf.clone_newuser == false && geteuid() != 0) { LOG_W("--disable_clone_newuser requires root() privs"); @@ -180,10 +180,10 @@ int main(int argc, char *argv[]) } cmdlineLogParams(&nsjconf); if (nsjailSetSigHandlers() == false) { - exit(1); + exit(0xff); } if (nsjailSetTimer(&nsjconf) == false) { - exit(1); + exit(0xff); } if (nsjconf.mode == MODE_LISTEN_TCP) { diff --git a/subproc.c b/subproc.c index bfc1c35..9243bb4 100644 --- a/subproc.c +++ b/subproc.c @@ -119,29 +119,29 @@ static const char *subprocCloneFlagsToStr(uintptr_t flags) static int subprocNewProc(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_err, int pipefd) { if (containSetupFD(nsjconf, fd_in, fd_out, fd_err) == false) { - exit(1); + exit(0xff); } if (pipefd == -1) { if (userInitNsFromParent(nsjconf, getpid()) == false) { LOG_E("Couldn't initialize net user namespace"); - exit(1); + exit(0xff); } if (cgroupInitNsFromParent(nsjconf, getpid()) == false) { LOG_E("Couldn't initialize net user namespace"); - exit(1); + exit(0xff); } } else { char doneChar; if (utilReadFromFd(pipefd, &doneChar, sizeof(doneChar)) != sizeof(doneChar)) { - exit(1); + exit(0xff); } if (doneChar != subprocDoneChar) { - exit(1); + exit(0xff); } } if (containContain(nsjconf) == false) { - exit(1); + exit(0xff); } if (nsjconf->keep_env == false) { clearenv(); @@ -161,13 +161,13 @@ static int subprocNewProc(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int /* Should be the last one in the sequence */ if (sandboxApply(nsjconf) == false) { - exit(1); + exit(0xff); } execv(nsjconf->exec_file, &nsjconf->argv[0]); PLOG_E("execve('%s') failed", nsjconf->exec_file); - _exit(1); + _exit(0xff); } static void subprocAdd(struct nsjconf_t *nsjconf, pid_t pid, int sock) @@ -359,7 +359,7 @@ static bool subprocInitParent(struct nsjconf_t *nsjconf, pid_t pid, int pipefd) } if (cgroupInitNsFromParent(nsjconf, pid) == false) { LOG_E("Couldn't initialize cgroup user namespace"); - exit(1); + exit(0xff); } if (userInitNsFromParent(nsjconf, pid) == false) { LOG_E("Couldn't initialize user namespaces for pid %d", pid); @@ -428,7 +428,7 @@ void subprocRunChild(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_er LOG_D("Entering namespace with flags:%s", subprocCloneFlagsToStr(flags)); if (unshare(flags) == -1) { PLOG_E("unshare(%#lx)", flags); - _exit(EXIT_FAILURE); + _exit(0xff); } subprocNewProc(nsjconf, fd_in, fd_out, fd_err, -1); }