tmpfs_size (size_t) + indent
authorJagger <robert@swiecki.net>
Tue, 7 Jul 2015 22:54:59 +0000 (00:54 +0200)
committerJagger <robert@swiecki.net>
Tue, 7 Jul 2015 22:54:59 +0000 (00:54 +0200)
cmdline.c
common.h
contain.c

index 92ce5a0f7d7110e49effd5bc479ca2c6dd3c7f0a..0a7ac4f0975ec59e54fb0b9f82a6fcbc56f5d1ab 100644 (file)
--- 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;
index 49235371beb8f59f1f8e50418a7e6cf19401dbbf..143af6a1c945822c5a4e255a8f9fbfe992c203ff 100644 (file)
--- 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;
index b2231f2f5faf91c0e2e7092361ba3fa6136a1bfb..250df3bcf4e4c5f44991f13cfcb9e73748043a48 100644 (file)
--- 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;
 }