From patchwork Tue Mar 8 19:02:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 8536821 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 4D5189F372 for ; Tue, 8 Mar 2016 19:05:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 381EF2015E for ; Tue, 8 Mar 2016 19:05:39 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C61520155 for ; Tue, 8 Mar 2016 19:05:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adMuu-0001EW-6D; Tue, 08 Mar 2016 19:03:36 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adMus-0001Dl-PU for xen-devel@lists.xenproject.org; Tue, 08 Mar 2016 19:03:34 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id EB/B9-01728-6022FD65; Tue, 08 Mar 2016 19:03:34 +0000 X-Env-Sender: write.harmandeep@gmail.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1457463811!4953833!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29023 invoked from network); 8 Mar 2016 19:03:33 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-12.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 8 Mar 2016 19:03:33 -0000 Received: by mail-wm0-f66.google.com with SMTP id n186so5921082wmn.0 for ; Tue, 08 Mar 2016 11:03:31 -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=+MclBpSkfho6tXwIHqgARqPFNac09boAYrZIWckcOKg=; b=rW79kGQa+ZP8QVA1d6sanPVwS9JgNobKijTtKUiv9RHQOAPbMONSWKalj2Fkazc7LT YrCHW4adyT/JLPqGtGlfagioZM0K4dJ0Vnxy/1fND6Hqn3hXMmVSTRNJXH+V+gkILy9e AG9trpV4xTObK1osgnnqcpALm0XM4l4r3QoIjQ1TTNhccLoPVEAn/XXvHO7q9t6qyTXx r6DQufYf4/jZRCjxuxqIB93GCSCJxRDF4hP1Pt2q1A1hQgem/t/bynlbWJUboh3Shk7b eovo3CDcWpy620OFRYXcYQE7RarmRGa0/fDIKmLnqKyhUh6axpotFTs8LU28jCpUVosr 8sDg== 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=+MclBpSkfho6tXwIHqgARqPFNac09boAYrZIWckcOKg=; b=A7ctWIUpgoTDxrQScGJNaL94NoeZLZdyXucOKpdVcZfN0qdFKJBTr7dyTWKPzbDcTA 7Gfw639d4gOLDaQUKR0u3gpMEuC97H0/RKSCojVsrsRMx9Tr0QrjVbozqJVZ9UliplJB UFoXuyKDOZ+CpbbpAgIRS/H2AxSeslIRfUSF0/xZ0ZYMonYGc2jY0S74Wro8RxI7uY0w hdPKsStI5G+RP0VdOpLwsNj+dsbt3wDQbSXIFM251QbcmWeSnpLvhy8aUZ1r+k/4cWDW U0TnowkdWVuUkEah90+TLnwrO4uxQRMuc2jXCoh5ueCIU53toI7sUmZ1oN3e5CvCSufW ys0w== X-Gm-Message-State: AD7BkJLjVLK2vnvi0XzyH4ru5bKNYdW1MkEbgqVca0oxYNhD8eycP/1xDP7Kf0bIH36NOQ== X-Received: by 10.194.60.200 with SMTP id j8mr30480246wjr.124.1457463786244; Tue, 08 Mar 2016 11:03:06 -0800 (PST) Received: from localhost.localdomain ([124.253.57.150]) by smtp.googlemail.com with ESMTPSA id hu1sm4310795wjb.36.2016.03.08.11.03.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Mar 2016 11:03:05 -0800 (PST) From: Harmandeep Kaur To: xen-devel@lists.xenproject.org Date: Wed, 9 Mar 2016 00:32:08 +0530 Message-Id: <1457463730-4712-8-git-send-email-write.harmandeep@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457463730-4712-1-git-send-email-write.harmandeep@gmail.com> References: <1457463730-4712-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 7/9 v2] xl: Improve return and exit codes of create, config_update and rename related functions. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no 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 create_domain(), string_realloc_append(), main_create(), main_config_update() and main_rename() are fixed. Signed-off-by: Harmandeep Kaur --- v2: Add create_domain() Remove main_sharing() --- tools/libxl/xl_cmdimpl.c | 54 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 4011c81..f0b5efc 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2684,7 +2684,7 @@ static uint32_t create_domain(struct domain_create *dom_info) int i; int need_daemon = daemonize; - int ret, rc; + int ret = 0, rc; libxl_evgen_domain_death *deathw = NULL; libxl_evgen_disk_eject **diskws = NULL; /* one per disk */ void *config_data = 0; @@ -2713,11 +2713,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( @@ -2726,11 +2726,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" @@ -2743,7 +2743,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); @@ -2757,7 +2757,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); \ @@ -2790,12 +2790,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 @@ -2809,7 +2809,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 = ""; config_in_json = !!(hdr.mandatory_flags & XL_MANDATORY_FLAG_JSON); @@ -2848,7 +2848,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); @@ -2872,7 +2872,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; } } @@ -3096,7 +3096,7 @@ out: * already happened in the parent. */ if ( daemonize && !need_daemon ) - exit(ret); + exit(EXIT_SUCCESS); return ret; } @@ -5016,7 +5016,7 @@ static void string_realloc_append(char **accumulate, const char *more) size_t morelen = strlen(more) + 1/*nul*/; if (oldlen > SSIZE_MAX || morelen > SSIZE_MAX - oldlen) { fprintf(stderr,"Additional config data far too large\n"); - exit(-ERROR_FAIL); + exit(EXIT_FAILURE); } *accumulate = xrealloc(*accumulate, oldlen + morelen); @@ -5091,7 +5091,7 @@ int main_create(int argc, char **argv) } else { help("create"); free(dom_info.extra_config); - return 2; + return EXIT_FAILURE; } } @@ -5110,11 +5110,11 @@ int main_create(int argc, char **argv) rc = create_domain(&dom_info); if (rc < 0) { free(dom_info.extra_config); - return -rc; + return EXIT_FAILURE; } free(dom_info.extra_config); - return 0; + return EXIT_SUCCESS; } int main_config_update(int argc, char **argv) @@ -5135,7 +5135,7 @@ int main_config_update(int argc, char **argv) if (argc < 2) { fprintf(stderr, "xl config-update requires a domain argument\n"); help("config-update"); - exit(1); + exit(EXIT_FAILURE); } fprintf(stderr, "WARNING: xl now has better capability to manage domain configuration, " @@ -5167,7 +5167,7 @@ int main_config_update(int argc, char **argv) } else { help("create"); free(extra_config); - return 2; + return EXIT_FAILURE; } } if (filename) { @@ -5176,25 +5176,25 @@ int main_config_update(int argc, char **argv) &config_data, &config_len); if (rc) { fprintf(stderr, "Failed to read config file: %s: %s\n", filename, strerror(errno)); - free(extra_config); return ERROR_FAIL; } + free(extra_config); return EXIT_FAILURE; } if (extra_config && strlen(extra_config)) { if (config_len > INT_MAX - (strlen(extra_config) + 2 + 1)) { fprintf(stderr, "Failed to attach extra configuration\n"); - exit(1); + exit(EXIT_FAILURE); } /* allocate space for the extra config plus two EOLs plus \0 */ config_data = realloc(config_data, config_len + strlen(extra_config) + 2 + 1); if (!config_data) { fprintf(stderr, "Failed to realloc config_data\n"); - exit(1); + exit(EXIT_FAILURE); } config_len += sprintf(config_data + config_len, "\n%s\n", extra_config); } } else { fprintf(stderr, "Config file not specified\n"); - exit(1); + exit(EXIT_FAILURE); } libxl_domain_config_init(&d_config); @@ -5210,7 +5210,7 @@ int main_config_update(int argc, char **argv) config_data, config_len); if (rc) { fprintf(stderr, "failed to update configuration\n"); - exit(1); + exit(EXIT_FAILURE); } } @@ -5218,7 +5218,7 @@ int main_config_update(int argc, char **argv) free(config_data); free(extra_config); - return 0; + return EXIT_SUCCESS; } static void button_press(uint32_t domid, const char *b) @@ -6389,10 +6389,10 @@ int main_rename(int argc, char **argv) domid = find_domain(dom); if (libxl_domain_rename(ctx, domid, common_domname, new_name)) { fprintf(stderr, "Can't rename domain '%s'.\n", dom); - return 1; + return EXIT_FAILURE; } - return 0; + return EXIT_SUCCESS; } int main_trigger(int argc, char **argv)