]> git.proxmox.com Git - mirror_lxcfs.git/blobdiff - lxcfs.c
pam_cgfs: remove dead assignment
[mirror_lxcfs.git] / lxcfs.c
diff --git a/lxcfs.c b/lxcfs.c
index f37ede427013b9fb98282f6699d79e391b5a60a2..d065125844baa1de19104387748018b5db816003 100644 (file)
--- a/lxcfs.c
+++ b/lxcfs.c
 #include <wait.h>
 #include <linux/sched.h>
 #include <sys/epoll.h>
-#include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/socket.h>
-#include <sys/syscall.h>
 
 #include "bindings.h"
 #include "config.h" // for VERSION
 
-/* Define pivot_root() if missing from the C library */
-#ifndef HAVE_PIVOT_ROOT
-static int pivot_root(const char * new_root, const char * put_old)
-{
-#ifdef __NR_pivot_root
-return syscall(__NR_pivot_root, new_root, put_old);
-#else
-errno = ENOSYS;
-return -1;
-#endif
-}
-#else
-extern int pivot_root(const char * new_root, const char * put_old);
-#endif
-
 void *dlopen_handle;
 
 /* Functions to keep track of number of threads using the library */
@@ -60,7 +43,7 @@ static void lock_mutex(pthread_mutex_t *l)
        int ret;
 
        if ((ret = pthread_mutex_lock(l)) != 0) {
-               fprintf(stderr, "pthread_mutex_lock returned:%d %s\n", ret, strerror(ret));
+               lxcfs_error("returned:%d %s\n", ret, strerror(ret));
                exit(1);
        }
 }
@@ -70,7 +53,7 @@ static void unlock_mutex(pthread_mutex_t *l)
        int ret;
 
        if ((ret = pthread_mutex_unlock(l)) != 0) {
-               fprintf(stderr, "pthread_mutex_unlock returned:%d %s\n", ret, strerror(ret));
+               lxcfs_error("returned:%d %s\n", ret, strerror(ret));
                exit(1);
        }
 }
@@ -91,23 +74,27 @@ static volatile sig_atomic_t need_reload;
  * lock and when we know the user_count was 0 */
 static void do_reload(void)
 {
-       if (dlopen_handle)
+       if (dlopen_handle) {
+               lxcfs_debug("%s\n", "Closing liblxcfs.so handle.");
                dlclose(dlopen_handle);
+       }
 
        /* First try loading using ld.so */
        dlopen_handle = dlopen("liblxcfs.so", RTLD_LAZY);
-       if (dlopen_handle)
+       if (dlopen_handle) {
+               lxcfs_debug("%s\n", "Successfully called dlopen() on liblxcfs.so.");
                goto good;
+       }
 
        dlopen_handle = dlopen("/usr/lib/lxcfs/liblxcfs.so", RTLD_LAZY);
        if (!dlopen_handle) {
-               fprintf(stderr, "Failed to open liblxcfs\n");
+               lxcfs_error("Failed to open liblxcfs.so: %s.\n", dlerror());
                _exit(1);
        }
 
 good:
        if (need_reload)
-               fprintf(stderr, "lxcfs: reloaded\n");
+               lxcfs_error("%s\n", "lxcfs: reloaded");
        need_reload = 0;
 }
 
@@ -132,27 +119,6 @@ static void reload_handler(int sig)
        need_reload = 1;
 }
 
