Message ID | 1450441425-10755-5-git-send-email-george.dunlap@eu.citrix.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Fri, 2015-12-18 at 12:23 +0000, George Dunlap wrote: > This makes xl more useful in scripts. > > The strange thing about this is that the internal cd_insert function > *already* returned something appropriate, and cd-eject was using it, > but cd-insert wasn't. > > Also: > > * Rework cd_insert to return EXIT_FAILURE and EXIT_SUCCESS rather > than > magic constants > > * Use 'r' for non-libxl return code, as specified in CODING_STYLE > > Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com> > Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com> Dario
George Dunlap writes ("[PATCH v4 4/5] xl: Return an error on failed cd-insert"): > This makes xl more useful in scripts. Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 1a8b4a1..0c3756b 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -3336,7 +3336,7 @@ static int cd_insert(uint32_t domid, const char *virtdev, char *phys) char *buf = NULL; XLU_Config *config = 0; struct stat b; - int rc = 0; + int r; xasprintf(&buf, "vdev=%s,access=r,devtype=cdrom,target=%s", virtdev, phys ? phys : ""); @@ -3352,18 +3352,22 @@ static int cd_insert(uint32_t domid, const char *virtdev, char *phys) && stat(disk.pdev_path, &b)) { fprintf(stderr, "Cannot stat file: %s\n", disk.pdev_path); - rc = 1; + r = EXIT_FAILURE; + goto out; + } + + if (libxl_cdrom_insert(ctx, domid, &disk, NULL)) { + r = EXIT_FAILURE; goto out; } - if (libxl_cdrom_insert(ctx, domid, &disk, NULL)) - rc=1; + r = EXIT_SUCCESS; out: libxl_device_disk_dispose(&disk); free(buf); - return rc; + return r; } int main_cd_eject(int argc, char **argv) @@ -3397,8 +3401,7 @@ int main_cd_insert(int argc, char **argv) virtdev = argv[optind + 1]; file = argv[optind + 2]; - cd_insert(domid, virtdev, file); - return 0; + return cd_insert(domid, virtdev, file); } int main_console(int argc, char **argv)
This makes xl more useful in scripts. The strange thing about this is that the internal cd_insert function *already* returned something appropriate, and cd-eject was using it, but cd-insert wasn't. Also: * Rework cd_insert to return EXIT_FAILURE and EXIT_SUCCESS rather than magic constants * Use 'r' for non-libxl return code, as specified in CODING_STYLE Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com> --- v4: - Use EXIT_{SUCCESS,FAILURE} rather than magic constants in cd_insert - Use 'r' rather than 'rc' for non-libxl return code - Fixed typo in changelog CC: Ian Campbell <ian.campbell@citrix.com> CC: Ian Jackson <ian.jackson@citrix.com> CC: Wei Liu <wei.liu2@citrix.com> --- tools/libxl/xl_cmdimpl.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)