1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

detect-virt: define main through macro

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-11-16 10:53:47 +01:00
parent 4515a95ee0
commit bdab09849e

View File

@ -120,7 +120,7 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
int main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
/* This is mostly intended to be used for scripts which want
@ -132,59 +132,45 @@ int main(int argc, char *argv[]) {
r = parse_argv(argc, argv);
if (r <= 0)
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
return r;
switch (arg_mode) {
case ONLY_VM:
r = detect_vm();
if (r < 0) {
log_error_errno(r, "Failed to check for VM: %m");
return EXIT_FAILURE;
}
if (r < 0)
return log_error_errno(r, "Failed to check for VM: %m");
break;
case ONLY_CONTAINER:
r = detect_container();
if (r < 0) {
log_error_errno(r, "Failed to check for container: %m");
return EXIT_FAILURE;
}
if (r < 0)
return log_error_errno(r, "Failed to check for container: %m");
break;
case ONLY_CHROOT:
r = running_in_chroot();
if (r < 0) {
log_error_errno(r, "Failed to check for chroot() environment: %m");
return EXIT_FAILURE;
}
return r ? EXIT_SUCCESS : EXIT_FAILURE;
if (r < 0)
return log_error_errno(r, "Failed to check for chroot() environment: %m");
return !r;
case ONLY_PRIVATE_USERS:
r = running_in_userns();
if (r < 0) {
log_error_errno(r, "Failed to check for user namespace: %m");
return EXIT_FAILURE;
}
return r ? EXIT_SUCCESS : EXIT_FAILURE;
if (r < 0)
return log_error_errno(r, "Failed to check for user namespace: %m");
return !r;
case ANY_VIRTUALIZATION:
default:
r = detect_virtualization();
if (r < 0) {
log_error_errno(r, "Failed to check for virtualization: %m");
return EXIT_FAILURE;
}
if (r < 0)
return log_error_errno(r, "Failed to check for virtualization: %m");
break;
}
if (!arg_quiet)
puts(virtualization_to_string(r));
return r != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE;
return r == VIRTUALIZATION_NONE;
}
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);