-/*
- * Functions and types to ease the use of clone()/__clone2()
- */
-pid_t lxcfs_clone(int (*fn)(void *), void *arg, int flags)
-{
-       size_t stack_size = sysconf(_SC_PAGESIZE);
-       void *stack = alloca(stack_size);
-       pid_t ret;
-
-#ifdef __ia64__
-       ret = __clone2(do_clone, stack,
-                      stack_size, flags | SIGCHLD, &clone_arg);
-#else
-       ret = clone(fn, stack  + stack_size, flags | SIGCHLD, &arg);
-#endif
-       if (ret < 0)
-               fprintf(stderr, "failed to clone (%#x): %s", flags, strerror(errno));
-
-       return ret;
-}
-
 /* Functions to run the library methods */
 static int do_cg_getattr(const char *path, struct stat *sb)
 {
@@ -162,7 +128,7 @@ static int do_cg_getattr(const char *path, struct stat *sb)
        cg_getattr = (int (*)(const char *, struct stat *)) dlsym(dlopen_handle, "cg_getattr");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_getattr: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -177,7 +143,7 @@ static int do_proc_getattr(const char *path, struct stat *sb)
        proc_getattr = (int (*)(const char *, struct stat *)) dlsym(dlopen_handle, "proc_getattr");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "proc_getattr: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -195,7 +161,7 @@ static int do_cg_read(const char *path, char *buf, size_t size, off_t offset,
        cg_read = (int (*)(const char *, char *, size_t, off_t, struct fuse_file_info *)) dlsym(dlopen_handle, "cg_read");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_read: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -213,7 +179,7 @@ static int do_proc_read(const char *path, char *buf, size_t size, off_t offset,
        proc_read = (int (*)(const char *, char *, size_t, off_t, struct fuse_file_info *)) dlsym(dlopen_handle, "proc_read");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "proc_read: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -230,7 +196,7 @@ static int do_cg_write(const char *path, const char *buf, size_t size, off_t off
        cg_write = (int (*)(const char *, const char *, size_t, off_t, struct fuse_file_info *)) dlsym(dlopen_handle, "cg_write");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_write: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -245,7 +211,7 @@ static int do_cg_mkdir(const char *path, mode_t mode)
        cg_mkdir = (int (*)(const char *, mode_t)) dlsym(dlopen_handle, "cg_mkdir");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_mkdir: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -260,7 +226,7 @@ static int do_cg_chown(const char *path, uid_t uid, gid_t gid)
        cg_chown = (int (*)(const char *, uid_t, gid_t)) dlsym(dlopen_handle, "cg_chown");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_chown: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -275,7 +241,7 @@ static int do_cg_rmdir(const char *path)
        cg_rmdir = (int (*)(const char *path)) dlsym(dlopen_handle, "cg_rmdir");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_rmdir: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -290,7 +256,7 @@ static int do_cg_chmod(const char *path, mode_t mode)
        cg_chmod = (int (*)(const char *, mode_t)) dlsym(dlopen_handle, "cg_chmod");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_chmod: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -308,7 +274,7 @@ static int do_cg_readdir(const char *path, void *buf, fuse_fill_dir_t filler, of
        cg_readdir = (int (*)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *)) dlsym(dlopen_handle, "cg_readdir");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_readdir: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -326,7 +292,7 @@ static int do_proc_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
        proc_readdir = (int (*)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *)) dlsym(dlopen_handle, "proc_readdir");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "proc_readdir: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -341,7 +307,7 @@ static int do_cg_open(const char *path, struct fuse_file_info *fi)
        cg_open = (int (*)(const char *, struct fuse_file_info *)) dlsym(dlopen_handle, "cg_open");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_open: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -356,7 +322,7 @@ static int do_cg_access(const char *path, int mode)
        cg_access = (int (*)(const char *, int mode)) dlsym(dlopen_handle, "cg_access");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_access: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -371,7 +337,7 @@ static int do_proc_open(const char *path, struct fuse_file_info *fi)
        proc_open = (int (*)(const char *path, struct fuse_file_info *fi)) dlsym(dlopen_handle, "proc_open");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "proc_open: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -386,7 +352,7 @@ static int do_proc_access(const char *path, int mode)
        proc_access = (int (*)(const char *, int mode)) dlsym(dlopen_handle, "proc_access");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "proc_access: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -401,7 +367,7 @@ static int do_cg_release(const char *path, struct fuse_file_info *fi)
        cg_release = (int (*)(const char *path, struct fuse_file_info *)) dlsym(dlopen_handle, "cg_release");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_release: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -416,7 +382,7 @@ static int do_proc_release(const char *path, struct fuse_file_info *fi)
        proc_release = (int (*)(const char *path, struct fuse_file_info *)) dlsym(dlopen_handle, "proc_release");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "proc_release: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -431,7 +397,7 @@ static int do_cg_opendir(const char *path, struct fuse_file_info *fi)
        cg_opendir = (int (*)(const char *path, struct fuse_file_info *fi)) dlsym(dlopen_handle, "cg_opendir");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_opendir: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -446,7 +412,7 @@ static int do_cg_releasedir(const char *path, struct fuse_file_info *fi)
        cg_releasedir = (int (*)(const char *path, struct fuse_file_info *)) dlsym(dlopen_handle, "cg_releasedir");
        error = dlerror();
        if (error != NULL) {
-               fprintf(stderr, "cg_releasedir: %s\n", error);
+               lxcfs_error("%s\n", error);
                return -1;
        }
 
@@ -462,11 +428,19 @@ static int do_cg_releasedir(const char *path, struct fuse_file_info *fi)
 static int lxcfs_getattr(const char *path, struct stat *sb)
 {
        int ret;
+       struct timespec now;
+
        if (strcmp(path, "/") == 0) {
+               if (clock_gettime(CLOCK_REALTIME, &now) < 0)
+                       return -EINVAL;
+               sb->st_uid = sb->st_gid = 0;
+               sb->st_atim = sb->st_mtim = sb->st_ctim = now;
+               sb->st_size = 0;
                sb->st_mode = S_IFDIR | 00755;
                sb->st_nlink = 2;
                return 0;
        }
+
        if (strncmp(path, "/cgroup", 7) == 0) {
                up_users();
                ret = do_cg_getattr(path, sb);
@@ -479,7 +453,7 @@ static int lxcfs_getattr(const char *path, struct stat *sb)
                down_users();
                return ret;
        }
-       return -EINVAL;
+       return -ENOENT;
 }
 
 static int lxcfs_opendir(const char *path, struct fuse_file_info *fi)
@@ -504,9 +478,11 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, of
 {
        int ret;
        if (strcmp(path, "/") == 0) {
-               if (filler(buf, "proc", NULL, 0) != 0 ||
-                               filler(buf, "cgroup", NULL, 0) != 0)
-                       return -EINVAL;
+               if (filler(buf, ".", NULL, 0) != 0 ||
+                   filler(buf, "..", NULL, 0) != 0 ||
+                   filler(buf, "proc", NULL, 0) != 0 ||
+                   filler(buf, "cgroup", NULL, 0) != 0)
+                       return -ENOMEM;
                return 0;
        }
        if (strncmp(path, "/cgroup", 7) == 0) {
@@ -521,12 +497,16 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, of
                down_users();
                return ret;
        }
-       return -EINVAL;
+       return -ENOENT;
 }
 
 static int lxcfs_access(const char *path, int mode)
 {
        int ret;
+
+       if (strcmp(path, "/") == 0 && (mode & W_OK) == 0)
+               return 0;
+
        if (strncmp(path, "/cgroup", 7) == 0) {
                up_users();
                ret = do_cg_access(path, mode);
@@ -540,7 +520,7 @@ static int lxcfs_access(const char *path, int mode)
                return ret;
        }
 
-       return -EINVAL;
+       return -EACCES;
 }
 
 static int lxcfs_releasedir(const char *path, struct fuse_file_info *fi)
@@ -575,7 +555,7 @@ static int lxcfs_open(const char *path, struct fuse_file_info *fi)
                return ret;
        }
 
-       return -EINVAL;
+       return -EACCES;
 }
 
 static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
@@ -651,7 +631,7 @@ int lxcfs_mkdir(const char *path, mode_t mode)
                return ret;
        }
 
-       return -EINVAL;
+       return -EPERM;
 }
 
 int lxcfs_chown(const char *path, uid_t uid, gid_t gid)
@@ -664,7 +644,10 @@ int lxcfs_chown(const char *path, uid_t uid, gid_t gid)
                return ret;
        }
 
-       return -EINVAL;
+       if (strncmp(path, "/proc", 5) == 0)
+               return -EPERM;
+
+       return -ENOENT;
 }
 
 /*
@@ -676,7 +659,7 @@ int lxcfs_truncate(const char *path, off_t newsize)
 {
        if (strncmp(path, "/cgroup", 7) == 0)
                return 0;
-       return -EINVAL;
+       return -EPERM;
 }
 
 int lxcfs_rmdir(const char *path)
@@ -688,7 +671,7 @@ int lxcfs_rmdir(const char *path)
                down_users();
                return ret;
        }
-       return -EINVAL;
+       return -EPERM;
 }
 
 int lxcfs_chmod(const char *path, mode_t mode)
@@ -700,7 +683,11 @@ int lxcfs_chmod(const char *path, mode_t mode)
                down_users();
                return ret;
        }
-       return -EINVAL;
+
+       if (strncmp(path, "/proc", 5) == 0)
+               return -EPERM;
+
+       return -ENOENT;
 }
 
 const struct fuse_operations lxcfs_ops = {
@@ -746,13 +733,13 @@ const struct fuse_operations lxcfs_ops = {
        .fgetattr = NULL,
 };
 
-static void usage(const char *me)
+static void usage()
 {
        fprintf(stderr, "Usage:\n");
        fprintf(stderr, "\n");
-       fprintf(stderr, "%s [-p pidfile] mountpoint\n", me);
+       fprintf(stderr, "lxcfs [-p pidfile] mountpoint\n");
        fprintf(stderr, "  Default pidfile is %s/lxcfs.pid\n", RUNTIME_PATH);
-       fprintf(stderr, "%s -h\n", me);
+       fprintf(stderr, "lxcfs -h\n");
        exit(1);
 }
 
@@ -802,213 +789,6 @@ bool swallow_option(int *argcp, char *argv[], char *opt, char **v)
        return false;
 }
 
-static bool mkdir_p(const char *dir, mode_t mode)
-{
-       const char *tmp = dir;
-       const char *orig = dir;
-       char *makeme;
-
-       do {
-               dir = tmp + strspn(tmp, "/");
-               tmp = dir + strcspn(dir, "/");
-               makeme = strndup(orig, dir - orig);
-               if (!makeme)
-                       return false;
-               if (mkdir(makeme, mode) && errno != EEXIST) {
-                       fprintf(stderr, "failed to create directory '%s': %s",
-                               makeme, strerror(errno));
-                       free(makeme);
-                       return false;
-               }
-               free(makeme);
-       } while(tmp != dir);
-
-       return true;
-}
-
-static bool umount_if_mounted(void)
-{
-       if (umount2(BASEDIR, MNT_DETACH) < 0 && errno != EINVAL) {
-               fprintf(stderr, "failed to umount %s: %s\n", BASEDIR,
-                       strerror(errno));
-               return false;
-       }
-       return true;
-}
-
-static int pivot_enter(void)
-{
-       int ret = -1, oldroot = -1, newroot = -1;
-
-       oldroot = open("/", O_DIRECTORY | O_RDONLY);
-       if (oldroot < 0) {
-               fprintf(stderr, "%s: Failed to open old root for fchdir.\n", __func__);
-               return ret;
-       }
-
-       newroot = open(ROOTDIR, O_DIRECTORY | O_RDONLY);
-       if (newroot < 0) {
-               fprintf(stderr, "%s: Failed to open new root for fchdir.\n", __func__);
-               goto err;
-       }
-
-       /* change into new root fs */
-       if (fchdir(newroot) < 0) {
-               fprintf(stderr, "%s: Failed to change directory to new rootfs: %s.\n", __func__, ROOTDIR);
-               goto err;
-       }
-
-       /* pivot_root into our new root fs */
-       if (pivot_root(".", ".") < 0) {
-               fprintf(stderr, "%s: pivot_root() syscall failed: %s.\n", __func__, strerror(errno));
-               goto err;
-       }
-
-       /*
-        * At this point the old-root is mounted on top of our new-root.
-        * To unmounted it we must not be chdir'd into it, so escape back
-        * to the old-root.
-        */
-       if (fchdir(oldroot) < 0) {
-               fprintf(stderr, "%s: Failed to enter old root.\n", __func__);
-               goto err;
-       }
-       if (umount2(".", MNT_DETACH) < 0) {
-               fprintf(stderr, "%s: Failed to detach old root.\n", __func__);
-               goto err;
-       }
-
-       if (fchdir(newroot) < 0) {
-               fprintf(stderr, "%s: Failed to re-enter new root.\n", __func__);
-               goto err;
-       }
-
-       ret = 0;
-
-err:
-       if (oldroot > 0)
-               close(oldroot);
-       if (newroot > 0)
-               close(newroot);
-       return ret;
-}
-
-/* Prepare our new clean root. */
-static int pivot_prepare(void)
-{
-       if (mkdir(ROOTDIR, 0700) < 0 && errno != EEXIST) {
-               fprintf(stderr, "%s: Failed to create directory for new root.\n", __func__);
-               return -1;
-       }
-
-       if (mount("/", ROOTDIR, NULL, MS_BIND, 0) < 0) {
-               fprintf(stderr, "%s: Failed to bind-mount / for new root: %s.\n", __func__, strerror(errno));
-               return -1;
-       }
-
-       if (mount(RUNTIME_PATH, ROOTDIR RUNTIME_PATH, NULL, MS_BIND, 0) < 0) {
-               fprintf(stderr, "%s: Failed to bind-mount /run into new root: %s.\n", __func__, strerror(errno));
-               return -1;
-       }
-
-       if (mount(BASEDIR, ROOTDIR BASEDIR, NULL, MS_REC | MS_MOVE, 0) < 0) {
-               printf("%s: failed to move " BASEDIR " into new root: %s.\n", __func__, strerror(errno));
-               return -1;
-       }
-
-       return 0;
-}
-
-static bool pivot_new_root(void)
-{
-       /* Prepare new root. */
-       if (pivot_prepare() < 0)
-               return false;
-
-       /* Pivot into new root. */
-       if (pivot_enter() < 0)
-               return false;
-
-       return true;
-}
-
-static bool setup_cgfs_dir(void)
-{
-       if (!mkdir_p(BASEDIR, 0700)) {
-               fprintf(stderr, "Failed to create lxcfs cgdir\n");
-               return false;
-       }
-       if (!umount_if_mounted()) {
-               fprintf(stderr, "Failed to clean up old lxcfs cgdir\n");
-               return false;
-       }
-       if (mount("tmpfs", BASEDIR, "tmpfs", 0, "size=100000,mode=700") < 0) {
-               fprintf(stderr, "Failed to mount tmpfs for private controllers\n");
-               return false;
-       }
-       return true;
-}
-
-static bool do_mount_cgroups(void)
-{
-       char *target;
-       size_t clen, len;
-       int i, ret;
-
-       for (i = 0; i < num_hierarchies; i++) {
-               char *controller = hierarchies[i];
-               clen = strlen(controller);
-               len = strlen(BASEDIR) + clen + 2;
-               target = malloc(len);
-               if (!target)
-                       return false;
-               ret = snprintf(target, len, "%s/%s", BASEDIR, controller);
-               if (ret < 0 || ret >= len) {
-                       free(target);
-                       return false;
-               }
-               if (mkdir(target, 0755) < 0 && errno != EEXIST) {
-                       free(target);
-                       return false;
-               }
-               if (mount(controller, target, "cgroup", 0, controller) < 0) {
-                       fprintf(stderr, "Failed mounting cgroup %s\n", controller);
-                       free(target);
-                       return false;
-               }
-
-               fd_hierarchies[i] = open(target, O_DIRECTORY);
-               if (fd_hierarchies[i] < 0) {
-                       free(target);
-                       return false;
-               }
-               free(target);
-       }
-       return true;
-}
-
-static int cgfs_setup_controllers(void *data)
-{
-       if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0) < 0) {
-               fprintf(stderr, "%s: Failed to re-mount / private: %s.\n", __func__, strerror(errno));
-               return -1;
-       }
-
-       if (!setup_cgfs_dir()) {
-               return false;
-       }
-
-       if (!do_mount_cgroups()) {
-               fprintf(stderr, "Failed to set up cgroup mounts\n");
-               return false;
-       }
-
-       if (!pivot_new_root())
-               return false;
-
-       return true;
-}
-
 static int set_pidfile(char *pidfile)
 {
        int fd;
@@ -1022,7 +802,7 @@ static int set_pidfile(char *pidfile)
 
        fd = open(pidfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
        if (fd == -1) {
-               fprintf(stderr, "Could not open pidfile %s: %m", pidfile);
+               fprintf(stderr, "Could not open pidfile %s: %m\n", pidfile);
                return -1;
        }
 
@@ -1051,20 +831,12 @@ static int set_pidfile(char *pidfile)
        return fd;
 }
 
-static void close_fd_hierarchies(void)
-{
-       int i;
-       for (i = 0; i < num_hierarchies; i++)
-               if (fd_hierarchies[i] > 0)
-                       close(fd_hierarchies[i]);
-}
-
 int main(int argc, char *argv[])
 {
        int ret = EXIT_FAILURE;
        int pidfd = -1;
        char *pidfile = NULL, *v = NULL;
-       size_t pidfile_len, mmap_len = 0;
+       size_t pidfile_len;
        /*
         * what we pass to fuse_main is:
         * argv[0] -s -f -o allow_other,directio argv[1] NULL
@@ -1091,7 +863,7 @@ int main(int argc, char *argv[])
                exit(EXIT_SUCCESS);
        }
        if (argc != 2 || is_help(argv[1]))
-               usage(argv[0]);
+               usage();
 
        do_reload();
        if (signal(SIGUSR1, reload_handler) == SIG_ERR) {
@@ -1106,24 +878,6 @@ int main(int argc, char *argv[])
        newargv[cnt++] = argv[1];
        newargv[cnt++] = NULL;
 
-       /* Share memory with our clone(). */
-       mmap_len = sizeof(int *) * num_hierarchies;
-       fd_hierarchies = mmap(NULL, mmap_len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
-       if (!fd_hierarchies)
-               goto out;
-
-       /* Mount cgroups in private mount namespace while sharing open file
-        * desciptores between clone() and parent. */
-       pid_t pid = lxcfs_clone(cgfs_setup_controllers, NULL, CLONE_NEWNS | CLONE_FILES);
-       if (pid < 0) {
-               fprintf(stderr, "%s: Error cloning new mount namespace: %s\n", __func__, strerror(errno));
-               goto out;
-       }
-       if (waitpid(pid, NULL, 0) < 0) {
-               fprintf(stderr, "%s: Error waiting on cloned child: %s\n", __func__, strerror(errno));
-               goto out;
-       }
-
        if (!pidfile) {
                pidfile_len = strlen(RUNTIME_PATH) + strlen("/lxcfs.pid") + 1;
                pidfile = alloca(pidfile_len);
@@ -1142,8 +896,5 @@ out:
                unlink(pidfile);
        if (pidfd > 0)
                close(pidfd);
-       close_fd_hierarchies();
-       if (fd_hierarchies)
-               munmap(fd_hierarchies, mmap_len);
        exit(ret);
 }