From: Jagger Date: Tue, 7 Jul 2015 22:54:59 +0000 (+0200) Subject: tmpfs_size (size_t) + indent X-Git-Tag: 1.0~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3fe2d183ccdce3a5a86d67afc7c8cc37bfbbc99;p=platform%2Fupstream%2Fnsjail.git tmpfs_size (size_t) + indent --- diff --git a/cmdline.c b/cmdline.c index 92ce5a0..0a7ac4f 100644 --- a/cmdline.c +++ b/cmdline.c @@ -87,7 +87,7 @@ void cmdlineLogParams(struct nsjconf_t *nsjconf) "max_conns_per_ip:%u, uid:%u, gid:%u, time_limit:%ld, personality:%#lx, daemonize:%s, " "clone_newnet:%s, clone_newuser:%s, clone_newns:%s, clone_newpid:%s, " "clone_newipc:%s, clonew_newuts:%s, apply_sandbox:%s, keep_caps:%s, " - "tmpfs_size:%u", + "tmpfs_size:%zu", nsjconf->hostname, nsjconf->chroot, nsjconf->argv[0], nsjconf->port, nsjconf->max_conns_per_ip, nsjconf->uid, nsjconf->gid, nsjconf->tlimit, nsjconf->personality, logYesNo(nsjconf->daemonize), logYesNo(nsjconf->clone_newnet), @@ -182,7 +182,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf) .initial_uid = getuid(), .initial_gid = getgid(), .max_conns_per_ip = 0, - .tmpfs_size = 4*1024*1024, + .tmpfs_size = 4 * (1024 * 1024), }; /* *INDENT-OFF* */ @@ -269,7 +269,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf) nsjconf->max_conns_per_ip = strtoul(optarg, NULL, 0); break; case 0x0506: - nsjconf->tmpfs_size = strtoul(optarg, NULL, 0); + nsjconf->tmpfs_size = strtoull(optarg, NULL, 0); break; case 'u': user = optarg; diff --git a/common.h b/common.h index 4923537..143af6a 100644 --- a/common.h +++ b/common.h @@ -83,7 +83,7 @@ struct nsjconf_t { uid_t initial_uid; gid_t initial_gid; unsigned int max_conns_per_ip; - unsigned int tmpfs_size; + size_t tmpfs_size; LIST_HEAD(pidslist, pids_t) pids; LIST_HEAD(rwbindmountptslist, constchar_t) rwbindmountpts; LIST_HEAD(robindmountptslist, constchar_t) robindmountpts; diff --git a/contain.c b/contain.c index b2231f2..250df3b 100644 --- a/contain.c +++ b/contain.c @@ -177,7 +177,8 @@ bool containPrepareEnv(struct nsjconf_t * nsjconf) /* findSpecDestination mutates spec (source:dest) to have a null byte instead * of ':' in between source and dest, then returns a pointer to the dest * string. */ -static char *findSpecDestination(char *spec) { +static char *findSpecDestination(char *spec) +{ char *dest = spec; while (*dest != ':' && *dest != '\0') { dest++; @@ -195,7 +196,8 @@ static char *findSpecDestination(char *spec) { } } -static bool bindMount(const char *newrootdir, const char *spec) { +static bool bindMount(const char *newrootdir, const char *spec) +{ char mount_pt[PATH_MAX]; bool success = false; char *source = strdup(spec); @@ -213,12 +215,13 @@ static bool bindMount(const char *newrootdir, const char *spec) { } success = true; -cleanup: + cleanup: free(source); return success; } -static bool remountBindMount(const char *spec, unsigned long flags) { +static bool remountBindMount(const char *spec, unsigned long flags) +{ bool success = false; char *source = strdup(spec); char *dest = findSpecDestination(source); @@ -230,7 +233,7 @@ static bool remountBindMount(const char *spec, unsigned long flags) { } success = true; -cleanup: + cleanup: free(source); return success; } @@ -297,8 +300,8 @@ bool containMountFS(struct nsjconf_t * nsjconf) /* It only makes sense with "--chroot /", so don't worry about errors */ umount2(destdir, MNT_DETACH); - char tmpfs_size[11+5]; - snprintf(tmpfs_size, sizeof(tmpfs_size), "size=%u", nsjconf->tmpfs_size); + char tmpfs_size[128]; + snprintf(tmpfs_size, sizeof(tmpfs_size), "size=%zu", nsjconf->tmpfs_size); LIST_FOREACH(p, &nsjconf->tmpfsmountpts, pointers) { if (strchr(p->value, ':') != NULL) { PLOG_E("invalid tmpfs mount spec. source:dest format unsupported."); @@ -317,9 +320,7 @@ bool containMountFS(struct nsjconf_t * nsjconf) } if (nsjconf->is_root_rw == false) { - if (mount - ("/", "/", NULL, MS_BIND | MS_RDONLY | MS_NOSUID | MS_REMOUNT | MS_PRIVATE, - NULL) == -1) { + if (mount("/", "/", NULL, MS_BIND | MS_RDONLY | MS_NOSUID | MS_REMOUNT | MS_PRIVATE, NULL) == -1) { PLOG_E("mount('/', '/', MS_BIND|MS_RDONLY|MS_NOSUID|MS_REMOUNT|MS_PRIVATE)"); return false; } @@ -336,7 +337,6 @@ bool containMountFS(struct nsjconf_t * nsjconf) } } - return true; }