]> xenbits.xensource.com Git - people/julieng/xen-unstable.git/commitdiff
xl: convert main() exit codes to EXIT_[SUCCESS|FAILURE]
authorHarmandeep Kaur <write.harmandeep@gmail.com>
Wed, 28 Oct 2015 02:26:20 +0000 (07:56 +0530)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 3 Nov 2015 17:03:03 +0000 (17:03 +0000)
Turning main() function exit codes towards using the EXIT_[SUCCESS|FAILURE]
constants, instead of instead of arbitrary numbers or libxl return codes.

Also includes a document comment in xl.h stating xl process should always
return EXIT_FOO and main_* can be treated as main() as if they are returning
a process exit status and not a function return value)

Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxl/xl.c
tools/libxl/xl.h

index 5316ad9241b29645f90cc18bffe6811617950efa..dfae84a595dd4d8efba909f6993350c4dd0db4b6 100644 (file)
@@ -318,7 +318,7 @@ int main(int argc, char **argv)
             break;
         default:
             fprintf(stderr, "unknown global option\n");
-            exit(2);
+            exit(EXIT_FAILURE);
         }
     }
 
@@ -326,13 +326,13 @@ int main(int argc, char **argv)
 
     if (!cmd) {
         help(NULL);
-        exit(1);
+        exit(EXIT_FAILURE);
     }
     opterr = 0;
 
     logger = xtl_createlogger_stdiostream(stderr, minmsglevel,
         (progress_use_cr ? XTL_STDIOSTREAM_PROGRESS_USE_CR : 0));
-    if (!logger) exit(1);
+    if (!logger) exit(EXIT_FAILURE);
 
     atexit(xl_ctx_free);
 
@@ -355,16 +355,16 @@ int main(int argc, char **argv)
     if (cspec) {
         if (dryrun_only && !cspec->can_dryrun) {
             fprintf(stderr, "command does not implement -N (dryrun) option\n");
-            ret = 1;
+            ret = EXIT_FAILURE;
             goto xit;
         }
         ret = cspec->cmd_impl(argc, argv);
     } else if (!strcmp(cmd, "help")) {
         help(argv[1]);
-        ret = 0;
+        ret = EXIT_SUCCESS;
     } else {
         fprintf(stderr, "command not implemented\n");
-        ret = 1;
+        ret = EXIT_FAILURE;
     }
 
  xit:
index 00211128fb33765c6bd10c35f66ab083ceec122a..bdab125df32068e2b5f7cae20f952f718fdf129a 100644 (file)
@@ -30,6 +30,13 @@ struct cmd_spec {
     char *cmd_option;
 };
 
+/*
+ * The xl process should always return either EXIT_SUCCESS or
+ * EXIT_FAILURE. main_* functions, implementing the various xl
+ * commands, can be treated as main() as if they are returning
+ * a process exit status and not a function return value.
+ */
+
 int main_vcpulist(int argc, char **argv);
 int main_info(int argc, char **argv);
 int main_sharing(int argc, char **argv);