debuggers.hg

changeset 20817:5a5c2ed76aaf

libxenlight: don't ignore ctx_init errors if there is one.

ctx_init can return error, and ignoring the errors, would lead to
segfault later. fix all call sites to check return values.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 08 11:44:15 2010 +0000 (2010-01-08)
parents f909045c2284
children 5254234fdb71
files tools/libxl/xl.c
line diff
     1.1 --- a/tools/libxl/xl.c	Fri Jan 08 11:39:33 2010 +0000
     1.2 +++ b/tools/libxl/xl.c	Fri Jan 08 11:44:15 2010 +0000
     1.3 @@ -762,7 +762,11 @@ static void create_domain(int debug, int
     1.4  start:
     1.5      domid = 0;
     1.6  
     1.7 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
     1.8 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
     1.9 +        fprintf(stderr, "cannot init xl context\n");
    1.10 +        return;
    1.11 +    }
    1.12 +
    1.13      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.14      libxl_domain_make(&ctx, &info1, &domid);
    1.15  
    1.16 @@ -974,7 +978,10 @@ void set_memory_target(char *p, char *me
    1.17      struct libxl_ctx ctx;
    1.18      uint32_t domid;
    1.19  
    1.20 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
    1.21 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
    1.22 +        fprintf(stderr, "cannot init xl context\n");
    1.23 +        return;
    1.24 +    }
    1.25      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.26  
    1.27      if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
    1.28 @@ -1016,7 +1023,10 @@ void console(char *p, int cons_num)
    1.29      struct libxl_ctx ctx;
    1.30      uint32_t domid;
    1.31  
    1.32 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
    1.33 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
    1.34 +        fprintf(stderr, "cannot init xl context\n");
    1.35 +        return;
    1.36 +    }
    1.37      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.38  
    1.39      if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
    1.40 @@ -1033,7 +1043,10 @@ void cd_insert(char *dom, char *virtdev,
    1.41      libxl_device_disk disk;
    1.42      char *p;
    1.43  
    1.44 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
    1.45 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
    1.46 +        fprintf(stderr, "cannot init xl context\n");
    1.47 +        return;
    1.48 +    }
    1.49      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.50  
    1.51      if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
    1.52 @@ -1166,7 +1179,10 @@ void pcilist(char *dom)
    1.53      libxl_device_pci *pcidevs;
    1.54      int num, i;
    1.55  
    1.56 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
    1.57 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
    1.58 +        fprintf(stderr, "cannot init xl context\n");
    1.59 +        return;
    1.60 +    }
    1.61      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.62  
    1.63      if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
    1.64 @@ -1216,7 +1232,10 @@ void pcidetach(char *dom, char *bdf)
    1.65      libxl_device_pci pcidev;
    1.66      unsigned int domain, bus, dev, func;
    1.67  
    1.68 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
    1.69 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
    1.70 +        fprintf(stderr, "cannot init xl context\n");
    1.71 +        return;
    1.72 +    }
    1.73      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.74  
    1.75      if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
    1.76 @@ -1262,7 +1281,10 @@ void pciattach(char *dom, char *bdf, cha
    1.77      libxl_device_pci pcidev;
    1.78      unsigned int domain, bus, dev, func;
    1.79  
    1.80 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
    1.81 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
    1.82 +        fprintf(stderr, "cannot init xl context\n");
    1.83 +        return;
    1.84 +    }
    1.85      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.86  
    1.87      if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
    1.88 @@ -1310,7 +1332,10 @@ void pause_domain(char *p)
    1.89      struct libxl_ctx ctx;
    1.90      uint32_t domid;
    1.91  
    1.92 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
    1.93 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
    1.94 +        fprintf(stderr, "cannot init xl context\n");
    1.95 +        return;
    1.96 +    }
    1.97      libxl_ctx_set_log(&ctx, log_callback, NULL);
    1.98  
    1.99      if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
   1.100 @@ -1325,7 +1350,10 @@ void unpause_domain(char *p)
   1.101      struct libxl_ctx ctx;
   1.102      uint32_t domid;
   1.103  
   1.104 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
   1.105 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
   1.106 +        fprintf(stderr, "cannot init xl context\n");
   1.107 +        return;
   1.108 +    }
   1.109      libxl_ctx_set_log(&ctx, log_callback, NULL);
   1.110  
   1.111      if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
   1.112 @@ -1340,7 +1368,10 @@ void destroy_domain(char *p)
   1.113      struct libxl_ctx ctx;
   1.114      uint32_t domid;
   1.115  
   1.116 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
   1.117 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
   1.118 +        fprintf(stderr, "cannot init xl context\n");
   1.119 +        return;
   1.120 +    }
   1.121      libxl_ctx_set_log(&ctx, log_callback, NULL);
   1.122  
   1.123      if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
   1.124 @@ -1356,7 +1387,10 @@ void list_domains(void)
   1.125      struct libxl_dominfo *info;
   1.126      int nb_domain, i;
   1.127  
   1.128 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
   1.129 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
   1.130 +        fprintf(stderr, "cannot init xl context\n");
   1.131 +        return;
   1.132 +    }
   1.133      libxl_ctx_set_log(&ctx, log_callback, NULL);
   1.134  
   1.135      info = libxl_domain_list(&ctx, &nb_domain);
   1.136 @@ -1383,7 +1417,10 @@ int save_domain(char *p, char *filename,
   1.137      uint32_t domid;
   1.138      int fd;
   1.139  
   1.140 -    libxl_ctx_init(&ctx, LIBXL_VERSION);
   1.141 +    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
   1.142 +        fprintf(stderr, "cannot init xl context\n");
   1.143 +        exit(2);
   1.144 +    }
   1.145      libxl_ctx_set_log(&ctx, log_callback, NULL);
   1.146  
   1.147      if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {