diff mbox

[v3,6/6] xl: improve exit codes of domain creation related functions

Message ID 20160408022416.9058.81418.stgit@Solace.fritz.box (mailing list archive)
State New, archived
Headers show

Commit Message

Dario Faggioli April 8, 2016, 2:24 a.m. UTC
by making them more consistent with other examples in xl.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
v3: In create_domain(), only deal with exit codes, internal returns
    need more work than what was being done in the original patch.
    Shorten changelog.

v2: Add create_domain()
    Remove main_sharing()
---
 tools/libxl/xl_cmdimpl.c |   32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

Comments

Wei Liu April 8, 2016, 12:40 p.m. UTC | #1
On Fri, Apr 08, 2016 at 04:24:17AM +0200, Dario Faggioli wrote:
> by making them more consistent with other examples in xl.
> 
> Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
> Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
> ---
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> ---
> v3: In create_domain(), only deal with exit codes, internal returns
>     need more work than what was being done in the original patch.
>     Shorten changelog.
> 
> v2: Add create_domain()
>     Remove main_sharing()
> ---
>  tools/libxl/xl_cmdimpl.c |   32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index d2ad8c8..31e2f30 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -2964,7 +2964,7 @@ static int 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);
> @@ -3212,7 +3212,7 @@ out:
>       * already happened in the parent.
>       */
>      if ( daemonize && !need_daemon )
> -        exit(ret);
> +        exit(EXIT_SUCCESS);

This is not entirely correct: ret can be non-zero here if I'm not
mistaken. Whether it is useful to exit with that value, I don't know.

Wei.
diff mbox

Patch

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index d2ad8c8..31e2f30 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -2964,7 +2964,7 @@  static int 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);
@@ -3212,7 +3212,7 @@  out:
      * already happened in the parent.
      */
     if ( daemonize && !need_daemon )
-        exit(ret);
+        exit(EXIT_SUCCESS);
 
     return ret;
 }
@@ -5345,7 +5345,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);
@@ -5420,7 +5420,7 @@  int main_create(int argc, char **argv)
         } else {
             help("create");
             free(dom_info.extra_config);
-            return 2;
+            return EXIT_FAILURE;
         }
     }
 
@@ -5440,11 +5440,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)
@@ -5465,7 +5465,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, "
@@ -5497,7 +5497,7 @@  int main_config_update(int argc, char **argv)
         } else {
             help("create");
             free(extra_config);
-            return 2;
+            return EXIT_FAILURE;
         }
     }
     if (filename) {
@@ -5506,25 +5506,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);
@@ -5540,7 +5540,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);
         }
     }
 
@@ -5548,7 +5548,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)
@@ -7034,10 +7034,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)