diff mbox

[7/9] xl: Improve return and exit codes of main_create(), main_config_update(), main_sharing(), main_rename() and related functions.

Message ID 1456318407-3635-8-git-send-email-write.harmandeep@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Harmandeep Kaur Feb. 24, 2016, 12:53 p.m. UTC
Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
---
 tools/libxl/xl_cmdimpl.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

Comments

Dario Faggioli March 2, 2016, 5:29 p.m. UTC | #1
On Wed, 2016-02-24 at 18:23 +0530, Harmandeep Kaur wrote:
> Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
>
I don't recall if I said this already, but main_sharing() does not
belong here.
 
> @@ -5095,11 +5095,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;
>      }
As far as I can see, create_domain() mostly returns libxl error codes.
I think you should convert that one as well (in 0/-1, as it's internal,
and doing it in this patch would be ok).

The rest of the patch looks ok to me.

Thanks and Regards,
Dario
diff mbox

Patch

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 9d95b50..f7f7d7f 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -5001,7 +5001,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);
@@ -5076,7 +5076,7 @@  int main_create(int argc, char **argv)
         } else {
             help("create");
             free(dom_info.extra_config);
-            return 2;
+            return EXIT_FAILURE;
         }
     }
 
@@ -5095,11 +5095,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)
@@ -5120,7 +5120,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, "
@@ -5152,7 +5152,7 @@  int main_config_update(int argc, char **argv)
         } else {
             help("create");
             free(extra_config);
-            return 2;
+            return EXIT_FAILURE;
         }
     }
     if (filename) {
@@ -5161,25 +5161,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);
@@ -5195,7 +5195,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);
         }
     }
 
@@ -5203,7 +5203,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)
@@ -5772,7 +5772,7 @@  int main_sharing(int argc, char **argv)
         info = libxl_list_domain(ctx, &nb_domain);
         if (!info) {
             fprintf(stderr, "libxl_list_domain failed.\n");
-            return 1;
+            return EXIT_FAILURE;
         }
         info_free = info;
     } else if (optind == argc-1) {
@@ -5781,17 +5781,17 @@  int main_sharing(int argc, char **argv)
         if (rc == ERROR_DOMAIN_NOTFOUND) {
             fprintf(stderr, "Error: Domain \'%s\' does not exist.\n",
                 argv[optind]);
-            return -rc;
+            return EXIT_FAILURE;
         }
         if (rc) {
             fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc);
-            return -rc;
+            return EXIT_FAILURE;
         }
         info = &info_buf;
         nb_domain = 1;
     } else {
         help("sharing");
-        return 2;
+        return EXIT_FAILURE;
     }
 
     sharing(info, nb_domain);
@@ -5801,7 +5801,7 @@  int main_sharing(int argc, char **argv)
     else
         libxl_dominfo_dispose(info);
 
-    return 0;
+    return EXIT_SUCCESS;
 }
 
 static int sched_domain_get(libxl_scheduler sched, int domid,
@@ -6374,10 +6374,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)