From: Harmandeep Kaur <write.harmandeep@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: wei.liu2@citrix.com, ian.campbell@citrix.com,
stefano.stabellini@eu.citrix.com, dario.faggioli@citrix.com,
ian.jackson@eu.citrix.com,
Harmandeep Kaur <write.harmandeep@gmail.com>
Subject: [PATCH 2/9] xl: Improve return and exit codes of restore and save related functions.
Date: Wed, 24 Feb 2016 18:23:20 +0530 [thread overview]
Message-ID: <1456318407-3635-3-git-send-email-write.harmandeep@gmail.com> (raw)
In-Reply-To: <1456318407-3635-1-git-send-email-write.harmandeep@gmail.com>
Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
---
tools/libxl/xl_cmdimpl.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 8f5a2f4..e5bb41f 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -2708,11 +2708,11 @@ static uint32_t create_domain(struct domain_create *dom_info)
restore_fd = open(restore_file, O_RDONLY);
if (restore_fd == -1) {
fprintf(stderr, "Can't open restore file: %s\n", strerror(errno));
- return ERROR_INVAL;
+ return -1;
}
restore_fd_to_close = restore_fd;
rc = libxl_fd_set_cloexec(ctx, restore_fd, 1);
- if (rc) return rc;
+ if (rc) return -1;
}
CHK_ERRNOVAL(libxl_read_exactly(
@@ -2721,11 +2721,11 @@ static uint32_t create_domain(struct domain_create *dom_info)
if (memcmp(hdr.magic, savefileheader_magic, sizeof(hdr.magic))) {
fprintf(stderr, "File has wrong magic number -"
" corrupt or for a different tool?\n");
- return ERROR_INVAL;
+ return -1;
}
if (hdr.byteorder != SAVEFILE_BYTEORDER_VALUE) {
fprintf(stderr, "File has wrong byte order\n");
- return ERROR_INVAL;
+ return -1;
}
fprintf(stderr, "Loading new save file %s"
" (new xl fmt info"
@@ -2738,7 +2738,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
fprintf(stderr, "Savefile has mandatory flag(s) 0x%"PRIx32" "
"which are not supported; need newer xl\n",
badflags);
- return ERROR_INVAL;
+ return -1;
}
if (hdr.optional_data_len) {
optdata_begin = xmalloc(hdr.optional_data_len);
@@ -2752,7 +2752,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
#define WITH_OPTDATA(amt, body) \
if (OPTDATA_LEFT < (amt)) { \
fprintf(stderr, "Savefile truncated.\n"); \
- return ERROR_INVAL; \
+ return -1; \
} else { \
body; \
optdata_here += (amt); \
@@ -2785,12 +2785,12 @@ static uint32_t create_domain(struct domain_create *dom_info)
ret = libxl_read_file_contents(ctx, config_file,
&config_data, &config_len);
if (ret) { fprintf(stderr, "Failed to read config file: %s: %s\n",
- config_file, strerror(errno)); return ERROR_FAIL; }
+ config_file, strerror(errno)); return -1; }
}
if (!restoring && extra_config && strlen(extra_config)) {
if (config_len > INT_MAX - (strlen(extra_config) + 2 + 1)) {
fprintf(stderr, "Failed to attach extra configuration\n");
- return ERROR_FAIL;
+ return -1;
}
/* allocate space for the extra config plus two EOLs plus \0 */
config_data = xrealloc(config_data, config_len
@@ -2804,7 +2804,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
if (!config_data) {
fprintf(stderr, "Config file not specified and"
" none in save file\n");
- return ERROR_INVAL;
+ return -1;
}
config_source = "<saved>";
config_in_json = !!(hdr.mandatory_flags & XL_MANDATORY_FLAG_JSON);
@@ -2843,7 +2843,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
if (!json) {
fprintf(stderr,
"Failed to convert domain configuration to JSON\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
fputs(json, cfg_print_fh);
free(json);
@@ -2867,7 +2867,7 @@ start:
ret = freemem(domid, &d_config.b_info);
if (ret < 0) {
fprintf(stderr, "failed to free memory for the domain\n");
- ret = ERROR_FAIL;
+ ret = -1;
goto error_out;
}
}
@@ -3091,9 +3091,9 @@ out:
* already happened in the parent.
*/
if ( daemonize && !need_daemon )
- exit(ret);
+ exit(EXIT_SUCCESS);
- return ret;
+ return ret < 0 ? -1 : 0;
}
void help(const char *command)
@@ -4122,7 +4122,7 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (fd < 0) {
fprintf(stderr, "Failed to open temp file %s for writing\n", filename);
- exit(2);
+ exit(EXIT_FAILURE);
}
save_domain_core_writeconfig(fd, filename, config_data, config_len);
@@ -4142,7 +4142,7 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
else
libxl_domain_destroy(ctx, domid, 0);
- exit(rc < 0 ? 1 : 0);
+ exit(rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}
static pid_t create_migration_child(const char *rune, int *send_fd,
@@ -4611,7 +4611,7 @@ int main_restore(int argc, char **argv)
checkpoint_file = argv[optind + 1];
} else {
help("restore");
- return 2;
+ return EXIT_FAILURE;
}
memset(&dom_info, 0, sizeof(dom_info));
@@ -4628,9 +4628,9 @@ int main_restore(int argc, char **argv)
rc = create_domain(&dom_info);
if (rc < 0)
- return -rc;
+ return EXIT_FAILURE;
- return 0;
+ return EXIT_SUCCESS;
}
int main_migrate_receive(int argc, char **argv)
@@ -4685,7 +4685,7 @@ int main_save(int argc, char **argv)
if (argc-optind > 3) {
help("save");
- return 2;
+ return EXIT_FAILURE;
}
domid = find_domain(argv[optind]);
@@ -4694,7 +4694,7 @@ int main_save(int argc, char **argv)
config_filename = argv[optind + 2];
save_domain(domid, filename, checkpoint, leavepaused, config_filename);
- return 0;
+ return EXIT_SUCCESS;
}
int main_migrate(int argc, char **argv)
--
2.5.0
next prev parent reply other threads:[~2016-02-24 12:54 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 12:53 [PATCH 0/9] xl: convert exit codes related to domain subcommands to EXIT_[SUCCESS|FAILURE] Harmandeep Kaur
2016-02-24 12:53 ` [PATCH 1/9] xl: Improve return and exit codes of memory related functions Harmandeep Kaur
2016-02-24 13:55 ` Olaf Hering
2016-02-24 14:30 ` Dario Faggioli
2016-02-25 11:10 ` Dario Faggioli
2016-02-24 12:53 ` Harmandeep Kaur [this message]
2016-03-02 18:02 ` [PATCH 2/9] xl: Improve return and exit codes of restore and save " Dario Faggioli
2016-02-24 12:53 ` [PATCH 3/9] xl: Improve return and exit codes of migrate " Harmandeep Kaur
2016-03-02 17:53 ` Dario Faggioli
2016-02-24 12:53 ` [PATCH 4/9] xl: Improve return and exit codes of main_console(), main_vncviewer() and main_dump_core() Harmandeep Kaur
2016-02-25 11:33 ` Dario Faggioli
[not found] ` <CAPtdW15OwR5WmAnyr9+KqEbTFsPwX2d9_CzS945gzoLQyPBtOA@mail.gmail.com>
2016-03-08 14:16 ` Dario Faggioli
2016-02-24 12:53 ` [PATCH 5/9] xl: Improve return and exit codes of main_pause(), main_unpause(), main_destroy() and main_shutdown_or_reboot() related functions Harmandeep Kaur
2016-03-02 16:59 ` Dario Faggioli
2016-02-24 12:53 ` [PATCH 6/9] xl: Improve return and exit codes of main_list() and main_vm_list() " Harmandeep Kaur
2016-03-02 17:37 ` Dario Faggioli
2016-02-24 12:53 ` [PATCH 7/9] xl: Improve return and exit codes of main_create(), main_config_update(), main_sharing(), main_rename() and " Harmandeep Kaur
2016-03-02 17:29 ` Dario Faggioli
2016-02-24 12:53 ` [PATCH 8/9] xl: Improve return and exit codes main_button_press(), main_trigger(), main_remus() " Harmandeep Kaur
2016-02-25 11:26 ` Dario Faggioli
2016-02-24 12:53 ` [PATCH 9/9] xl: Improve return codes of main_domid(), main_domname() and main_sysrq() " Harmandeep Kaur
2016-02-25 11:18 ` Dario Faggioli
2016-02-25 10:57 ` [PATCH 0/9] xl: convert exit codes related to domain subcommands to EXIT_[SUCCESS|FAILURE] Dario Faggioli
2016-03-02 18:05 ` Dario Faggioli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456318407-3635-3-git-send-email-write.harmandeep@gmail.com \
--to=write.harmandeep@gmail.com \
--cc=dario.faggioli@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.