From patchwork Wed Feb 24 12:53:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 8405961 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3172C9F2F0 for ; Wed, 24 Feb 2016 12:56:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 164BA2011D for ; Wed, 24 Feb 2016 12:56:56 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C750D20165 for ; Wed, 24 Feb 2016 12:56:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYYxV-00083d-CN; Wed, 24 Feb 2016 12:54:25 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYYxS-00082T-V9 for xen-devel@lists.xenproject.org; Wed, 24 Feb 2016 12:54:23 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id BB/D9-03606-EF7ADC65; Wed, 24 Feb 2016 12:54:22 +0000 X-Env-Sender: write.harmandeep@gmail.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1456318459!24173821!1 X-Originating-IP: [209.85.220.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27631 invoked from network); 24 Feb 2016 12:54:20 -0000 Received: from mail-pa0-f67.google.com (HELO mail-pa0-f67.google.com) (209.85.220.67) by server-13.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 24 Feb 2016 12:54:20 -0000 Received: by mail-pa0-f67.google.com with SMTP id fl4so871281pad.2 for ; Wed, 24 Feb 2016 04:54:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i/oMK8rGMmv2NJbsHiJIND1Iat/QJFIunu+61ciEM7I=; b=LIqsEYbd+c5gEnFQuLOB7PMvKab/N5NUU4w9t7rDslvhCoTzvsLEi0Fu4W4Fd3OFyW a3iMZ0LCrI3iSp8Y694QDCHvO25OOvRY+4gnN5/ijKi2z6yApoGW36BZI/7mxXbr4TM0 tEOq5Jh32HVaaCqC6JAFHK1EjDJ+ARTT4KI2QFKgSzZtxouxnZAyA19X48qvWMdopUlF GbbkXZ7oUb3ndVZo/fjT77kJ0WrHB/3qD7zSrUyhpOqOv30KjFd3TJA/ljX1Iwbd8Z6I aqFwIps6c2YKRja0wTGnPRivhZ47uApJz+x+C76onBo2IM9u7rqOnvf8UhNytjEL5Scd C90Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=i/oMK8rGMmv2NJbsHiJIND1Iat/QJFIunu+61ciEM7I=; b=PmC5TJ6VDoeKXnZ1JzqlLSOGAJqjNxDOgCyp5qUfkfIdVpSW5/Hkad7H5P5KRsclaL rp/vctt5aJ7UfZ0G6Lk2mDQB3RDgqEyeAxWZWt/+qVUbG4pcJx2l/fk9lq3x3hxuWrlq XTff3yMvAIg7fSNI2rKSyoZc4ZFh9vNSd02jB03VARZfhXn3Xod32aPF+42zVKjaSxrh gy/V98dk6+Y68LgTXT3V1BVlC6jA6ykKQ4fwy5zA3YKJr87SNPsDUEOi1Lo+qDOZj9BO zdWP29L6ACQQw/lOqhzqtKxokMLtv5Ct/AazrgILUsTQvRYZbpmXR5A8Pf3NqfSE0vS6 Eceg== X-Gm-Message-State: AG10YOT+vRfCM+iyKUg1yyO4awsynWUurd4q5xi8F/Hj4XrVxXrERSC0jhpRm4RqjIlGdg== X-Received: by 10.66.145.68 with SMTP id ss4mr54318435pab.79.1456318459394; Wed, 24 Feb 2016 04:54:19 -0800 (PST) Received: from localhost.localdomain ([124.253.62.0]) by smtp.googlemail.com with ESMTPSA id t87sm5027294pfa.14.2016.02.24.04.54.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Feb 2016 04:54:18 -0800 (PST) From: Harmandeep Kaur To: xen-devel@lists.xenproject.org Date: Wed, 24 Feb 2016 18:23:21 +0530 Message-Id: <1456318407-3635-4-git-send-email-write.harmandeep@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456318407-3635-1-git-send-email-write.harmandeep@gmail.com> References: <1456318407-3635-1-git-send-email-write.harmandeep@gmail.com> 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 Subject: [Xen-devel] [PATCH 3/9] xl: Improve return and exit codes of migrate related functions. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Harmandeep Kaur --- tools/libxl/xl_cmdimpl.c | 56 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index e5bb41f..2092c80 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -50,7 +50,7 @@ else if (chk_errnoval > 0) { \ fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n", \ __FILE__,__LINE__, strerror(chk_errnoval), #call); \ - exit(-ERROR_FAIL); \ + exit(EXIT_FAILURE); \ } \ }) @@ -4036,7 +4036,7 @@ static void save_domain_core_begin(uint32_t domid, &config_v, config_len_r); if (rc) { fprintf(stderr, "unable to read overridden config file\n"); - exit(2); + exit(EXIT_FAILURE); } parse_config_data(override_config_file, config_v, *config_len_r, &d_config); @@ -4045,14 +4045,14 @@ static void save_domain_core_begin(uint32_t domid, rc = libxl_retrieve_domain_configuration(ctx, domid, &d_config); if (rc) { fprintf(stderr, "unable to retrieve domain configuration\n"); - exit(2); + exit(EXIT_FAILURE); } } config_c = libxl_domain_config_to_json(ctx, &d_config); if (!config_c) { fprintf(stderr, "unable to convert config file to JSON\n"); - exit(2); + exit(EXIT_FAILURE); } *config_data_r = (uint8_t *)config_c; *config_len_r = strlen(config_c) + 1; /* including trailing '\0' */ @@ -4152,7 +4152,7 @@ static pid_t create_migration_child(const char *rune, int *send_fd, pid_t child; if (!rune || !send_fd || !recv_fd) - return -1; + return EXIT_FAILURE; MUST( libxl_pipe(ctx, sendpipe) ); MUST( libxl_pipe(ctx, recvpipe) ); @@ -4166,7 +4166,7 @@ static pid_t create_migration_child(const char *rune, int *send_fd, close(recvpipe[0]); close(recvpipe[1]); execlp("sh","sh","-c",rune,(char*)0); perror("failed to exec sh"); - exit(-1); + exit(EXIT_FAILURE); } close(sendpipe[0]); @@ -4189,16 +4189,16 @@ static int migrate_read_fixedmessage(int fd, const void *msg, int msgsz, stream = rune ? "migration receiver stream" : "migration stream"; rc = libxl_read_exactly(ctx, fd, buf, msgsz, stream, what); - if (rc) return ERROR_FAIL; + if (rc) return EXIT_FAILURE; if (memcmp(buf, msg, msgsz)) { fprintf(stderr, "%s contained unexpected data instead of %s\n", stream, what); if (rune) fprintf(stderr, "(command run was: %s )\n", rune); - return ERROR_FAIL; + return EXIT_FAILURE; } - return 0; + return EXIT_SUCCESS; } static void migration_child_report(int recv_fd) { @@ -4272,7 +4272,7 @@ static void migrate_do_preamble(int send_fd, int recv_fd, pid_t child, if (send_fd < 0 || recv_fd < 0) { fprintf(stderr, "migrate_do_preamble: invalid file descriptors\n"); - exit(1); + exit(EXIT_FAILURE); } rc = migrate_read_fixedmessage(recv_fd, migrate_receiver_banner, @@ -4281,7 +4281,7 @@ static void migrate_do_preamble(int send_fd, int recv_fd, pid_t child, if (rc) { close(send_fd); migration_child_report(recv_fd); - exit(-rc); + exit(EXIT_FAILURE); } save_domain_core_writeconfig(send_fd, "migration stream", @@ -4306,7 +4306,7 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug, if (!config_len) { fprintf(stderr, "No config file stored for running domain and " "none supplied - cannot migrate.\n"); - exit(1); + exit(EXIT_FAILURE); } child = create_migration_child(rune, &send_fd, &recv_fd); @@ -4393,26 +4393,26 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug, if (!rc) fprintf(stderr, "migration sender: Resumed OK.\n"); fprintf(stderr, "Migration failed due to problems at target.\n"); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); } fprintf(stderr, "migration sender: Target reports successful startup.\n"); libxl_domain_destroy(ctx, domid, 0); /* bang! */ fprintf(stderr, "Migration successful.\n"); - exit(0); + exit(EXIT_SUCCESS); failed_suspend: close(send_fd); migration_child_report(recv_fd); fprintf(stderr, "Migration failed, failed to suspend at sender.\n"); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); failed_resume: close(send_fd); migration_child_report(recv_fd); fprintf(stderr, "Migration failed, resuming at sender.\n"); libxl_domain_resume(ctx, domid, 1, 0); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); failed_badly: fprintf(stderr, @@ -4425,7 +4425,7 @@ static void migrate_domain(uint32_t domid, const char *rune, int debug, close(send_fd); migration_child_report(recv_fd); - exit(-ERROR_BADFAIL); + exit(EXIT_FAILURE); } static void migrate_receive(int debug, int daemonize, int monitor, @@ -4460,7 +4460,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, if (rc < 0) { fprintf(stderr, "migration target: Domain creation failed" " (code %d).\n", rc); - exit(-rc); + exit(EXIT_FAILURE); } domid = rc; @@ -4497,7 +4497,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, "Failed to unpause domain %s (id: %u):%d\n", common_domname, domid, rc); - exit(rc ? -ERROR_FAIL: 0); + exit(rc ? EXIT_FAILURE : EXIT_SUCCESS); } fprintf(stderr, "migration target: Transfer complete," @@ -4507,7 +4507,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, migrate_receiver_ready, sizeof(migrate_receiver_ready), "migration ack stream", "ready message"); - if (rc) exit(-rc); + if (rc) exit(EXIT_FAILURE); rc = migrate_read_fixedmessage(recv_fd, migrate_permission_to_go, sizeof(migrate_permission_to_go), @@ -4532,14 +4532,14 @@ static void migrate_receive(int debug, int daemonize, int monitor, migrate_report, sizeof(migrate_report), "migration ack stream", "success/failure report"); - if (rc2) exit(-ERROR_BADFAIL); + if (rc2) exit(EXIT_FAILURE); rc_buf = -rc; assert(!!rc_buf == !!rc); rc2 = libxl_write_exactly(ctx, send_fd, &rc_buf, 1, "migration ack stream", "success/failure code"); - if (rc2) exit(-ERROR_BADFAIL); + if (rc2) exit(EXIT_FAILURE); if (rc) { fprintf(stderr, "migration target: Failure, destroying our copy.\n"); @@ -4548,7 +4548,7 @@ static void migrate_receive(int debug, int daemonize, int monitor, if (rc2) { fprintf(stderr, "migration target: Failed to destroy our copy" " (code %d).\n", rc2); - exit(-ERROR_BADFAIL); + exit(EXIT_FAILURE); } fprintf(stderr, "migration target: Cleanup OK, granting sender" @@ -4559,10 +4559,10 @@ static void migrate_receive(int debug, int daemonize, int monitor, sizeof(migrate_permission_to_go), "migration ack stream", "permission to sender to have domain back"); - if (rc2) exit(-ERROR_BADFAIL); + if (rc2) exit(EXIT_FAILURE); } - exit(0); + exit(EXIT_SUCCESS); } int main_restore(int argc, char **argv) @@ -4656,13 +4656,13 @@ int main_migrate_receive(int argc, char **argv) if (argc-optind != 0) { help("migrate-receive"); - return 2; + return EXIT_FAILURE; } migrate_receive(debug, daemonize, monitor, STDOUT_FILENO, STDIN_FILENO, remus); - return 0; + return EXIT_SUCCESS; } int main_save(int argc, char **argv) @@ -4761,7 +4761,7 @@ int main_migrate(int argc, char **argv) } migrate_domain(domid, rune, debug, config_filename); - return 0; + return EXIT_SUCCESS; } #endif