1. 29 Nov, 2016 4 commits
  2. 28 Nov, 2016 3 commits
    • log: use lxc_unix_epoch_to_utc() · e1378d35
      Christian Brauner authored
      This allows us to generate nice timestamps in a thread-safe manner without
      relying on locale touching functions from any libc.
      Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
    • log: add lxc_unix_epoch_to_utc() · 65a9df89
      Christian Brauner authored
      Converts a unix time Epoch given by a struct timespec to a UTC string useable
      in our logging functions. Maybe expanded to allow for more generic formatting.
      Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
    • log: drop all timezone conversion functions · c57dbb96
      Christian Brauner authored
      Our log functions need to make extra sure that they are thread-safe. We had
      some problems with that before. This especially involves time-conversion
      functions. I don't want to find any localtime() or gmtime() functions or
      relatives in here. Not even localtime_r() or gmtime_r() or relatives. They all
      fiddle with global variables and locking in various libcs. They cause deadlocks
      when liblxc is used multi-threaded and no matter how smart you think you are,
      you __will__ cause trouble using them.
      (As a short example how this can cause trouble: LXD uses forkstart to fork off
      a new process that runs the container. At the same time the go runtime LXD
      relies on does its own multi-threading thing which we can't control. The
      fork()ing + threading then seems to mess with the locking states in these time
      functions causing deadlocks.)
      The current solution is to be good old unix people and use the Epoch as our
      reference point and simply use the seconds and nanoseconds that have past since
      then. This relies on clock_gettime() which is explicitly marked MT-Safe with no
      restrictions! This way, anyone who is really strongly invested in getting the
      actual time the log entry was created, can just convert it for themselves. Our
      logging is mostly done for debugging purposes so don't try to make it pretty.
      Pretty might cost you thread-safety.
      Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
  3. 27 Nov, 2016 7 commits
  4. 26 Nov, 2016 19 commits
  5. 25 Nov, 2016 7 commits
    • Merge pull request #1319 from brauner/2016-11-25/fix_logging_race · 1145b828
      Stéphane Graber authored
      log: fix race
    • configure: do not allow variable length arrays · d8f2dda5
      Christian Brauner authored
      There pointless and marked as optional since C11.
      Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
    • log: use N/A if getpid() != gettid() when threaded · 450b6d3d
      Christian Brauner authored
      Sample log output:
      
          lxc 20161125201943.819 INFO     lxc_start - start.c:lxc_check_inherited:243 - Closed inherited fd: 54.
      --> lxc N/A                INFO     lxc_monitor - monitor.c:lxc_monitor_sock_name:178 - using monitor sock name lxc/ad055575fe28ddd5//var/lib/lxc
          lxc 20161125201943.958 DEBUG    lxc_commands - commands.c:lxc_cmd_handler:893 - peer has disconnected
      --> lxc N/A                DEBUG    lxc_commands - commands.c:lxc_cmd_get_state:579 - 'lxc-test-concurrent-0' is in 'RUNNING' state
          lxc 20161125201943.960 DEBUG    lxc_commands - commands.c:lxc_cmd_handler:893 - peer has disconnected
          lxc 20161125201944.009 INFO     lxc_start - start.c:lxc_check_inherited:243 - Closed inherited fd: 3.
      Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
    • log: fix race · 0dcdbf8a
      Christian Brauner authored
      localtime_r() can lead to deadlocks because it calls __tzset() and
      __tzconvert() internally. The deadlock stems from an interaction between these
      functions and the functions in monitor.c and commands.{c,h}. The latter
      functions will write to the log independent of the container thread that is
      currently running. Since the monitor fork()ed it seems to duplicate the mutex
      states of the time functions mentioned above causing the deadlock.
      As a short termm fix, I suggest to simply disable receiving the time when
      monitor.c or command.{c,h} functions are called. This should be ok, since the
      [lxc monitor] will only emit a few messages and thread-safety is currently more
      important than beautiful logs. The rest of the log stays the same as it was
      before.
      
      Here is an example output from logs where I printed the pid and tid of the
      process that is currently writing to the log:
      
                  lxc 20161125170200.619 INFO     lxc_start:   18695-18695: - start.c:lxc_check_inherited:243 - Closed inherited fd: 23.
                  lxc 20161125170200.640 DEBUG    lxc_start:   18677-18677: - start.c:__lxc_start:1334 - Not dropping CAP_SYS_BOOT or watching utmp.
                  lxc 20161125170200.640 INFO     lxc_cgroup:  18677-18677: - cgroups/cgroup.c:cgroup_init:68 - cgroup driver cgroupfs-ng initing for lxc-test-concurrent-0
      
      ----------> lxc 20150427012246.000 INFO     lxc_monitor: 13017-18622: - monitor.c:lxc_monitor_sock_name:178 - using monitor sock name lxc/ad055575fe28ddd5//var/lib/lxc
      
                  lxc 20161125170200.662 DEBUG    lxc_cgfsng:  18677-18677: - cgroups/cgfsng.c:filter_and_set_cpus:478 - No isolated cpus detected.
                  lxc 20161125170200.662 DEBUG    lxc_cgfsng:  18677-18677: - cgroups/cgfsng.c:handle_cpuset_hierarchy:648 - "cgroup.clone_children" was already set to "1".
      Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
    • Merge pull request #1317 from brauner/2016-11-24/cleanup_attach · 8d3786cb
      Stéphane Graber authored
      cleanup attach
    • Merge pull request #1318 from brauner/2016-11-25/fix_logging_race · b5e39501
      Stéphane Graber authored
      log: use thread-safe localtime_r()