|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v9 2/3] xenpm: Use EXIT_{SUCCESS,FAILURE} instead of errno as exit codes
errno is not unified accross platforms, which makes error codes actually
platform specific. C standard defines EXIT_SUCCESS and EXIT_FAILURE
(respectively 0 and 1) as standard errors codes, even though it only reports
whether it failed or not.
Suggested-by: Jan Beulich <jbeulich@xxxxxxxx>
Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
v9:
- Introduced
tools/misc/xenpm.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c
index 682d092479..e4902d2e82 100644
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -112,7 +112,7 @@ static void parse_cpuid(const char *arg, int *cpuid)
if ( strcasecmp(arg, "all") )
{
fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg);
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
*cpuid = -1;
}
@@ -124,7 +124,7 @@ static void parse_cpuid_and_int(int argc, char *argv[],
if ( argc == 0 )
{
fprintf(stderr, "Missing %s\n", what);
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
if ( argc > 1 )
@@ -133,7 +133,7 @@ static void parse_cpuid_and_int(int argc, char *argv[],
if ( sscanf(argv[argc > 1], "%d", val) != 1 )
{
fprintf(stderr, "Invalid %s '%s'\n", what, argv[argc > 1]);
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
}
@@ -662,7 +662,7 @@ static void signal_int_handler(int signo)
out:
free(cputopo);
xc_interface_close(xc_handle);
- exit(0);
+ exit(EXIT_SUCCESS);
}
void start_gather_func(int argc, char *argv[])
@@ -1154,7 +1154,7 @@ void scaling_governor_func(int argc, char *argv[])
else
{
fprintf(stderr, "Missing argument(s)\n");
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
if ( cpuid < 0 )
@@ -1215,7 +1215,7 @@ void cpu_topology_func(int argc, char *argv[])
out:
free(cputopo);
if ( rc )
- exit(rc);
+ exit(EXIT_FAILURE);
}
void set_sched_smt_func(int argc, char *argv[])
@@ -1224,7 +1224,7 @@ void set_sched_smt_func(int argc, char *argv[])
if ( argc != 1 ) {
fprintf(stderr, "Missing or invalid argument(s)\n");
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
if ( !strcasecmp(argv[0], "disable") )
@@ -1234,7 +1234,7 @@ void set_sched_smt_func(int argc, char *argv[])
else
{
fprintf(stderr, "Invalid argument: %s\n", argv[0]);
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
if ( !xc_set_sched_opt_smt(xc_handle, value) )
@@ -1254,12 +1254,12 @@ void set_vcpu_migration_delay_func(int argc, char
*argv[])
if ( argc != 1 || (value = atoi(argv[0])) < 0 ) {
fprintf(stderr, "Missing or invalid argument(s)\n");
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
if ( xc_sched_credit_params_get(xc_handle, 0, &sparam) < 0 ) {
fprintf(stderr, "getting Credit scheduler parameters failed\n");
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
sparam.vcpu_migr_delay_us = value;
@@ -1304,7 +1304,7 @@ void set_max_cstate_func(int argc, char *argv[])
: (subval = XEN_SYSCTL_CX_UNLIMITED, strcmp(argv[1],
"unlimited")))) )
{
fprintf(stderr, "Missing, excess, or invalid argument(s)\n");
- exit(EINVAL);
+ exit(EXIT_FAILURE);
}
snprintf(buf, ARRAY_SIZE(buf), "C%d", value);
@@ -1575,7 +1575,7 @@ static void cppc_set_func(int argc, char *argv[])
uint32_t set_params;
if ( parse_cppc_opts(&set_cppc, &cpuid, argc, argv) )
- exit(EINVAL);
+ exit(EXIT_FAILURE);
if ( cpuid != -1 )
{
@@ -1637,7 +1637,7 @@ int main(int argc, char *argv[])
if ( !xc_handle )
{
fprintf(stderr, "failed to get the handler\n");
- return EIO;
+ return EXIT_FAILURE;
}
ret = xc_physinfo(xc_handle, &physinfo);
@@ -1647,7 +1647,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "failed to get processor information (%d - %s)\n",
ret, strerror(ret));
xc_interface_close(xc_handle);
- return ret;
+ return EXIT_FAILURE;
}
max_cpu_nr = physinfo.max_cpu_id + 1;
@@ -1662,7 +1662,8 @@ int main(int argc, char *argv[])
for ( i = 0; i < nr_matches; i++ )
fprintf(stderr, " %s", main_options[matches_main_options[i]].name);
fprintf(stderr, "\n");
- ret = EINVAL;
+ xc_interface_close(xc_handle);
+ return EXIT_FAILURE;
}
else if ( nr_matches == 1 )
/* dispatch to the corresponding function handler */
@@ -1670,10 +1671,11 @@ int main(int argc, char *argv[])
else
{
show_help();
- ret = EINVAL;
+ xc_interface_close(xc_handle);
+ return EXIT_FAILURE;
}
xc_interface_close(xc_handle);
- return ret;
+ return EXIT_SUCCESS;
}
--
2.53.0
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |