]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Revert "Use pthread_atfork() to unlock mutexes after fork()"
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 2 Jan 2014 15:40:16 +0000 (09:40 -0600)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 2 Jan 2014 15:40:16 +0000 (09:40 -0600)
This reverts commit 84e9e197933e601b66480da578b92630ebedfc72, because
it breaks bionic builds.  The patch is desirable so hopefully we can
come up with a solution or alternate patch soon.

src/lxc/Makefile.am
src/lxc/attach.c
src/lxc/bdev.c
src/lxc/lxccontainer.c
src/lxc/lxclock.c
src/lxc/monitor.c

index f18d6e17689df779486eff1aee0420d7026669e2..74b38e2dbbfa2ee285d3f0c5611591ccdc9465b0 100644 (file)
@@ -135,10 +135,9 @@ AM_CFLAGS += -DHAVE_SECCOMP
 liblxc_so_SOURCES += seccomp.c
 endif
 
-liblxc_so_CFLAGS = -fPIC -DPIC $(AM_CFLAGS) -pthread
+liblxc_so_CFLAGS = -fPIC -DPIC $(AM_CFLAGS)
 
 liblxc_so_LDFLAGS = \
-       -pthread \
        -shared \
        -Wl,-soname,liblxc.so.$(firstword $(subst ., ,$(VERSION)))
 
index 252e172a2a97d0b73b1da1f03bdebddf5f06b365..674961731b39f8e58ab7499769b60a2a7bc91c5b 100644 (file)
@@ -497,6 +497,7 @@ char *lxc_attach_getpwshell(uid_t uid)
                        NULL
                };
 
+               process_unlock(); // we're no longer sharing
                close(pipes[0]);
 
                /* we want to capture stdout */
@@ -789,6 +790,7 @@ int lxc_attach(const char* name, const char* lxcpath, lxc_attach_exec_t exec_fun
                return -1;
        }
 
+       process_unlock(); // we're no longer sharing
        /* first subprocess begins here, we close the socket that is for the
         * initial thread
         */
index d6175c111771aa95ae4a128f2e04d259774d7d37..29e2ad57f77b4d9c594df2380ed3efdc7fd89e99 100644 (file)
@@ -73,6 +73,7 @@ static int do_rsync(const char *src, const char *dest)
        if (pid > 0)
                return wait_for_pid(pid);
 
+       process_unlock(); // we're no longer sharing
        l = strlen(src) + 2;
        s = malloc(l);
        if (!s)
@@ -197,6 +198,7 @@ static int do_mkfs(const char *path, const char *fstype)
        if (pid > 0)
                return wait_for_pid(pid);
 
+       process_unlock(); // we're no longer sharing
        // If the file is not a block device, we don't want mkfs to ask
        // us about whether to proceed.
        close(0);
@@ -281,6 +283,7 @@ static int detect_fs(struct bdev *bdev, char *type, int len)
                return ret;
        }
 
+       process_unlock(); // we're no longer sharing
        if (unshare(CLONE_NEWNS) < 0)
                exit(1);
 
