[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [BUG] libxl_ctx_free calls close(0)



Hello,

it seems that libxl_ctx_free always calls close(0) for some
reason, even if libxl never opens file descriptor 0. It sometimes
closes valid descriptor in application causing random and
hard to debug I/O errors.

The following simple program can be used to reproduce this bug:

#include <stdio.h>
#include <libxl.h>

static void LogMessage(struct xentoollog_logger *logger,
                     xentoollog_level level,
                     int errnoval /* or -1 */,
                     const char *context /* eg "xc", "xl", may be 0 */,
                     const char *format /* without level, context, \n
*/,
                     va_list al)
{
}

static void LogProgress(struct xentoollog_logger *logger,
                     const char *context /* see above */,
                     const char *doing_what /* no \r,\n */,
                     int percent, unsigned long done, unsigned long
total)
{
}

static void LogDestroy(struct xentoollog_logger *logger)
{
}


int main(int argc, char *argv[])
{
   xentoollog_logger logger;
   logger.vmessage = LogMessage;
   logger.progress = LogProgress;
   logger.destroy = LogDestroy;

   libxl_ctx *ctx;
   int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, &logger);
   if (rc != 0)
   {
      printf("libxl_ctx_alloc failed (%d)\n", rc);
      return 1;
   }


   libxl_ctx_free(ctx);
   return 0;
}

Strace output for it is following (I omit shared library 
loading on startup):

set_tid_address(0x7f787db29a50)         = 17944
set_robust_list(0x7f787db29a60, 24)     = 0
rt_sigaction(SIGRTMIN, {0x7f787c4809b0, [], SA_RESTORER|SA_SIGINFO,
0x7f787c489890}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7f787c480a40, [],
SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f787c489890}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY})
= 0
brk(0)                                  = 0x156d000
brk(0x158e000)                          = 0x158e000
pipe([3, 4])                            = 0
fcntl(3, F_GETFL)                       = 0 (flags O_RDONLY)
fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0
fcntl(4, F_GETFL)                       = 0x1 (flags O_WRONLY)
fcntl(4, F_SETFL, O_WRONLY|O_NONBLOCK)  = 0
open("/proc/xen/privcmd", O_RDWR)       = 5
fcntl(5, F_GETFD)                       = 0
fcntl(5, F_SETFD, FD_CLOEXEC)           = 0
stat("/var/run/xenstored/socket", {st_mode=S_IFSOCK|0600, st_size=0,
...}) = 0
socket(PF_LOCAL, SOCK_STREAM, 0)        = 6
fcntl(6, F_GETFD)                       = 0
fcntl(6, F_SETFD, FD_CLOEXEC)           = 0
connect(6, {sa_family=AF_LOCAL, sun_path="/var/run/xenstored/socket"},
110) = 0
close(5)                                = 0
close(6)                                = 0
close(3)                                = 0
close(4)                                = 0
close(0)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

Best regards,
Victor Kirhenshtein


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.