debuggers.hg

changeset 21944:bb187c5a7fbc

xl: return(N) from individual commands to top level instead of exit(N)

This allows the top level command dispatcher to cleanup some of its
own allocations.

This is a fairly mechanical conversion of exit(FOO) into return FOO
for the top-level command functions (i.e. main_*). There are still
code paths which will exit() further down the call chains which will
require actual thought.

At first glance not all the return codes are which one would normally
expect for process exit codes (e.g. some are negative) but I didn't
attempt to address that here.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Fri Jul 30 15:15:24 2010 +0100 (2010-07-30)
parents 84f8ad68bc58
children 5b52397e10dc
files tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/xl_cmdimpl.c	Fri Jul 30 15:12:56 2010 +0100
     1.2 +++ b/tools/libxl/xl_cmdimpl.c	Fri Jul 30 15:15:24 2010 +0100
     1.3 @@ -1701,7 +1701,7 @@ int main_memmax(int argc, char **argv)
     1.4      }
     1.5      if (optind >= argc - 1) {
     1.6          help("mem-max");
     1.7 -        exit(2);
     1.8 +        return 2;
     1.9      }
    1.10  
    1.11      p = argv[optind];
    1.12 @@ -1710,10 +1710,10 @@ int main_memmax(int argc, char **argv)
    1.13      rc = set_memory_max(p, mem);
    1.14      if (rc) {
    1.15          fprintf(stderr, "cannot set domid %d static max memory to : %s\n", domid, mem);
    1.16 -        exit(1);
    1.17 -    }
    1.18 -
    1.19 -    exit(0);
    1.20 +        return 1;
    1.21 +    }
    1.22 +
    1.23 +    return 0;
    1.24  }
    1.25  
    1.26  void set_memory_target(char *p, char *mem)
    1.27 @@ -1740,7 +1740,7 @@ int main_memset(int argc, char **argv)
    1.28          switch (opt) {
    1.29          case 'h':
    1.30              help("mem-set");
    1.31 -            exit(0);
    1.32 +            return 0;
    1.33          default:
    1.34              fprintf(stderr, "option not supported\n");
    1.35              break;
    1.36 @@ -1748,14 +1748,14 @@ int main_memset(int argc, char **argv)
    1.37      }
    1.38      if (optind >= argc - 1) {
    1.39          help("mem-set");
    1.40 -        exit(2);
    1.41 +        return 2;
    1.42      }
    1.43  
    1.44      p = argv[optind];
    1.45      mem = argv[optind + 1];
    1.46  
    1.47      set_memory_target(p, mem);
    1.48 -    exit(0);
    1.49 +    return 0;
    1.50  }
    1.51  
    1.52  void cd_insert(char *dom, char *virtdev, char *phys)
    1.53 @@ -1806,7 +1806,7 @@ int main_cd_eject(int argc, char **argv)
    1.54          switch (opt) {
    1.55          case 'h':
    1.56              help("cd-eject");
    1.57 -            exit(0);
    1.58 +            return 0;
    1.59          default:
    1.60              fprintf(stderr, "option not supported\n");
    1.61              break;
    1.62 @@ -1814,14 +1814,14 @@ int main_cd_eject(int argc, char **argv)
    1.63      }
    1.64      if (optind >= argc - 1) {
    1.65          help("cd-eject");
    1.66 -        exit(2);
    1.67 +        return 2;
    1.68      }
    1.69  
    1.70      p = argv[optind];
    1.71      virtdev = argv[optind + 1];
    1.72  
    1.73      cd_insert(p, virtdev, NULL);
    1.74 -    exit(0);
    1.75 +    return 0;
    1.76  }
    1.77  
    1.78  int main_cd_insert(int argc, char **argv)
    1.79 @@ -1833,7 +1833,7 @@ int main_cd_insert(int argc, char **argv
    1.80          switch (opt) {
    1.81          case 'h':
    1.82              help("cd-insert");
    1.83 -            exit(0);
    1.84 +            return 0;
    1.85          default:
    1.86              fprintf(stderr, "option not supported\n");
    1.87              break;
    1.88 @@ -1841,7 +1841,7 @@ int main_cd_insert(int argc, char **argv
    1.89      }
    1.90      if (optind >= argc - 2) {
    1.91          help("cd-insert");
    1.92 -        exit(2);
    1.93 +        return 2;
    1.94      }
    1.95  
    1.96      p = argv[optind];
    1.97 @@ -1849,7 +1849,7 @@ int main_cd_insert(int argc, char **argv
    1.98      file = argv[optind + 2];
    1.99  
   1.100      cd_insert(p, virtdev, file);
   1.101 -    exit(0);
   1.102 +    return 0;
   1.103  }
   1.104  
   1.105  int main_console(int argc, char **argv)
   1.106 @@ -1860,7 +1860,7 @@ int main_console(int argc, char **argv)
   1.107          switch (opt) {
   1.108          case 'h':
   1.109              help("console");
   1.110 -            exit(0);
   1.111 +            return 0;
   1.112          default:
   1.113              fprintf(stderr, "option not supported\n");
   1.114              break;
   1.115 @@ -1868,7 +1868,7 @@ int main_console(int argc, char **argv)
   1.116      }
   1.117      if (optind >= argc) {
   1.118          help("console");
   1.119 -        exit(2);
   1.120 +        return 2;
   1.121      }
   1.122  
   1.123      find_domain(argv[optind]);
   1.124 @@ -1906,7 +1906,7 @@ int main_vncviewer(int argc, char **argv
   1.125              break;
   1.126          case 'h':
   1.127              help("vncviewer");
   1.128 -            exit(0);
   1.129 +            return 0;
   1.130          default:
   1.131              fprintf(stderr, "option not supported\n");
   1.132              break;
   1.133 @@ -1915,12 +1915,12 @@ int main_vncviewer(int argc, char **argv
   1.134  
   1.135      if (argc - optind != 1) {
   1.136          help("vncviewer");
   1.137 -        exit(2);
   1.138 +        return 2;
   1.139      }
   1.140  
   1.141      if (vncviewer(argv[optind], autopass))
   1.142 -        exit(1);
   1.143 -    exit(0);
   1.144 +        return 1;
   1.145 +    return 0;
   1.146  }
   1.147  
   1.148  void pcilist_assignable(void)
   1.149 @@ -1945,7 +1945,7 @@ int main_pcilist_assignable(int argc, ch
   1.150          switch (opt) {
   1.151          case 'h':
   1.152              help("pci-list-assignable-devices");
   1.153 -            exit(0);
   1.154 +            return 0;
   1.155          default:
   1.156              fprintf(stderr, "option not supported\n");
   1.157              break;
   1.158 @@ -1953,7 +1953,7 @@ int main_pcilist_assignable(int argc, ch
   1.159      }
   1.160  
   1.161      pcilist_assignable();
   1.162 -    exit(0);
   1.163 +    return 0;
   1.164  }
   1.165  
   1.166  void pcilist(char *dom)
   1.167 @@ -1981,7 +1981,7 @@ int main_pcilist(int argc, char **argv)
   1.168          switch (opt) {
   1.169          case 'h':
   1.170              help("pci-list");
   1.171 -            exit(0);
   1.172 +            return 0;
   1.173          default:
   1.174              fprintf(stderr, "option not supported\n");
   1.175              break;
   1.176 @@ -1989,13 +1989,13 @@ int main_pcilist(int argc, char **argv)
   1.177      }
   1.178      if (optind >= argc) {
   1.179          help("pci-list");
   1.180 -        exit(2);
   1.181 +        return 2;
   1.182      }
   1.183  
   1.184      domname = argv[optind];
   1.185  
   1.186      pcilist(domname);
   1.187 -    exit(0);
   1.188 +    return 0;
   1.189  }
   1.190  
   1.191  void pcidetach(char *dom, char *bdf)
   1.192 @@ -2023,7 +2023,7 @@ int main_pcidetach(int argc, char **argv
   1.193          switch (opt) {
   1.194          case 'h':
   1.195              help("pci-detach");
   1.196 -            exit(0);
   1.197 +            return 0;
   1.198          default:
   1.199              fprintf(stderr, "option not supported\n");
   1.200              break;
   1.201 @@ -2031,14 +2031,14 @@ int main_pcidetach(int argc, char **argv
   1.202      }
   1.203      if (optind >= argc - 1) {
   1.204          help("pci-detach");
   1.205 -        exit(2);
   1.206 +        return 2;
   1.207      }
   1.208  
   1.209      domname = argv[optind];
   1.210      bdf = argv[optind + 1];
   1.211  
   1.212      pcidetach(domname, bdf);
   1.213 -    exit(0);
   1.214 +    return 0;
   1.215  }
   1.216  void pciattach(char *dom, char *bdf, char *vs)
   1.217  {
   1.218 @@ -2065,7 +2065,7 @@ int main_pciattach(int argc, char **argv
   1.219          switch (opt) {
   1.220          case 'h':
   1.221              help("pci-attach");
   1.222 -            exit(0);
   1.223 +            return 0;
   1.224          default:
   1.225              fprintf(stderr, "option not supported\n");
   1.226              break;
   1.227 @@ -2073,7 +2073,7 @@ int main_pciattach(int argc, char **argv
   1.228      }
   1.229      if (optind >= argc - 1) {
   1.230          help("pci-attach");
   1.231 -        exit(2);
   1.232 +        return 2;
   1.233      }
   1.234  
   1.235      domname = argv[optind];
   1.236 @@ -2083,7 +2083,7 @@ int main_pciattach(int argc, char **argv
   1.237          vs = argv[optind + 2];
   1.238  
   1.239      pciattach(domname, bdf, vs);
   1.240 -    exit(0);
   1.241 +    return 0;
   1.242  }
   1.243  
   1.244  void pause_domain(char *p)
   1.245 @@ -2673,7 +2673,7 @@ int main_restore(int argc, char **argv)
   1.246              break;
   1.247          case 'h':
   1.248              help("restore");
   1.249 -            exit(0);
   1.250 +            return 0;
   1.251          default:
   1.252              fprintf(stderr, "option not supported\n");
   1.253              break;
   1.254 @@ -2687,7 +2687,7 @@ int main_restore(int argc, char **argv)
   1.255          checkpoint_file = argv[optind + 1];
   1.256      } else {
   1.257          help("restore");
   1.258 -        exit(2);
   1.259 +        return 2;
   1.260      }
   1.261  
   1.262      memset(&dom_info, 0, sizeof(dom_info));
   1.263 @@ -2700,9 +2700,9 @@ int main_restore(int argc, char **argv)
   1.264  
   1.265      rc = create_domain(&dom_info);
   1.266      if (rc < 0)
   1.267 -        exit(-rc);
   1.268 -
   1.269 -    exit(0);
   1.270 +        return -rc;
   1.271 +
   1.272 +    return 0;
   1.273  }
   1.274  
   1.275  int main_migrate_receive(int argc, char **argv)
   1.276 @@ -2714,7 +2714,7 @@ int main_migrate_receive(int argc, char 
   1.277          switch (opt) {
   1.278          case 'h':
   1.279              help("migrate-receive");
   1.280 -            exit(2);
   1.281 +            return 2;
   1.282              break;
   1.283          case 'e':
   1.284              daemonize = 0;
   1.285 @@ -2730,10 +2730,10 @@ int main_migrate_receive(int argc, char 
   1.286  
   1.287      if (argc-optind != 0) {
   1.288          help("migrate-receive");
   1.289 -        exit(2);
   1.290 +        return 2;
   1.291      }
   1.292      migrate_receive(debug, daemonize);
   1.293 -    exit(0);
   1.294 +    return 0;
   1.295  }
   1.296  
   1.297  int main_save(int argc, char **argv)
   1.298 @@ -2750,7 +2750,7 @@ int main_save(int argc, char **argv)
   1.299              break;
   1.300          case 'h':
   1.301              help("save");
   1.302 -            exit(0);
   1.303 +            return 0;
   1.304          default:
   1.305              fprintf(stderr, "option not supported\n");
   1.306              break;
   1.307 @@ -2759,14 +2759,14 @@ int main_save(int argc, char **argv)
   1.308  
   1.309      if (argc-optind < 1 || argc-optind > 3) {
   1.310          help("save");
   1.311 -        exit(2);
   1.312 +        return 2;
   1.313      }
   1.314  
   1.315      p = argv[optind];
   1.316      filename = argv[optind + 1];
   1.317      config_filename = argv[optind + 2];
   1.318      save_domain(p, filename, checkpoint, config_filename);
   1.319 -    exit(0);
   1.320 +    return 0;
   1.321  }
   1.322  
   1.323  int main_migrate(int argc, char **argv)
   1.324 @@ -2782,7 +2782,7 @@ int main_migrate(int argc, char **argv)
   1.325          switch (opt) {
   1.326          case 'h':
   1.327              help("migrate");
   1.328 -            exit(0);
   1.329 +            return 0;
   1.330          case 'C':
   1.331              config_filename = optarg;
   1.332              break;
   1.333 @@ -2803,7 +2803,7 @@ int main_migrate(int argc, char **argv)
   1.334  
   1.335      if (argc-optind < 2 || argc-optind > 2) {
   1.336          help("migrate");
   1.337 -        exit(2);
   1.338 +        return 2;
   1.339      }
   1.340  
   1.341      p = argv[optind];
   1.342 @@ -2816,21 +2816,21 @@ int main_migrate(int argc, char **argv)
   1.343                       ssh_command, host,
   1.344                       daemonize ? "" : " -e",
   1.345                       debug ? " -d" : "") < 0)
   1.346 -            exit(1);
   1.347 +            return 1;
   1.348      }
   1.349  
   1.350      migrate_domain(p, rune, config_filename);
   1.351 -    exit(0);
   1.352 +    return 0;
   1.353  }
   1.354  
   1.355  int main_dump_core(int argc, char **argv)
   1.356  {
   1.357      if ( argc-optind < 2 ) {
   1.358          help("dump-core");
   1.359 -        exit(2);
   1.360 +        return 2;
   1.361      }
   1.362      core_dump_domain(argv[optind], argv[optind + 1]);
   1.363 -    exit(0);
   1.364 +    return 0;
   1.365  }
   1.366  
   1.367  int main_pause(int argc, char **argv)
   1.368 @@ -2843,7 +2843,7 @@ int main_pause(int argc, char **argv)
   1.369          switch (opt) {
   1.370          case 'h':
   1.371              help("pause");
   1.372 -            exit(0);
   1.373 +            return 0;
   1.374          default:
   1.375              fprintf(stderr, "option not supported\n");
   1.376              break;
   1.377 @@ -2851,13 +2851,13 @@ int main_pause(int argc, char **argv)
   1.378      }
   1.379      if (optind >= argc) {
   1.380          help("pause");
   1.381 -        exit(2);
   1.382 +        return 2;
   1.383      }
   1.384  
   1.385      p = argv[optind];
   1.386  
   1.387      pause_domain(p);
   1.388 -    exit(0);
   1.389 +    return 0;
   1.390  }
   1.391  
   1.392  int main_unpause(int argc, char **argv)
   1.393 @@ -2870,7 +2870,7 @@ int main_unpause(int argc, char **argv)
   1.394          switch (opt) {
   1.395          case 'h':
   1.396              help("unpause");
   1.397 -            exit(0);
   1.398 +            return 0;
   1.399          default:
   1.400              fprintf(stderr, "option not supported\n");
   1.401              break;
   1.402 @@ -2878,13 +2878,13 @@ int main_unpause(int argc, char **argv)
   1.403      }
   1.404      if (optind >= argc) {
   1.405          help("unpause");
   1.406 -        exit(2);
   1.407 +        return 2;
   1.408      }
   1.409  
   1.410      p = argv[optind];
   1.411  
   1.412      unpause_domain(p);
   1.413 -    exit(0);
   1.414 +    return 0;
   1.415  }
   1.416  
   1.417  int main_destroy(int argc, char **argv)
   1.418 @@ -2896,7 +2896,7 @@ int main_destroy(int argc, char **argv)
   1.419          switch (opt) {
   1.420          case 'h':
   1.421              help("destroy");
   1.422 -            exit(0);
   1.423 +            return 0;
   1.424          default:
   1.425              fprintf(stderr, "option not supported\n");
   1.426              break;
   1.427 @@ -2904,13 +2904,13 @@ int main_destroy(int argc, char **argv)
   1.428      }
   1.429      if (optind >= argc) {
   1.430          help("destroy");
   1.431 -        exit(2);
   1.432 +        return 2;
   1.433      }
   1.434  
   1.435      p = argv[optind];
   1.436  
   1.437      destroy_domain(p);
   1.438 -    exit(0);
   1.439 +    return 0;
   1.440  }
   1.441  
   1.442  int main_shutdown(int argc, char **argv)
   1.443 @@ -2922,7 +2922,7 @@ int main_shutdown(int argc, char **argv)
   1.444          switch (opt) {
   1.445          case 'h':
   1.446              help("shutdown");
   1.447 -            exit(0);
   1.448 +            return 0;
   1.449          default:
   1.450              fprintf(stderr, "option not supported\n");
   1.451              break;
   1.452 @@ -2930,13 +2930,13 @@ int main_shutdown(int argc, char **argv)
   1.453      }
   1.454      if (optind >= argc) {
   1.455          help("shutdown");
   1.456 -        exit(2);
   1.457 +        return 2;
   1.458      }
   1.459  
   1.460      p = argv[optind];
   1.461  
   1.462      shutdown_domain(p);
   1.463 -    exit(0);
   1.464 +    return 0;
   1.465  }
   1.466  
   1.467  int main_reboot(int argc, char **argv)
   1.468 @@ -2948,7 +2948,7 @@ int main_reboot(int argc, char **argv)
   1.469          switch (opt) {
   1.470          case 'h':
   1.471              help("reboot");
   1.472 -            exit(0);
   1.473 +            return 0;
   1.474          default:
   1.475              fprintf(stderr, "option not supported\n");
   1.476              break;
   1.477 @@ -2956,13 +2956,13 @@ int main_reboot(int argc, char **argv)
   1.478      }
   1.479      if (optind >= argc) {
   1.480          help("reboot");
   1.481 -        exit(2);
   1.482 +        return 2;
   1.483      }
   1.484  
   1.485      p = argv[optind];
   1.486  
   1.487      reboot_domain(p);
   1.488 -    exit(0);
   1.489 +    return 0;
   1.490  }
   1.491  int main_list(int argc, char **argv)
   1.492  {
   1.493 @@ -2991,7 +2991,7 @@ int main_list(int argc, char **argv)
   1.494              break;
   1.495          case 'h':
   1.496              help("list");
   1.497 -            exit(0);
   1.498 +            return 0;
   1.499          case 'v':
   1.500              verbose = 1;
   1.501              break;
   1.502 @@ -3005,7 +3005,7 @@ int main_list(int argc, char **argv)
   1.503          info = libxl_list_domain(&ctx, &nb_domain);
   1.504          if (!info) {
   1.505              fprintf(stderr, "libxl_domain_infolist failed.\n");
   1.506 -            exit(1);
   1.507 +            return 1;
   1.508          }
   1.509          info_free = info;
   1.510      } else if (optind == argc-1) {
   1.511 @@ -3013,13 +3013,13 @@ int main_list(int argc, char **argv)
   1.512          rc = libxl_domain_info(&ctx, &info_buf, domid);
   1.513          if (rc) {
   1.514              fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc);
   1.515 -            exit(-rc);
   1.516 +            return -rc;
   1.517          }
   1.518          info = &info_buf;
   1.519          nb_domain = 1;
   1.520      } else {
   1.521          help("list");
   1.522 -        exit(2);
   1.523 +        return 2;
   1.524      }
   1.525  
   1.526      if (details)
   1.527 @@ -3029,7 +3029,7 @@ int main_list(int argc, char **argv)
   1.528  
   1.529      free(info_free);
   1.530  
   1.531 -    exit(0);
   1.532 +    return 0;
   1.533  }
   1.534  
   1.535  int main_list_vm(int argc, char **argv)
   1.536 @@ -3040,7 +3040,7 @@ int main_list_vm(int argc, char **argv)
   1.537          switch (opt) {
   1.538          case 'h':
   1.539              help("list-vm");
   1.540 -            exit(0);
   1.541 +            return 0;
   1.542          default:
   1.543              fprintf(stderr, "option not supported\n");
   1.544              break;
   1.545 @@ -3048,7 +3048,7 @@ int main_list_vm(int argc, char **argv)
   1.546      }
   1.547  
   1.548      list_vm();
   1.549 -    exit(0);
   1.550 +    return 0;
   1.551  }
   1.552  
   1.553  int main_create(int argc, char **argv)
   1.554 @@ -3091,7 +3091,7 @@ int main_create(int argc, char **argv)
   1.555              break;
   1.556          case 'h':
   1.557              help("create");
   1.558 -            exit(0);
   1.559 +            return 0;
   1.560          case 'n':
   1.561              dryrun = 1;
   1.562              break;
   1.563 @@ -3116,7 +3116,7 @@ int main_create(int argc, char **argv)
   1.564              filename = argv[optind];
   1.565          } else {
   1.566              help("create");
   1.567 -            exit(2);
   1.568 +            return 2;
   1.569          }
   1.570          optind++;
   1.571      }
   1.572 @@ -3134,9 +3134,9 @@ int main_create(int argc, char **argv)
   1.573  
   1.574      rc = create_domain(&dom_info);
   1.575      if (rc < 0)
   1.576 -        exit(-rc);
   1.577 -
   1.578 -    exit(0);
   1.579 +        return -rc;
   1.580 +
   1.581 +    return 0;
   1.582  }
   1.583  
   1.584  void button_press(char *p, char *b)
   1.585 @@ -3167,7 +3167,7 @@ int main_button_press(int argc, char **a
   1.586          switch (opt) {
   1.587          case 'h':
   1.588              help("button-press");
   1.589 -            exit(0);
   1.590 +            return 0;
   1.591          default:
   1.592              fprintf(stderr, "option not supported\n");
   1.593              break;
   1.594 @@ -3175,14 +3175,14 @@ int main_button_press(int argc, char **a
   1.595      }
   1.596      if (optind >= argc - 1) {
   1.597          help("button-press");
   1.598 -        exit(2);
   1.599 +        return 2;
   1.600      }
   1.601  
   1.602      p = argv[optind];
   1.603      b = argv[optind + 1];
   1.604  
   1.605      button_press(p, b);
   1.606 -    exit(0);
   1.607 +    return 0;
   1.608  }
   1.609  
   1.610  static void print_vcpuinfo(uint32_t tdomid,
   1.611 @@ -3304,7 +3304,7 @@ int main_vcpulist(int argc, char **argv)
   1.612          switch (opt) {
   1.613          case 'h':
   1.614              help("vcpu-list");
   1.615 -            exit(0);
   1.616 +            return 0;
   1.617          default:
   1.618              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.619              break;
   1.620 @@ -3312,7 +3312,7 @@ int main_vcpulist(int argc, char **argv)
   1.621      }
   1.622  
   1.623      vcpulist(argc - 2, argv + 2);
   1.624 -    exit(0);
   1.625 +    return 0;
   1.626  }
   1.627  
   1.628  void vcpupin(char *d, const char *vcpu, char *cpu)
   1.629 @@ -3402,13 +3402,13 @@ int main_vcpupin(int argc, char **argv)
   1.630  
   1.631      if (argc != 5) {
   1.632          help("vcpu-pin");
   1.633 -        exit(0);
   1.634 +        return 0;
   1.635      }
   1.636      while ((opt = getopt(argc, argv, "h")) != -1) {
   1.637          switch (opt) {
   1.638          case 'h':
   1.639              help("vcpu-pin");
   1.640 -            exit(0);
   1.641 +            return 0;
   1.642          default:
   1.643              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.644              break;
   1.645 @@ -3416,7 +3416,7 @@ int main_vcpupin(int argc, char **argv)
   1.646      }
   1.647  
   1.648      vcpupin(argv[2], argv[3] , argv[4]);
   1.649 -    exit(0);
   1.650 +    return 0;
   1.651  }
   1.652  
   1.653  void vcpuset(char *d, char* nr_vcpus)
   1.654 @@ -3443,13 +3443,13 @@ int main_vcpuset(int argc, char **argv)
   1.655  
   1.656      if (argc != 4) {
   1.657          help("vcpu-set");
   1.658 -        exit(0);
   1.659 +        return 0;
   1.660      }
   1.661      while ((opt = getopt(argc, argv, "h")) != -1) {
   1.662          switch (opt) {
   1.663          case 'h':
   1.664          help("vcpu-set");
   1.665 -            exit(0);
   1.666 +            return 0;
   1.667          default:
   1.668              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.669              break;
   1.670 @@ -3457,7 +3457,7 @@ int main_vcpuset(int argc, char **argv)
   1.671      }
   1.672  
   1.673      vcpuset(argv[2], argv[3]);
   1.674 -    exit(0);
   1.675 +    return 0;
   1.676  }
   1.677  
   1.678  static void output_xeninfo(void)
   1.679 @@ -3564,7 +3564,7 @@ int main_info(int argc, char **argv)
   1.680          switch (opt) {
   1.681          case 'h':
   1.682              help("info");
   1.683 -            exit(0);
   1.684 +            return 0;
   1.685          default:
   1.686              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.687              break;
   1.688 @@ -3572,7 +3572,7 @@ int main_info(int argc, char **argv)
   1.689      }
   1.690  
   1.691      info();
   1.692 -    exit(0);
   1.693 +    return 0;
   1.694  }
   1.695  
   1.696  static int sched_credit_domain_get(
   1.697 @@ -3633,7 +3633,7 @@ int main_sched_credit(int argc, char **a
   1.698              break;
   1.699          case 'h':
   1.700              help("sched-credit");
   1.701 -            exit(0);
   1.702 +            return 0;
   1.703          default:
   1.704              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.705              break;
   1.706 @@ -3642,21 +3642,21 @@ int main_sched_credit(int argc, char **a
   1.707  
   1.708      if (!dom && (opt_w || opt_c)) {
   1.709          fprintf(stderr, "Must specify a domain.\n");
   1.710 -        exit(1);
   1.711 +        return 1;
   1.712      }
   1.713  
   1.714      if (!dom) { /* list all domain's credit scheduler info */
   1.715          info = libxl_list_domain(&ctx, &nb_domain);
   1.716          if (!info) {
   1.717              fprintf(stderr, "libxl_domain_infolist failed.\n");
   1.718 -            exit(1);
   1.719 +            return 1;
   1.720          }
   1.721  
   1.722          printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap");
   1.723          for (i = 0; i < nb_domain; i++) {
   1.724              rc = sched_credit_domain_get(info[i].domid, &scinfo);
   1.725              if (rc)
   1.726 -                exit(-rc);
   1.727 +                return -rc;
   1.728              sched_credit_domain_output(info[i].domid, &scinfo);
   1.729          }
   1.730      } else {
   1.731 @@ -3664,7 +3664,7 @@ int main_sched_credit(int argc, char **a
   1.732  
   1.733          rc = sched_credit_domain_get(domid, &scinfo);
   1.734          if (rc)
   1.735 -            exit(-rc);
   1.736 +            return -rc;
   1.737  
   1.738          if (!opt_w && !opt_c) { /* output credit scheduler info */
   1.739              printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap");
   1.740 @@ -3676,11 +3676,11 @@ int main_sched_credit(int argc, char **a
   1.741                  scinfo.cap = cap;
   1.742              rc = sched_credit_domain_set(domid, &scinfo);
   1.743              if (rc)
   1.744 -                exit(-rc);
   1.745 +                return -rc;
   1.746          }
   1.747      }
   1.748  
   1.749 -    exit(0);
   1.750 +    return 0;
   1.751  }
   1.752  
   1.753  int main_domid(int argc, char **argv)
   1.754 @@ -3692,7 +3692,7 @@ int main_domid(int argc, char **argv)
   1.755          switch (opt) {
   1.756          case 'h':
   1.757              help("domid");
   1.758 -            exit(0);
   1.759 +            return 0;
   1.760          default:
   1.761              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.762              break;
   1.763 @@ -3703,17 +3703,17 @@ int main_domid(int argc, char **argv)
   1.764      if (!domname) {
   1.765          fprintf(stderr, "Must specify a domain name.\n\n");
   1.766          help("domid");
   1.767 -        exit(1);
   1.768 +        return 1;
   1.769      }
   1.770  
   1.771      if (libxl_name_to_domid(&ctx, domname, &domid)) {
   1.772          fprintf(stderr, "Can't get domid of domain name '%s', maybe this domain does not exist.\n", domname);
   1.773 -        exit(1);
   1.774 +        return 1;
   1.775      }
   1.776  
   1.777      printf("%d\n", domid);
   1.778  
   1.779 -    exit(0);
   1.780 +    return 0;
   1.781  }
   1.782  
   1.783  int main_domname(int argc, char **argv)
   1.784 @@ -3726,7 +3726,7 @@ int main_domname(int argc, char **argv)
   1.785          switch (opt) {
   1.786          case 'h':
   1.787              help("domname");
   1.788 -            exit(0);
   1.789 +            return 0;
   1.790          default:
   1.791              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.792              break;
   1.793 @@ -3736,24 +3736,24 @@ int main_domname(int argc, char **argv)
   1.794      if (!argv[optind]) {
   1.795          fprintf(stderr, "Must specify a domain id.\n\n");
   1.796          help("domname");
   1.797 -        exit(1);
   1.798 +        return 1;
   1.799      }
   1.800      domid = strtol(argv[optind], &endptr, 10);
   1.801      if (domid == 0 && !strcmp(endptr, argv[optind])) {
   1.802          /*no digits at all*/
   1.803          fprintf(stderr, "Invalid domain id.\n\n");
   1.804 -        exit(1);
   1.805 +        return 1;
   1.806      }
   1.807  
   1.808      domname = libxl_domid_to_name(&ctx, domid);
   1.809      if (!domname) {
   1.810          fprintf(stderr, "Can't get domain name of domain id '%d', maybe this domain does not exist.\n", domid);
   1.811 -        exit(1);
   1.812 +        return 1;
   1.813      }
   1.814  
   1.815      printf("%s\n", domname);
   1.816  
   1.817 -    exit(0);
   1.818 +    return 0;
   1.819  }
   1.820  
   1.821  int main_rename(int argc, char **argv)
   1.822 @@ -3766,7 +3766,7 @@ int main_rename(int argc, char **argv)
   1.823          switch (opt) {
   1.824          case 'h':
   1.825              help("rename");
   1.826 -            exit(0);
   1.827 +            return 0;
   1.828          default:
   1.829              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.830              break;
   1.831 @@ -3777,7 +3777,7 @@ int main_rename(int argc, char **argv)
   1.832      if (!dom || !argv[optind]) {
   1.833          fprintf(stderr, "'xl rename' requires 2 arguments.\n\n");
   1.834          help("rename");
   1.835 -        exit(1);
   1.836 +        return 1;
   1.837      }
   1.838  
   1.839      find_domain(dom);
   1.840 @@ -3785,10 +3785,10 @@ int main_rename(int argc, char **argv)
   1.841  
   1.842      if (libxl_domain_rename(&ctx, domid, common_domname, new_name, 0)) {
   1.843          fprintf(stderr, "Can't rename domain '%s'.\n", dom);
   1.844 -        exit(1);
   1.845 -    }
   1.846 -
   1.847 -    exit(0);
   1.848 +        return 1;
   1.849 +    }
   1.850 +
   1.851 +    return 0;
   1.852  }
   1.853  
   1.854  int main_trigger(int argc, char **argv)
   1.855 @@ -3803,7 +3803,7 @@ int main_trigger(int argc, char **argv)
   1.856          switch (opt) {
   1.857          case 'h':
   1.858              help("trigger");
   1.859 -            exit(0);
   1.860 +            return 0;
   1.861          default:
   1.862              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.863              break;
   1.864 @@ -3814,7 +3814,7 @@ int main_trigger(int argc, char **argv)
   1.865      if (!dom || !argv[optind]) {
   1.866          fprintf(stderr, "'xl trigger' requires between 2 and 3 arguments.\n\n");
   1.867          help("trigger");
   1.868 -        exit(1);
   1.869 +        return 1;
   1.870      }
   1.871  
   1.872      find_domain(dom);
   1.873 @@ -3830,7 +3830,7 @@ int main_trigger(int argc, char **argv)
   1.874  
   1.875      libxl_send_trigger(&ctx, domid, trigger_name, vcpuid);
   1.876  
   1.877 -    exit(0);
   1.878 +    return 0;
   1.879  }
   1.880  
   1.881  
   1.882 @@ -3844,7 +3844,7 @@ int main_sysrq(int argc, char **argv)
   1.883          switch (opt) {
   1.884          case 'h':
   1.885              help("sysrq");
   1.886 -            exit(0);
   1.887 +            return 0;
   1.888          default:
   1.889              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.890              break;
   1.891 @@ -3855,7 +3855,7 @@ int main_sysrq(int argc, char **argv)
   1.892      if (!dom || !argv[optind]) {
   1.893          fprintf(stderr, "'xl sysrq' requires 2 arguments.\n\n");
   1.894          help("sysrq");
   1.895 -        exit(1);
   1.896 +        return 1;
   1.897      }
   1.898  
   1.899      find_domain(dom);
   1.900 @@ -3865,12 +3865,12 @@ int main_sysrq(int argc, char **argv)
   1.901      if (sysrq[1] != '\0') {
   1.902          fprintf(stderr, "Invalid sysrq.\n\n");
   1.903          help("sysrq");
   1.904 -        exit(1);
   1.905 +        return 1;
   1.906      }
   1.907  
   1.908      libxl_send_sysrq(&ctx, domid, sysrq[0]);
   1.909  
   1.910 -    exit(0);
   1.911 +    return 0;
   1.912  }
   1.913  
   1.914  int main_debug_keys(int argc, char **argv)
   1.915 @@ -3882,7 +3882,7 @@ int main_debug_keys(int argc, char **arg
   1.916          switch (opt) {
   1.917          case 'h':
   1.918              help("debug-keys");
   1.919 -            exit(0);
   1.920 +            return 0;
   1.921          default:
   1.922              fprintf(stderr, "option not supported\n");
   1.923              break;
   1.924 @@ -3890,17 +3890,17 @@ int main_debug_keys(int argc, char **arg
   1.925      }
   1.926      if (optind >= argc) {
   1.927          help("debug-keys");
   1.928 -        exit(2);
   1.929 +        return 2;
   1.930      }
   1.931  
   1.932      keys = argv[optind];
   1.933  
   1.934      if (libxl_send_debug_keys(&ctx, keys)) {
   1.935          fprintf(stderr, "cannot send debug keys: %s\n", keys);
   1.936 -        exit(1);
   1.937 -    }
   1.938 -
   1.939 -    exit(0);
   1.940 +        return 1;
   1.941 +    }
   1.942 +
   1.943 +    return 0;
   1.944  }
   1.945  
   1.946  int main_dmesg(int argc, char **argv)
   1.947 @@ -3917,7 +3917,7 @@ int main_dmesg(int argc, char **argv)
   1.948              break;
   1.949          case 'h':
   1.950              help("dmesg");
   1.951 -            exit(0);
   1.952 +            return 0;
   1.953          default:
   1.954              fprintf(stderr, "option not supported\n");
   1.955              break;
   1.956 @@ -3933,7 +3933,7 @@ int main_dmesg(int argc, char **argv)
   1.957  
   1.958  finish:
   1.959      libxl_xen_console_read_finish(&ctx, cr);
   1.960 -    exit(ret);
   1.961 +    return ret;
   1.962  }
   1.963  
   1.964  int main_top(int argc, char **argv)
   1.965 @@ -3944,14 +3944,14 @@ int main_top(int argc, char **argv)
   1.966          switch (opt) {
   1.967          case 'h':
   1.968              help("top");
   1.969 -            exit(0);
   1.970 +            return 0;
   1.971          default:
   1.972              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.973              break;
   1.974          }
   1.975      }
   1.976  
   1.977 -    exit(system("xentop"));
   1.978 +    return system("xentop");
   1.979  }
   1.980  
   1.981  int main_networkattach(int argc, char **argv)
   1.982 @@ -3964,13 +3964,13 @@ int main_networkattach(int argc, char **
   1.983  
   1.984      if ((argc < 3) || (argc > 11)) {
   1.985          help("network-attach");
   1.986 -        exit(0);
   1.987 +        return 0;
   1.988      }
   1.989      while ((opt = getopt(argc, argv, "h")) != -1) {
   1.990          switch (opt) {
   1.991          case 'h':
   1.992              help("network-attach");
   1.993 -            exit(0);
   1.994 +            return 0;
   1.995          default:
   1.996              fprintf(stderr, "option `%c' not supported.\n", opt);
   1.997              break;
   1.998 @@ -3979,7 +3979,7 @@ int main_networkattach(int argc, char **
   1.999  
  1.1000      if (domain_qualifier_to_domid(argv[2], &domid, 0) < 0) {
  1.1001          fprintf(stderr, "%s is an invalid domain identifier\n", argv[2]);
  1.1002 -        exit(1);
  1.1003 +        return 1;
  1.1004      }
  1.1005      init_nic_info(&nic, -1);
  1.1006      for (argv += 3, argc -= 3; argc > 0; ++argv, --argc) {
  1.1007 @@ -3990,7 +3990,7 @@ int main_networkattach(int argc, char **
  1.1008                  nic.nictype = NICTYPE_IOEMU;
  1.1009              } else {
  1.1010                  fprintf(stderr, "Invalid parameter `type'.\n");
  1.1011 -                exit(1);
  1.1012 +                return 1;
  1.1013              }
  1.1014          } else if (!strncmp("mac=", *argv, 4)) {
  1.1015              tok = strtok((*argv) + 4, ":");
  1.1016 @@ -3998,7 +3998,7 @@ int main_networkattach(int argc, char **
  1.1017                  val = strtoul(tok, &endptr, 16);
  1.1018                  if ((tok == endptr) || (val > 255)) {
  1.1019                      fprintf(stderr, "Invalid parameter `mac'.\n");
  1.1020 -                    exit(1);
  1.1021 +                    return 1;
  1.1022                  }
  1.1023                  nic.mac[i] = val;
  1.1024              }
  1.1025 @@ -4007,7 +4007,7 @@ int main_networkattach(int argc, char **
  1.1026          } else if (!strncmp("ip=", *argv, 3)) {
  1.1027              if (!inet_aton((*argv) + 3, &(nic.ip))) {
  1.1028                  fprintf(stderr, "Invalid parameter `ip'.\n");
  1.1029 -                exit(1);
  1.1030 +                return 1;
  1.1031              }
  1.1032          } else if (!strncmp("script=", *argv, 6)) {
  1.1033              nic.script = (*argv) + 6;
  1.1034 @@ -4015,7 +4015,7 @@ int main_networkattach(int argc, char **
  1.1035              val = strtoul((*argv) + 8, &endptr, 10);
  1.1036              if (((*argv) + 8) == endptr) {
  1.1037                  fprintf(stderr, "Invalid parameter `backend'.\n");
  1.1038 -                exit(1);
  1.1039 +                return 1;
  1.1040              }
  1.1041              nic.backend_domid = val;
  1.1042          } else if (!strncmp("vifname=", *argv, 8)) {
  1.1043 @@ -4026,15 +4026,15 @@ int main_networkattach(int argc, char **
  1.1044          } else if (!strncmp("accel=", *argv, 6)) {
  1.1045          } else {
  1.1046              fprintf(stderr, "unrecognized argument `%s'\n", *argv);
  1.1047 -            exit(1);
  1.1048 +            return 1;
  1.1049          }
  1.1050      }
  1.1051      nic.domid = domid;
  1.1052      if (libxl_device_nic_add(&ctx, domid, &nic)) {
  1.1053          fprintf(stderr, "libxl_device_nic_add failed.\n");
  1.1054 -        exit(1);
  1.1055 -    }
  1.1056 -    exit(0);
  1.1057 +        return 1;
  1.1058 +    }
  1.1059 +    return 0;
  1.1060  }
  1.1061  
  1.1062  int main_networklist(int argc, char **argv)
  1.1063 @@ -4045,13 +4045,13 @@ int main_networklist(int argc, char **ar
  1.1064  
  1.1065      if (argc < 3) {
  1.1066          help("network-list");
  1.1067 -        exit(1);
  1.1068 +        return 1;
  1.1069      }
  1.1070      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1071          switch (opt) {
  1.1072              case 'h':
  1.1073                  help("network-list");
  1.1074 -                exit(0);
  1.1075 +                return 0;
  1.1076              default:
  1.1077                  fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1078                  break;
  1.1079 @@ -4082,7 +4082,7 @@ int main_networklist(int argc, char **ar
  1.1080                     nics->rref_tx, nics->rref_rx, nics->backend);
  1.1081          }
  1.1082      }
  1.1083 -    exit(0);
  1.1084 +    return 0;
  1.1085  }
  1.1086  
  1.1087  int main_networkdetach(int argc, char **argv)
  1.1088 @@ -4092,13 +4092,13 @@ int main_networkdetach(int argc, char **
  1.1089  
  1.1090      if (argc != 4) {
  1.1091          help("network-detach");
  1.1092 -        exit(0);
  1.1093 +        return 0;
  1.1094      }
  1.1095      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1096          switch (opt) {
  1.1097          case 'h':
  1.1098              help("network-detach");
  1.1099 -            exit(0);
  1.1100 +            return 0;
  1.1101          default:
  1.1102              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1103              break;
  1.1104 @@ -4107,25 +4107,25 @@ int main_networkdetach(int argc, char **
  1.1105  
  1.1106      if (domain_qualifier_to_domid(argv[2], &domid, 0) < 0) {
  1.1107          fprintf(stderr, "%s is an invalid domain identifier\n", argv[2]);
  1.1108 -        exit(1);
  1.1109 +        return 1;
  1.1110      }
  1.1111  
  1.1112      if (!strchr(argv[3], ':')) {
  1.1113          if (libxl_devid_to_device_nic(&ctx, domid, argv[3], &nic)) {
  1.1114              fprintf(stderr, "Unknown device %s.\n", argv[3]);
  1.1115 -            exit(1);
  1.1116 +            return 1;
  1.1117          }
  1.1118      } else {
  1.1119          if (libxl_mac_to_device_nic(&ctx, domid, argv[3], &nic)) {
  1.1120              fprintf(stderr, "Unknown device %s.\n", argv[3]);
  1.1121 -            exit(1);
  1.1122 +            return 1;
  1.1123          }
  1.1124      }
  1.1125      if (libxl_device_nic_del(&ctx, &nic, 1)) {
  1.1126          fprintf(stderr, "libxl_device_nic_del failed.\n");
  1.1127 -        exit(1);
  1.1128 -    }
  1.1129 -    exit(0);
  1.1130 +        return 1;
  1.1131 +    }
  1.1132 +    return 0;
  1.1133  }
  1.1134  
  1.1135  int main_blockattach(int argc, char **argv)
  1.1136 @@ -4137,13 +4137,13 @@ int main_blockattach(int argc, char **ar
  1.1137  
  1.1138      if ((argc < 5) || (argc > 7)) {
  1.1139          help("block-attach");
  1.1140 -        exit(0);
  1.1141 +        return 0;
  1.1142      }
  1.1143      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1144          switch (opt) {
  1.1145          case 'h':
  1.1146              help("block-attach");
  1.1147 -            exit(0);
  1.1148 +            return 0;
  1.1149          default:
  1.1150              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1151              break;
  1.1152 @@ -4167,16 +4167,16 @@ int main_blockattach(int argc, char **ar
  1.1153              disk.phystype = PHYSTYPE_QCOW2;
  1.1154          } else {
  1.1155              fprintf(stderr, "Error: `%s' is not a valid disk image.\n", tok);
  1.1156 -            exit(1);
  1.1157 +            return 1;
  1.1158          }
  1.1159      } else {
  1.1160          fprintf(stderr, "Error: `%s' is not a valid block device.\n", tok);
  1.1161 -        exit(1);
  1.1162 +        return 1;
  1.1163      }
  1.1164      disk.physpath = strtok(NULL, "\0");
  1.1165      if (!disk.physpath) {
  1.1166          fprintf(stderr, "Error: missing path to disk image.\n");
  1.1167 -        exit(1);
  1.1168 +        return 1;
  1.1169      }
  1.1170      disk.virtpath = argv[4];
  1.1171      disk.unpluggable = 1;
  1.1172 @@ -4184,12 +4184,12 @@ int main_blockattach(int argc, char **ar
  1.1173  
  1.1174      if (domain_qualifier_to_domid(argv[2], &fe_domid, 0) < 0) {
  1.1175          fprintf(stderr, "%s is an invalid domain identifier\n", argv[2]);
  1.1176 -        exit(1);
  1.1177 +        return 1;
  1.1178      }
  1.1179      if (argc == 7) {
  1.1180          if (domain_qualifier_to_domid(argv[6], &be_domid, 0) < 0) {
  1.1181              fprintf(stderr, "%s is an invalid domain identifier\n", argv[6]);
  1.1182 -            exit(1);
  1.1183 +            return 1;
  1.1184          }
  1.1185      }
  1.1186      disk.domid = fe_domid;
  1.1187 @@ -4197,7 +4197,7 @@ int main_blockattach(int argc, char **ar
  1.1188      if (libxl_device_disk_add(&ctx, fe_domid, &disk)) {
  1.1189          fprintf(stderr, "libxl_device_disk_add failed.\n");
  1.1190      }
  1.1191 -    exit(0);
  1.1192 +    return 0;
  1.1193  }
  1.1194  
  1.1195  int main_blocklist(int argc, char **argv)
  1.1196 @@ -4209,13 +4209,13 @@ int main_blocklist(int argc, char **argv
  1.1197  
  1.1198      if (argc < 3) {
  1.1199          help("block-list");
  1.1200 -        exit(0);
  1.1201 +        return 0;
  1.1202      }
  1.1203      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1204          switch (opt) {
  1.1205          case 'h':
  1.1206              help("block-list");
  1.1207 -            exit(0);
  1.1208 +            return 0;
  1.1209          default:
  1.1210              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1211              break;
  1.1212 @@ -4242,7 +4242,7 @@ int main_blocklist(int argc, char **argv
  1.1213              }
  1.1214          }
  1.1215      }
  1.1216 -    exit(0);
  1.1217 +    return 0;
  1.1218  }
  1.1219  
  1.1220  int main_blockdetach(int argc, char **argv)
  1.1221 @@ -4252,13 +4252,13 @@ int main_blockdetach(int argc, char **ar
  1.1222  
  1.1223      if (argc != 4) {
  1.1224          help("block-detach");
  1.1225 -        exit(0);
  1.1226 +        return 0;
  1.1227      }
  1.1228      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1229          switch (opt) {
  1.1230          case 'h':
  1.1231              help("block-detach");
  1.1232 -            exit(0);
  1.1233 +            return 0;
  1.1234          default:
  1.1235              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1236              break;
  1.1237 @@ -4267,16 +4267,16 @@ int main_blockdetach(int argc, char **ar
  1.1238  
  1.1239      if (domain_qualifier_to_domid(argv[2], &domid, 0) < 0) {
  1.1240          fprintf(stderr, "%s is an invalid domain identifier\n", argv[2]);
  1.1241 -        exit(1);
  1.1242 +        return 1;
  1.1243      }
  1.1244      if (libxl_devid_to_device_disk(&ctx, domid, argv[3], &disk)) {
  1.1245          fprintf(stderr, "Error: Device %s not connected.\n", argv[3]);
  1.1246 -        exit(1);
  1.1247 +        return 1;
  1.1248      }
  1.1249      if (libxl_device_disk_del(&ctx, &disk, 1)) {
  1.1250          fprintf(stderr, "libxl_device_del failed.\n");
  1.1251      }
  1.1252 -    exit(0);
  1.1253 +    return 0;
  1.1254  }
  1.1255  
  1.1256  int main_network2attach(int argc, char **argv)
  1.1257 @@ -4290,13 +4290,13 @@ int main_network2attach(int argc, char *
  1.1258  
  1.1259      if ((argc < 3) || (argc > 12)) {
  1.1260          help("network2-attach");
  1.1261 -        exit(0);
  1.1262 +        return 0;
  1.1263      }
  1.1264      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1265          switch (opt) {
  1.1266          case 'h':
  1.1267              help("network2-attach");
  1.1268 -            exit(0);
  1.1269 +            return 0;
  1.1270          default:
  1.1271              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1272              break;
  1.1273 @@ -4305,7 +4305,7 @@ int main_network2attach(int argc, char *
  1.1274  
  1.1275      if (domain_qualifier_to_domid(argv[2], &domid, 0) < 0) {
  1.1276          fprintf(stderr, "%s is an invalid domain identifier\n", argv[1]);
  1.1277 -        exit(1);
  1.1278 +        return 1;
  1.1279      }
  1.1280      init_net2_info(&net2, -1);
  1.1281      for (argv += 3, argc -= 3; argc > 0; --argc, ++argv) {
  1.1282 @@ -4315,7 +4315,7 @@ int main_network2attach(int argc, char *
  1.1283                  val = strtoul(tok, &endptr, 16);
  1.1284                  if ((tok == endptr) || (val > 255)) {
  1.1285                      fprintf(stderr, "Invalid parameter `front_mac'.\n");
  1.1286 -                    exit(1);
  1.1287 +                    return 1;
  1.1288                  }
  1.1289                  net2.front_mac[i] = val;
  1.1290              }
  1.1291 @@ -4325,7 +4325,7 @@ int main_network2attach(int argc, char *
  1.1292                  val = strtoul(tok, &endptr, 16);
  1.1293                  if ((tok == endptr) || (val > 255)) {
  1.1294                      fprintf(stderr, "Invalid parameter back_mac=%s.\n", *argv + 9);
  1.1295 -                    exit(1);
  1.1296 +                    return 1;
  1.1297                  }
  1.1298                  net2.back_mac[i] = val;
  1.1299              }
  1.1300 @@ -4345,26 +4345,26 @@ int main_network2attach(int argc, char *
  1.1301              val = strtoul(*argv + 5, &endptr, 10);
  1.1302              if (endptr == (*argv + 5)) {
  1.1303                  fprintf(stderr, "Invalid parameter pdev=%s.\n", *argv + 5);
  1.1304 -                exit(1);
  1.1305 +                return 1;
  1.1306              }
  1.1307              net2.pdev = val;
  1.1308          } else if (!strncmp("max_bypasses=", *argv, 13)) {
  1.1309              val = strtoul(*argv + 13, &endptr, 10);
  1.1310              if (endptr == (*argv + 13)) {
  1.1311                  fprintf(stderr, "Invalid parameter max_bypasses=%s.\n", *argv + 13);
  1.1312 -                exit(1);
  1.1313 +                return 1;
  1.1314              }
  1.1315              net2.max_bypasses = val;
  1.1316          } else {
  1.1317              fprintf(stderr, "unrecognized argument `%s'\n", *argv);
  1.1318 -            exit(1);
  1.1319 +            return 1;
  1.1320          }
  1.1321      }
  1.1322  
  1.1323      if (back_dom) {
  1.1324          if (domain_qualifier_to_domid(back_dom, &back_domid, 0) < 0) {
  1.1325              fprintf(stderr, "%s is an invalid domain identifier\n", back_dom);
  1.1326 -            exit(1);
  1.1327 +            return 1;
  1.1328          }
  1.1329      }
  1.1330      net2.domid = domid;
  1.1331 @@ -4372,7 +4372,7 @@ int main_network2attach(int argc, char *
  1.1332      if (libxl_device_net2_add(&ctx, domid, &net2)) {
  1.1333          fprintf(stderr, "libxl_device_net2_add failed.\n");
  1.1334      }
  1.1335 -    exit(0);
  1.1336 +    return 0;
  1.1337  }
  1.1338  
  1.1339  int main_network2list(int argc, char **argv)
  1.1340 @@ -4383,13 +4383,13 @@ int main_network2list(int argc, char **a
  1.1341  
  1.1342      if (argc < 3) {
  1.1343          help("network2-list");
  1.1344 -        exit(0);
  1.1345 +        return 0;
  1.1346      }
  1.1347      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1348          switch (opt) {
  1.1349          case 'h':
  1.1350              help("network2-list");
  1.1351 -            exit(0);
  1.1352 +            return 0;
  1.1353          default:
  1.1354              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1355              break;
  1.1356 @@ -4417,7 +4417,7 @@ int main_network2list(int argc, char **a
  1.1357              }
  1.1358          }
  1.1359      }
  1.1360 -    exit(0);
  1.1361 +    return 0;
  1.1362  }
  1.1363  
  1.1364  int main_network2detach(int argc, char **argv)
  1.1365 @@ -4427,13 +4427,13 @@ int main_network2detach(int argc, char *
  1.1366  
  1.1367      if (argc != 4) {
  1.1368          help("network2-detach");
  1.1369 -        exit(0);
  1.1370 +        return 0;
  1.1371      }
  1.1372      while ((opt = getopt(argc, argv, "h")) != -1) {
  1.1373          switch (opt) {
  1.1374          case 'h':
  1.1375              help("network2-detach");
  1.1376 -            exit(0);
  1.1377 +            return 0;
  1.1378          default:
  1.1379              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1380              break;
  1.1381 @@ -4442,17 +4442,17 @@ int main_network2detach(int argc, char *
  1.1382  
  1.1383      if (domain_qualifier_to_domid(argv[2], &domid, 0) < 0) {
  1.1384          fprintf(stderr, "%s is an invalid domain identifier\n", argv[2]);
  1.1385 -        exit(1);
  1.1386 +        return 1;
  1.1387      }
  1.1388      if (libxl_devid_to_device_net2(&ctx, domid, argv[3], &net2)) {
  1.1389         fprintf(stderr, "Error: Device %s not connected.\n", argv[3]);
  1.1390 -        exit(1);
  1.1391 +        return 1;
  1.1392      }
  1.1393      if (libxl_device_net2_del(&ctx, &net2, 1)) {
  1.1394          fprintf(stderr, "libxl_device_net2_del failed.\n");
  1.1395 -        exit(1);
  1.1396 -    }
  1.1397 -    exit(0);
  1.1398 +        return 1;
  1.1399 +    }
  1.1400 +    return 0;
  1.1401  }
  1.1402  
  1.1403  static char *uptime_to_string(unsigned long time, int short_mode)
  1.1404 @@ -4624,7 +4624,7 @@ int main_uptime(int argc, char **argv)
  1.1405              break;
  1.1406          case 'h':
  1.1407              help("uptime");
  1.1408 -            exit(0);
  1.1409 +            return 0;
  1.1410          default:
  1.1411              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1412              break;
  1.1413 @@ -4638,7 +4638,7 @@ int main_uptime(int argc, char **argv)
  1.1414  
  1.1415      print_uptime(short_mode, domains, nb_doms);
  1.1416  
  1.1417 -    exit(0);
  1.1418 +    return 0;
  1.1419  }
  1.1420  
  1.1421  int main_tmem_list(int argc, char **argv)
  1.1422 @@ -4659,7 +4659,7 @@ int main_tmem_list(int argc, char **argv
  1.1423              break;
  1.1424          case 'h':
  1.1425              help("tmem-list");
  1.1426 -            exit(0);
  1.1427 +            return 0;
  1.1428          default:
  1.1429              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1430              break;
  1.1431 @@ -4670,7 +4670,7 @@ int main_tmem_list(int argc, char **argv
  1.1432      if (!dom && all == 0) {
  1.1433          fprintf(stderr, "You must specify -a or a domain id.\n\n");
  1.1434          help("tmem-list");
  1.1435 -        exit(1);
  1.1436 +        return 1;
  1.1437      }
  1.1438  
  1.1439      if (all)
  1.1440 @@ -4680,11 +4680,11 @@ int main_tmem_list(int argc, char **argv
  1.1441  
  1.1442      buf = libxl_tmem_list(&ctx, domid, use_long);
  1.1443      if (buf == NULL)
  1.1444 -        exit(-1);
  1.1445 +        return -1;
  1.1446  
  1.1447      printf("%s\n", buf);
  1.1448      free(buf);
  1.1449 -    exit(0);
  1.1450 +    return 0;
  1.1451  }
  1.1452  
  1.1453  int main_tmem_freeze(int argc, char **argv)
  1.1454 @@ -4700,7 +4700,7 @@ int main_tmem_freeze(int argc, char **ar
  1.1455              break;
  1.1456          case 'h':
  1.1457              help("tmem-freeze");
  1.1458 -            exit(0);
  1.1459 +            return 0;
  1.1460          default:
  1.1461              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1462              break;
  1.1463 @@ -4711,7 +4711,7 @@ int main_tmem_freeze(int argc, char **ar
  1.1464      if (!dom && all == 0) {
  1.1465          fprintf(stderr, "You must specify -a or a domain id.\n\n");
  1.1466          help("tmem-freeze");
  1.1467 -        exit(1);
  1.1468 +        return 1;
  1.1469      }
  1.1470  
  1.1471      if (all)
  1.1472 @@ -4720,7 +4720,7 @@ int main_tmem_freeze(int argc, char **ar
  1.1473          find_domain(dom);
  1.1474  
  1.1475      libxl_tmem_freeze(&ctx, domid);
  1.1476 -    exit(0);
  1.1477 +    return 0;
  1.1478  }
  1.1479  
  1.1480  int main_tmem_destroy(int argc, char **argv)
  1.1481 @@ -4736,7 +4736,7 @@ int main_tmem_destroy(int argc, char **a
  1.1482              break;
  1.1483          case 'h':
  1.1484              help("tmem-destroy");
  1.1485 -            exit(0);
  1.1486 +            return 0;
  1.1487          default:
  1.1488              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1489              break;
  1.1490 @@ -4747,7 +4747,7 @@ int main_tmem_destroy(int argc, char **a
  1.1491      if (!dom && all == 0) {
  1.1492          fprintf(stderr, "You must specify -a or a domain id.\n\n");
  1.1493          help("tmem-destroy");
  1.1494 -        exit(1);
  1.1495 +        return 1;
  1.1496      }
  1.1497  
  1.1498      if (all)
  1.1499 @@ -4756,7 +4756,7 @@ int main_tmem_destroy(int argc, char **a
  1.1500          find_domain(dom);
  1.1501  
  1.1502      libxl_tmem_destroy(&ctx, domid);
  1.1503 -    exit(0);
  1.1504 +    return 0;
  1.1505  }
  1.1506  
  1.1507  int main_tmem_thaw(int argc, char **argv)
  1.1508 @@ -4772,7 +4772,7 @@ int main_tmem_thaw(int argc, char **argv
  1.1509              break;
  1.1510          case 'h':
  1.1511              help("tmem-thaw");
  1.1512 -            exit(0);
  1.1513 +            return 0;
  1.1514          default:
  1.1515              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1516              break;
  1.1517 @@ -4783,7 +4783,7 @@ int main_tmem_thaw(int argc, char **argv
  1.1518      if (!dom && all == 0) {
  1.1519          fprintf(stderr, "You must specify -a or a domain id.\n\n");
  1.1520          help("tmem-thaw");
  1.1521 -        exit(1);
  1.1522 +        return 1;
  1.1523      }
  1.1524  
  1.1525      if (all)
  1.1526 @@ -4792,7 +4792,7 @@ int main_tmem_thaw(int argc, char **argv
  1.1527          find_domain(dom);
  1.1528  
  1.1529      libxl_tmem_thaw(&ctx, domid);
  1.1530 -    exit(0);
  1.1531 +    return 0;
  1.1532  }
  1.1533  
  1.1534  int main_tmem_set(int argc, char **argv)
  1.1535 @@ -4822,7 +4822,7 @@ int main_tmem_set(int argc, char **argv)
  1.1536              break;
  1.1537          case 'h':
  1.1538              help("tmem-set");
  1.1539 -            exit(0);
  1.1540 +            return 0;
  1.1541          default:
  1.1542              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1543              break;
  1.1544 @@ -4833,7 +4833,7 @@ int main_tmem_set(int argc, char **argv)
  1.1545      if (!dom && all == 0) {
  1.1546          fprintf(stderr, "You must specify -a or a domain id.\n\n");
  1.1547          help("tmem-set");
  1.1548 -        exit(1);
  1.1549 +        return 1;
  1.1550      }
  1.1551  
  1.1552      if (all)
  1.1553 @@ -4844,7 +4844,7 @@ int main_tmem_set(int argc, char **argv)
  1.1554      if (!opt_w && !opt_c && !opt_p) {
  1.1555          fprintf(stderr, "No set value specified.\n\n");
  1.1556          help("tmem-set");
  1.1557 -        exit(1);
  1.1558 +        return 1;
  1.1559      }
  1.1560  
  1.1561      if (opt_w)
  1.1562 @@ -4854,7 +4854,7 @@ int main_tmem_set(int argc, char **argv)
  1.1563      if (opt_p)
  1.1564          libxl_tmem_set(&ctx, domid, "compress", compress);
  1.1565  
  1.1566 -    exit(0);
  1.1567 +    return 0;
  1.1568  }
  1.1569  
  1.1570  int main_tmem_shared_auth(int argc, char **argv)
  1.1571 @@ -4880,7 +4880,7 @@ int main_tmem_shared_auth(int argc, char
  1.1572              break;
  1.1573          case 'h':
  1.1574              help("tmem-shared-auth");
  1.1575 -            exit(0);
  1.1576 +            return 0;
  1.1577          default:
  1.1578              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1579              break;
  1.1580 @@ -4891,7 +4891,7 @@ int main_tmem_shared_auth(int argc, char
  1.1581      if (!dom && all == 0) {
  1.1582          fprintf(stderr, "You must specify -a or a domain id.\n\n");
  1.1583          help("tmem-shared-auth");
  1.1584 -        exit(1);
  1.1585 +        return 1;
  1.1586      }
  1.1587  
  1.1588      if (all)
  1.1589 @@ -4902,18 +4902,18 @@ int main_tmem_shared_auth(int argc, char
  1.1590      if (uuid == NULL || autharg == NULL) {
  1.1591          fprintf(stderr, "No uuid or auth specified.\n\n");
  1.1592          help("tmem-shared-auth");
  1.1593 -        exit(1);
  1.1594 +        return 1;
  1.1595      }
  1.1596  
  1.1597      auth = strtol(autharg, &endptr, 10);
  1.1598      if (*endptr != '\0') {
  1.1599          fprintf(stderr, "Invalid auth, valid auth are <0|1>.\n\n");
  1.1600 -        exit(1);
  1.1601 +        return 1;
  1.1602      }
  1.1603  
  1.1604      libxl_tmem_shared_auth(&ctx, domid, uuid, auth);
  1.1605  
  1.1606 -    exit(0);
  1.1607 +    return 0;
  1.1608  }
  1.1609  
  1.1610  int main_tmem_freeable(int argc, char **argv)
  1.1611 @@ -4925,7 +4925,7 @@ int main_tmem_freeable(int argc, char **
  1.1612          switch (opt) {
  1.1613          case 'h':
  1.1614              help("tmem-freeable");
  1.1615 -            exit(0);
  1.1616 +            return 0;
  1.1617          default:
  1.1618              fprintf(stderr, "option `%c' not supported.\n", opt);
  1.1619              break;
  1.1620 @@ -4934,8 +4934,8 @@ int main_tmem_freeable(int argc, char **
  1.1621  
  1.1622      mb = libxl_tmem_freeable(&ctx);
  1.1623      if (mb == -1)
  1.1624 -        exit(-1);
  1.1625 +        return -1;
  1.1626  
  1.1627      printf("%d\n", mb);
  1.1628 -    exit(0);
  1.1629 +    return 0;
  1.1630  }