[lxc-devel] [PATCH] put shared variables into thread-local storage

S.Çağlar Onur caglar at 10ur.org
Fri Mar 7 05:04:14 UTC 2014


On Thu, Mar 6, 2014 at 11:58 PM, Serge Hallyn <serge.hallyn at ubuntu.com> wrote:
> Quoting S.Çağlar Onur (caglar at 10ur.org):
>> This doesn't solve the general design problem of the log.c (eg; some log lines
>> got lost or scattered into multiple files) but at least prevent multithreaded
>> code from crashing.
>>
>> Before this change something like following;
>>
>> sudo src/tests/lxc-test-concurrent -i 10 -j 20
>>
>> was crashing nearly all the time due to 3afbcc4600a as we started to
>> set lxc.loglevel and lxc.logfile with that commit.
>>
>> Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
>
> Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

Ahh looks like I forgot lxc_log_fd and that was causing log lines to
scatter around. Putting it into tls solved that issue as well so patch
will follow

>> ---
>>  src/lxc/log.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/src/lxc/log.c b/src/lxc/log.c
>> index 2f880e2..1dd1aa8 100644
>> --- a/src/lxc/log.c
>> +++ b/src/lxc/log.c
>> @@ -41,6 +41,15 @@
>>  #define LXC_LOG_BUFFER_SIZE  512
>>
>>  int lxc_log_fd = -1;
>> +#ifdef HAVE_TLS
>> +static __thread char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
>> +static __thread char *log_fname = NULL;
>> +/* command line values for logfile or logpriority should always override
>> + * values from the configuration file or defaults
>> + */
>> +static __thread int lxc_logfile_specified = 0;
>> +static __thread int lxc_loglevel_specified = 0;
>> +#else
>>  static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
>>  static char *log_fname = NULL;
>>  /* command line values for logfile or logpriority should always override
>> @@ -48,6 +57,7 @@ static char *log_fname = NULL;
>>   */
>>  static int lxc_logfile_specified = 0;
>>  static int lxc_loglevel_specified = 0;
>> +#endif
>>
>>  lxc_log_define(lxc_log, lxc);
>>
>> --
>> 1.8.3.2
>>
>> _______________________________________________
>> lxc-devel mailing list
>> lxc-devel at lists.linuxcontainers.org
>> http://lists.linuxcontainers.org/listinfo/lxc-devel
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel



-- 
S.Çağlar Onur <caglar at 10ur.org>


More information about the lxc-devel mailing list