udev/cdrom: split main() into main() and run()

However, we do not use DEFINE_MAIN_FUNCTION() here, as ubuntu s390x CI
does not like it...
This commit is contained in:
Yu Watanabe 2021-01-05 03:07:23 +09:00 committed by Luca Boccassi
parent 2131110553
commit a084b38789
1 changed files with 27 additions and 24 deletions

View File

@ -943,33 +943,24 @@ static int parse_argv(int argc, char *argv[]) {
return 1; return 1;
} }
int main(int argc, char *argv[]) { static int run(int argc, char *argv[]) {
_cleanup_(context_clear) Context c; _cleanup_(context_clear) Context c;
int r, rc = 0; int r;
log_set_target(LOG_TARGET_AUTO);
udev_parse_config();
log_parse_environment();
log_open();
context_init(&c); context_init(&c);
r = parse_argv(argc, argv); r = parse_argv(argc, argv);
if (r <= 0) { if (r <= 0)
rc = r < 0; return r;
goto exit;
}
if (open_drive(&c) < 0) { r = open_drive(&c);
rc = 1; if (r < 0)
goto exit; return r;
}
/* same data as original cdrom_id */ /* same data as original cdrom_id */
if (cd_capability_compat(&c) < 0) { r = cd_capability_compat(&c);
rc = 1; if (r < 0)
goto exit; return r;
}
/* check for media - don't bail if there's no media as we still need to /* check for media - don't bail if there's no media as we still need to
* to read profiles */ * to read profiles */
@ -979,8 +970,7 @@ int main(int argc, char *argv[]) {
if (cd_inquiry(&c) < 0) if (cd_inquiry(&c) < 0)
goto work; goto work;
/* read drive and possibly current profile */ r = cd_profiles(&c); /* read drive and possibly current profile */
r = cd_profiles(&c);
if (r > 0) { if (r > 0) {
/* at this point we are guaranteed to have media in the drive - find out more about it */ /* at this point we are guaranteed to have media in the drive - find out more about it */
@ -1012,7 +1002,20 @@ work:
print_properties(&c); print_properties(&c);
exit: return 0;
log_close(); }
return rc;
int main(int argc, char *argv[]) {
int r;
log_set_target(LOG_TARGET_AUTO);
udev_parse_config();
log_parse_environment();
log_open();
r = run(argc, argv);
log_close();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
} }