@@ -572,6 +575,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
                if (!pid) {
                        char dev[MAXPATHLEN];
 
+                       process_unlock(); // we're no longer sharing
                        ret = snprintf(dev, MAXPATHLEN, "%s/%s", zfsroot, nname);
                        if (ret < 0  || ret >= MAXPATHLEN)
                                exit(1);
@@ -595,6 +599,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
                if ((pid = fork()) < 0)
                        return -1;
                if (!pid) {
+                       process_unlock(); // we're no longer sharing
                        execlp("zfs", "zfs", "destroy", path1, NULL);
                        exit(1);
                }
@@ -605,6 +610,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
                if ((pid = fork()) < 0)
                        return -1;
                if (!pid) {
+                       process_unlock(); // we're no longer sharing
                        execlp("zfs", "zfs", "snapshot", path1, NULL);
                        exit(1);
                }
@@ -615,6 +621,7 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
                if ((pid = fork()) < 0)
                        return -1;
                if (!pid) {
+                       process_unlock(); // we're no longer sharing
                        execlp("zfs", "zfs", "clone", option, path1, path2, NULL);
                        exit(1);
                }
@@ -665,6 +672,7 @@ static int zfs_destroy(struct bdev *orig)
        if (pid)
                return wait_for_pid(pid);
 
+       process_unlock(); // we're no longer sharing
        if (!zfs_list_entry(orig->src, output, MAXPATHLEN)) {
                ERROR("Error: zfs entry for %s not found", orig->src);
                return -1;
@@ -709,6 +717,7 @@ static int zfs_create(struct bdev *bdev, const char *dest, const char *n,
        if (pid)
                return wait_for_pid(pid);
 
+       process_unlock(); // we're no longer sharing
        char dev[MAXPATHLEN];
        ret = snprintf(dev, MAXPATHLEN, "%s/%s", zfsroot, n);
        if (ret < 0  || ret >= MAXPATHLEN)
@@ -853,6 +862,7 @@ static int do_lvm_create(const char *path, unsigned long size, const char *thinp
        if (pid > 0)
                return wait_for_pid(pid);
 
+       process_unlock(); // we're no longer sharing
        // lvcreate default size is in M, not bytes.
        ret = snprintf(sz, 24, "%lu", size/1000000);
        if (ret < 0 || ret >= 24)
@@ -912,6 +922,7 @@ static int lvm_snapshot(const char *orig, const char *path, unsigned long size)
        if (pid > 0)
                return wait_for_pid(pid);
 
+       process_unlock(); // we're no longer sharing
        // lvcreate default size is in M, not bytes.
        ret = snprintf(sz, 24, "%lu", size/1000000);
        if (ret < 0 || ret >= 24)
@@ -1045,6 +1056,7 @@ static int lvm_destroy(struct bdev *orig)
        if ((pid = fork()) < 0)
                return -1;
        if (!pid) {
+               process_unlock(); // we're no longer sharing
                execlp("lvremove", "lvremove", "-f", orig->src, NULL);
                exit(1);
        }
@@ -2080,6 +2092,7 @@ struct bdev *bdev_copy(const char *src, const char *oldname, const char *cname,
                return new;
        }
 
+       process_unlock(); // we're no longer sharing
        if (unshare(CLONE_NEWNS) < 0) {
                SYSERROR("unshare CLONE_NEWNS");
                exit(1);
index e1cbd76f5340fe78f4ce1bebb5d4bd87f4aee469..b62f7ba6eb861a180758a4453a994f63a5fb7e77 100644 (file)
@@ -601,6 +601,7 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
                if (pid != 0)
                        return wait_on_daemonized_start(c, pid);
 
+               process_unlock(); // we're no longer sharing
                /* second fork to be reparented by init */
                pid = fork();
                if (pid < 0) {
@@ -838,6 +839,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool quiet
                char **newargv;
                struct lxc_conf *conf = c->lxc_conf;
 
+               process_unlock(); // we're no longer sharing
                if (quiet) {
                        close(0);
                        close(1);
@@ -1234,6 +1236,7 @@ static bool lxcapi_create(struct lxc_container *c, const char *t,
        if (pid == 0) { // child
                struct bdev *bdev = NULL;
 
+               process_unlock(); // we're no longer sharing
                if (!(bdev = do_bdev_create(c, bdevtype, specs))) {
                        ERROR("Error creating backing store type %s for %s",
                                bdevtype ? bdevtype : "(none)", c->name);
@@ -2325,6 +2328,7 @@ static int clone_update_rootfs(struct lxc_container *c0,
        if (pid > 0)
                return wait_for_pid(pid);
 
+       process_unlock(); // we're no longer sharing
        bdev = bdev_init(c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
        if (!bdev)
                exit(1);
index 69d3d158af9bd73ef4391b8a4cba23e32e4054fd..b30f4c3421079b0305fba0de76973abde233fc4a 100644 (file)
@@ -89,7 +89,7 @@ void unlock_mutex(pthread_mutex_t *l)
        int ret;
 
        if ((ret = pthread_mutex_unlock(l)) != 0) {
-               fprintf(stderr, "pthread_mutex_unlock returned:%d %s", ret, strerror(ret));
+               fprintf(stderr, "pthread_mutex_lock returned:%d %s", ret, strerror(ret));
                dump_stacktrace();
                exit(1);
        }
@@ -317,21 +317,6 @@ void process_unlock(void)
        unlock_mutex(&thread_mutex);
 }
 
-/* One thread can do fork() while another one is holding a mutex.
- * There is only one thread in child just after the fork(), so noone will ever release that mutex.
- * We setup a "child" fork handler to unlock the mutex just after the fork().
- * For several mutex types, unlocking an unlocked mutex can lead to undefined behavior.
- * One way to deal with it is to setup "prepare" fork handler
- * to lock the mutex before fork() and both "parent" and "child" fork handlers
- * to unlock the mutex.
- * This forbids doing fork() while explicitly holding the lock.
- */
-__attribute__((constructor))
-static void process_lock_setup_atfork(void)
-{
-       pthread_atfork(process_lock, process_unlock, process_unlock);
-}
-
 /* Protects static const values inside the lxc_global_config_value funtion */
 void static_lock(void)
 {
@@ -343,12 +328,6 @@ void static_unlock(void)
        unlock_mutex(&static_mutex);
 }
 
-__attribute__((constructor))
-static void static_lock_setup_atfork(void)
-{
-       pthread_atfork(static_lock, static_unlock, static_unlock);
-}
-
 int container_mem_lock(struct lxc_container *c)
 {
        return lxclock(c->privlock, 0);
index 1fe117072b28e4e9ccf2a77182942708b5f154e3..2cc4831afd7c472b46a17460de570278475fcbcd 100644 (file)
@@ -299,6 +299,7 @@ int lxc_monitord_spawn(const char *lxcpath)
                return 0;
        }
 
+       process_unlock(); // we're no longer sharing
        if (pipe(pipefd) < 0) {
                SYSERROR("failed to create pipe");
                exit(EXIT_FAILURE);