]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Merge pull request #2039 from brauner/2017-12-14/fix_command_socket_race
authorSerge Hallyn <serge@hallyn.com>
Thu, 14 Dec 2017 21:56:24 +0000 (15:56 -0600)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2017 21:56:24 +0000 (15:56 -0600)
commands: fix race when open()/close() cmd socket

1  2 
src/lxc/start.c

diff --cc src/lxc/start.c
index 5052e2d5a7a9034f014acd1ea56b5962e43a95b8,4911fdde36833bb5eb1cdc0157666acaaf8fa53e..e175076068c433f353fe4cbfa1f918a83bdf7fe2
@@@ -784,15 -753,25 +784,25 @@@ void lxc_fini(const char *name, struct 
  
        cgroup_destroy(handler);
  
-       lxc_set_state(name, handler, STOPPED);
+       /* This function will try to connect to the legacy lxc-monitord state
+        * server and only exists for backwards compatibility.
+        */
+       lxc_monitor_send_state(name, STOPPED, handler->lxcpath);
  
        if (handler->conf->reboot == 0) {
-               /* close command socket */
+               /* For all new state clients simply close the command socket.
+                * This will inform all state clients that the container is
+                * STOPPED and also prevents a race between a open()/close() on
+                * the command socket causing a new process to get ECONNREFUSED
+                * because we haven't yet closed the command socket.
+                */
                close(handler->conf->maincmd_fd);
                handler->conf->maincmd_fd = -1;
+       } else {
+               lxc_set_state(name, handler, STOPPED);
        }
  
 -      if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) {
 +      if (run_lxc_hooks(name, "post-stop", handler->conf, NULL)) {
                ERROR("Failed to run lxc.hook.post-stop for container \"%s\".", name);
                if (handler->conf->reboot) {
                        WARN("Container will be stopped instead of rebooted.");