pthread_mutex_lock() will only return an error if it was set to
PTHREAD_MUTEX_ERRORCHECK and we are recursively calling it (and
would otherwise have deadlocked).  If that's the case then log a
message for future debugging and exit.  Trying to "recover" at
that point is madness.

Signed-off-by: Serge Hallyn <serge.hal...@ubuntu.com>
---
 src/lxc/console.c      | 16 ++++++++--------
 src/lxc/lxccontainer.c | 12 ++++--------
 src/lxc/lxclock.c      |  6 ++++--
 src/lxc/lxclock.h      |  2 +-
 src/lxc/monitor.c      |  2 ++
 5 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/lxc/console.c b/src/lxc/console.c
index e35a811..f503f18 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -100,16 +100,16 @@ static void lxc_console_winch(struct lxc_tty_state *ts)
 
 void lxc_console_sigwinch(int sig)
 {
-       if (process_lock() == 0) {
-               struct lxc_list *it;
-               struct lxc_tty_state *ts;
+       struct lxc_list *it;
+       struct lxc_tty_state *ts;
 
-               lxc_list_for_each(it, &lxc_ttys) {
-                       ts = it->elem;
-                       lxc_console_winch(ts);
-               }
-               process_unlock();
+       process_lock();
+
+       lxc_list_for_each(it, &lxc_ttys) {
+               ts = it->elem;
+               lxc_console_winch(ts);
        }
+       process_unlock();
 }
 
 static int lxc_console_cb_sigwinch_fd(int fd, void *cbdata,
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 3c51c4a..bb2f226 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -100,8 +100,7 @@ int ongoing_create(struct lxc_container *c)
 
        if (!file_exists(path))
                return 0;
-       if (process_lock())
-               return -1;
+       process_lock();
        if ((fd = open(path, O_RDWR)) < 0) {
                // give benefit of the doubt
                SYSERROR("Error opening partial file");
@@ -138,8 +137,7 @@ int create_partial(struct lxc_container *c)
                ERROR("Error writing partial pathname");
                return -1;
        }
-       if (process_lock())
-               return -1;
+       process_lock();
        if ((fd=open(path, O_RDWR | O_CREAT | O_EXCL, 0755)) < 0) {
                SYSERROR("Erorr creating partial file");
                process_unlock();
@@ -173,8 +171,7 @@ void remove_partial(struct lxc_container *c, int fd)
                ERROR("Error writing partial pathname");
                return;
        }
-       if (process_lock())
-               return;
+       process_lock();
        if (unlink(path) < 0)
                SYSERROR("Error unlink partial file %s", path);
        process_unlock();
@@ -546,8 +543,7 @@ static bool lxcapi_start(struct lxc_container *c, int 
useinit, char * const argv
                        return false;
                lxc_monitord_spawn(c->config_path);
 
-               if (process_lock())
-                       return false;
+               process_lock();
                pid_t pid = fork();
                if (pid < 0) {
                        lxc_container_put(c);
diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c
index 1d6a86c..3307418 100644
--- a/src/lxc/lxclock.c
+++ b/src/lxc/lxclock.c
@@ -271,12 +271,14 @@ void lxc_putlock(struct lxc_lock *l)
        free(l);
 }
 
-int process_lock(void)
+void process_lock(void)
 {
        int ret;
        ret = pthread_mutex_lock(&thread_mutex);
-       if (ret != 0)
+       if (ret != 0) {
                ERROR("pthread_mutex_lock returned:%d %s", ret, strerror(ret));
+               exit(1);
+       }
        return ret;
 }
 
diff --git a/src/lxc/lxclock.h b/src/lxc/lxclock.h
index fae7e4d..dcdf79d 100644
--- a/src/lxc/lxclock.h
+++ b/src/lxc/lxclock.h
@@ -85,7 +85,7 @@ extern int lxcunlock(struct lxc_lock *lock);
 
 extern void lxc_putlock(struct lxc_lock *l);
 
-extern int process_lock(void);
+extern void process_lock(void);
 extern void process_unlock(void);
 struct lxc_container;
 extern int container_mem_lock(struct lxc_container *c);
diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c
index 64e9987..747d6ca 100644
--- a/src/lxc/monitor.c
+++ b/src/lxc/monitor.c
@@ -187,7 +187,9 @@ int lxc_monitor_open(const char *lxcpath)
        if (lxc_monitor_sock_name(lxcpath, &addr) < 0)
                return -1;
 
+       process_lock();
        fd = socket(PF_UNIX, SOCK_STREAM, 0);
+       process_unlock();
        if (fd < 0) {
                ERROR("socket : %s", strerror(errno));
                return -1;
-- 
1.8.3.2


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to